encoder_amd64.go 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. // +build amd64,go1.16,!go1.22
  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. // Encoder represents a specific set of encoder configurations.
  22. type Encoder = encoder.Encoder
  23. // StreamEncoder uses io.Writer as input.
  24. type StreamEncoder = encoder.StreamEncoder
  25. // Options is a set of encoding options.
  26. type Options = encoder.Options
  27. const (
  28. // SortMapKeys indicates that the keys of a map needs to be sorted
  29. // before serializing into JSON.
  30. // WARNING: This hurts performance A LOT, USE WITH CARE.
  31. SortMapKeys Options = encoder.SortMapKeys
  32. // EscapeHTML indicates encoder to escape all HTML characters
  33. // after serializing into JSON (see https://pkg.go.dev/encoding/json#HTMLEscape).
  34. // WARNING: This hurts performance A LOT, USE WITH CARE.
  35. EscapeHTML Options = encoder.EscapeHTML
  36. // CompactMarshaler indicates that the output JSON from json.Marshaler
  37. // is always compact and needs no validation
  38. CompactMarshaler Options = encoder.CompactMarshaler
  39. // NoQuoteTextMarshaler indicates that the output text from encoding.TextMarshaler
  40. // is always escaped string and needs no quoting
  41. NoQuoteTextMarshaler Options = encoder.NoQuoteTextMarshaler
  42. // NoNullSliceOrMap indicates all empty Array or Object are encoded as '[]' or '{}',
  43. // instead of 'null'
  44. NoNullSliceOrMap Options = encoder.NoNullSliceOrMap
  45. // ValidateString indicates that encoder should validate the input string
  46. // before encoding it into JSON.
  47. ValidateString Options = encoder.ValidateString
  48. // NoValidateJSONMarshaler indicates that the encoder should not validate the output string
  49. // after encoding the JSONMarshaler to JSON.
  50. NoValidateJSONMarshaler Options = encoder.NoValidateJSONMarshaler
  51. // CompatibleWithStd is used to be compatible with std encoder.
  52. CompatibleWithStd Options = encoder.CompatibleWithStd
  53. )
  54. var (
  55. // Encode returns the JSON encoding of val, encoded with opts.
  56. Encode = encoder.Encode
  57. // EncodeInto is like Encode but uses a user-supplied buffer instead of allocating a new one.
  58. EncodeIndented = encoder.EncodeIndented
  59. // EncodeIndented is like Encode but applies Indent to format the output.
  60. // Each JSON element in the output will begin on a new line beginning with prefix
  61. // followed by one or more copies of indent according to the indentation nesting.
  62. EncodeInto = encoder.EncodeInto
  63. // HTMLEscape appends to dst the JSON-encoded src with <, >, &, U+2028 and U+2029
  64. // characters inside string literals changed to \u003c, \u003e, \u0026, \u2028, \u2029
  65. // so that the JSON will be safe to embed inside HTML <script> tags.
  66. // For historical reasons, web browsers don't honor standard HTML
  67. // escaping within <script> tags, so an alternative JSON encoding must
  68. // be used.
  69. HTMLEscape = encoder.HTMLEscape
  70. // Pretouch compiles vt ahead-of-time to avoid JIT compilation on-the-fly, in
  71. // order to reduce the first-hit latency.
  72. //
  73. // Opts are the compile options, for example, "option.WithCompileRecursiveDepth" is
  74. // a compile option to set the depth of recursive compile for the nested struct type.
  75. Pretouch = encoder.Pretouch
  76. // Quote returns the JSON-quoted version of s.
  77. Quote = encoder.Quote
  78. // Valid validates json and returns first non-blank character position,
  79. // if it is only one valid json value.
  80. // Otherwise returns invalid character position using start.
  81. //
  82. // Note: it does not check for the invalid UTF-8 characters.
  83. Valid = encoder.Valid
  84. // NewStreamEncoder adapts to encoding/json.NewDecoder API.
  85. //
  86. // NewStreamEncoder returns a new encoder that write to w.
  87. NewStreamEncoder = encoder.NewStreamEncoder
  88. )