github.com/bytedance/sonic@v1.11.7-0.20240517092252-d2edb31b167b/encoder/encoder_amd64.go (about)

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