encoder_amd64.go 4.5 KB

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