github.com/goshafaq/sonic@v0.0.0-20231026082336-871835fb94c6/encoder/encoder_amd64.go (about)

     1  //go:build amd64 && go1.16 && !go1.22
     2  // +build amd64,go1.16,!go1.22
     3  
     4  /*
     5   * Copyright 2023 ByteDance Inc.
     6   *
     7   * Licensed under the Apache License, Version 2.0 (the "License");
     8   * you may not use this file except in compliance with the License.
     9   * You may obtain a copy of the License at
    10   *
    11   *     http://www.apache.org/licenses/LICENSE-2.0
    12   *
    13   * Unless required by applicable law or agreed to in writing, software
    14   * distributed under the License is distributed on an "AS IS" BASIS,
    15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    16   * See the License for the specific language governing permissions and
    17   * limitations under the License.
    18   */
    19  
    20  package encoder
    21  
    22  import (
    23  	"github.com/goshafaq/sonic/internal/encoder"
    24  )
    25  
    26  // Encoder represents a specific set of encoder configurations.
    27  type Encoder = encoder.Encoder
    28  
    29  // StreamEncoder uses io.Writer as input.
    30  type StreamEncoder = encoder.StreamEncoder
    31  
    32  // Options is a set of encoding options.
    33  type Options = encoder.Options
    34  
    35  const (
    36  	// SortMapKeys indicates that the keys of a map needs to be sorted
    37  	// before serializing into JSON.
    38  	// WARNING: This hurts performance A LOT, USE WITH CARE.
    39  	SortMapKeys Options = encoder.SortMapKeys
    40  
    41  	// EscapeHTML indicates encoder to escape all HTML characters
    42  	// after serializing into JSON (see https://pkg.go.dev/encoding/json#HTMLEscape).
    43  	// WARNING: This hurts performance A LOT, USE WITH CARE.
    44  	EscapeHTML Options = encoder.EscapeHTML
    45  
    46  	// CompactMarshaler indicates that the output JSON from json.Marshaler
    47  	// is always compact and needs no validation
    48  	CompactMarshaler Options = encoder.CompactMarshaler
    49  
    50  	// NoQuoteTextMarshaler indicates that the output text from encoding.TextMarshaler
    51  	// is always escaped string and needs no quoting
    52  	NoQuoteTextMarshaler Options = encoder.NoQuoteTextMarshaler
    53  
    54  	// NoNullSliceOrMap indicates all empty Array or Object are encoded as '[]' or '{}',
    55  	// instead of 'null'
    56  	NoNullSliceOrMap Options = encoder.NoNullSliceOrMap
    57  
    58  	// ValidateString indicates that encoder should validate the input string
    59  	// before encoding it into JSON.
    60  	ValidateString Options = encoder.ValidateString
    61  
    62  	// NoValidateJSONMarshaler indicates that the encoder should not validate the output string
    63  	// after encoding the JSONMarshaler to JSON.
    64  	NoValidateJSONMarshaler Options = encoder.NoValidateJSONMarshaler
    65  
    66  	// CompatibleWithStd is used to be compatible with std encoder.
    67  	CompatibleWithStd Options = encoder.CompatibleWithStd
    68  )
    69  
    70  var (
    71  	// Encode returns the JSON encoding of val, encoded with opts.
    72  	Encode = encoder.Encode
    73  
    74  	// EncodeInto is like Encode but uses a user-supplied buffer instead of allocating a new one.
    75  	EncodeIndented = encoder.EncodeIndented
    76  
    77  	// EncodeIndented is like Encode but applies Indent to format the output.
    78  	// Each JSON element in the output will begin on a new line beginning with prefix
    79  	// followed by one or more copies of indent according to the indentation nesting.
    80  	EncodeInto = encoder.EncodeInto
    81  
    82  	// HTMLEscape appends to dst the JSON-encoded src with <, >, &, U+2028 and U+2029
    83  	// characters inside string literals changed to \u003c, \u003e, \u0026, \u2028, \u2029
    84  	// so that the JSON will be safe to embed inside HTML <script> tags.
    85  	// For historical reasons, web browsers don't honor standard HTML
    86  	// escaping within <script> tags, so an alternative JSON encoding must
    87  	// be used.
    88  	HTMLEscape = encoder.HTMLEscape
    89  
    90  	// Pretouch compiles vt ahead-of-time to avoid JIT compilation on-the-fly, in
    91  	// order to reduce the first-hit latency.
    92  	//
    93  	// Opts are the compile options, for example, "option.WithCompileRecursiveDepth" is
    94  	// a compile option to set the depth of recursive compile for the nested struct type.
    95  	Pretouch = encoder.Pretouch
    96  
    97  	// Quote returns the JSON-quoted version of s.
    98  	Quote = encoder.Quote
    99  
   100  	// Valid validates json and returns first non-blank character position,
   101  	// if it is only one valid json value.
   102  	// Otherwise returns invalid character position using start.
   103  	//
   104  	// Note: it does not check for the invalid UTF-8 characters.
   105  	Valid = encoder.Valid
   106  
   107  	// NewStreamEncoder adapts to encoding/json.NewDecoder API.
   108  	//
   109  	// NewStreamEncoder returns a new encoder that write to w.
   110  	NewStreamEncoder = encoder.NewStreamEncoder
   111  )