| 1 | // Copyright 2020 The Go Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style |
| 3 | // license that can be found in the LICENSE file. |
| 4 | |
| 5 | package jsonscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/ |
| 6 | |
| 7 | import ( |
| 8 | "bytesscip-go gomod github.com/golang/go/src go1.21 bytes/" |
| 9 | "errorsscip-go gomod github.com/golang/go/src go1.21 errors/" |
| 10 | "ioscip-go gomod github.com/golang/go/src go1.21 io/" |
| 11 | "sortscip-go gomod github.com/golang/go/src go1.21 sort/" |
| 12 | "syncscip-go gomod github.com/golang/go/src go1.21 sync/" |
| 13 | "unicode/utf16scip-go gomod github.com/golang/go/src go1.21 `unicode/utf16`/" |
| 14 | "unicode/utf8scip-go gomod github.com/golang/go/src go1.21 `unicode/utf8`/" |
| 15 | ) |
| 16 | |
| 17 | // NOTE: RawValue is analogous to v1 json.RawMessage. |
| 18 | |
| 19 | // RawValue represents a single raw JSON value, which may be one of the following: |
| 20 | // - a JSON literal (i.e., null, true, or false) |
| 21 | // - a JSON string (e.g., "hello, world!") |
| 22 | // - a JSON number (e.g., 123.456) |
| 23 | // - an entire JSON object (e.g., {"fizz":"buzz"} ) |
| 24 | // - an entire JSON array (e.g., [1,2,3] ) |
| 25 | // |
| 26 | // RawValue can represent entire array or object values, while Token cannot. |
| 27 | // RawValue may contain leading and/or trailing whitespace. |
| 28 | type RawValuescip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/RawValue# []byte |
| 29 | |
| 30 | // Clone returns a copy of v. |
| 31 | func (v RawValuescip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/RawValue#) Clonescip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/RawValue#Clone().() RawValuescip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/RawValue# { |
| 32 | if v == nil { |
| 33 | return nil |
| 34 | } |
| 35 | return append(RawValuescip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/RawValue#{}, v...) |
| 36 | } |
| 37 | |
| 38 | // String returns the string formatting of v. |
| 39 | func (v RawValuescip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/RawValue#) Stringscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/RawValue#String().() string { |
| 40 | if v == nil { |
| 41 | return "null" |
| 42 | } |
| 43 | return string(v) |
| 44 | } |
| 45 | |
| 46 | // IsValid reports whether the raw JSON value is syntactically valid |
| 47 | // according to RFC 7493. |
| 48 | // |
| 49 | // It verifies whether the input is properly encoded as UTF-8, |
| 50 | // that escape sequences within strings decode to valid Unicode codepoints, and |
| 51 | // that all names in each object are unique. |
| 52 | // It does not verify whether numbers are representable within the limits |
| 53 | // of any common numeric type (e.g., float64, int64, or uint64). |
| 54 | func (v RawValuescip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/RawValue#) IsValidscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/RawValue#IsValid().() bool { |
| 55 | d := getBufferedDecoderscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/getBufferedDecoder().(v, DecodeOptionsscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/DecodeOptions#{}) |
| 56 | defer putBufferedDecoderscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/putBufferedDecoder().(d) |
| 57 | _, errVal := d.ReadValuescip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/Decoder#ReadValue().() |
| 58 | _, errEOF := d.ReadTokenscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/Decoder#ReadToken().() |
| 59 | return errVal == nil && errEOF == ioscip-go gomod github.com/golang/go/src go1.21 io/.EOFscip-go gomod github.com/golang/go/src go1.21 io/EOF. |
| 60 | } |
| 61 | |
| 62 | // Compact removes all whitespace from the raw JSON value. |
| 63 | // |
| 64 | // It does not reformat JSON strings to use any other representation. |
| 65 | // It is guaranteed to succeed if the input is valid. |
| 66 | // If the value is already compacted, then the buffer is not mutated. |
| 67 | func (v *RawValuescip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/RawValue#) Compactscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/RawValue#Compact().() error { |
| 68 | return v.reformatscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/RawValue#reformat().(false, false, "", "") |
| 69 | } |
| 70 | |
| 71 | // Indent reformats the whitespace in the raw JSON value so that each element |
| 72 | // in a JSON object or array begins on a new, indented line beginning with |
| 73 | // prefix followed by one or more copies of indent according to the nesting. |
| 74 | // The value does not begin with the prefix nor any indention, |
| 75 | // to make it easier to embed inside other formatted JSON data. |
| 76 | // |
| 77 | // It does not reformat JSON strings to use any other representation. |
| 78 | // It is guaranteed to succeed if the input is valid. |
| 79 | // If the value is already indented properly, then the buffer is not mutated. |
| 80 | func (v *RawValuescip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/RawValue#) Indentscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/RawValue#Indent().(prefix, indent string) error { |
| 81 | return v.reformatscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/RawValue#reformat().(false, true, prefix, indent) |
| 82 | } |
| 83 | |
| 84 | // Canonicalize canonicalizes the raw JSON value according to the |
| 85 | // JSON Canonicalization Scheme (JCS) as defined by RFC 8785 |
| 86 | // where it produces a stable representation of a JSON value. |
| 87 | // |
| 88 | // The output stability is dependent on the stability of the application data |
| 89 | // (see RFC 8785, Appendix E). It cannot produce stable output from |
| 90 | // fundamentally unstable input. For example, if the JSON value |
| 91 | // contains ephemeral data (e.g., a frequently changing timestamp), |
| 92 | // then the value is still unstable regardless of whether this is called. |
| 93 | // |
| 94 | // Note that JCS treats all JSON numbers as IEEE 754 double precision numbers. |
| 95 | // Any numbers with precision beyond what is representable by that form |
| 96 | // will lose their precision when canonicalized. For example, integer values |
| 97 | // beyond ±2⁵³ will lose their precision. It is recommended that |
| 98 | // int64 and uint64 data types be represented as a JSON string. |
| 99 | // |
| 100 | // It is guaranteed to succeed if the input is valid. |
| 101 | // If the value is already canonicalized, then the buffer is not mutated. |
| 102 | func (v *RawValuescip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/RawValue#) Canonicalizescip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/RawValue#Canonicalize().() error { |
| 103 | return v.reformatscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/RawValue#reformat().(true, false, "", "") |
| 104 | } |
| 105 | |
| 106 | // TODO: Instead of implementing the v1 Marshaler/Unmarshaler, |
| 107 | // consider implementing the v2 versions instead. |
| 108 | |
| 109 | // MarshalJSON returns v as the JSON encoding of v. |
| 110 | // It returns the stored value as the raw JSON output without any validation. |
| 111 | // If v is nil, then this returns a JSON null. |
| 112 | func (v RawValuescip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/RawValue#) MarshalJSONscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/RawValue#MarshalJSON().() ([]byte, error) { |
| 113 | // NOTE: This matches the behavior of v1 json.RawMessage.MarshalJSON. |
| 114 | if v == nil { |
| 115 | return []byte("null"), nil |
| 116 | } |
| 117 | return v, nil |
| 118 | } |
| 119 | |
| 120 | // UnmarshalJSON sets v as the JSON encoding of b. |
| 121 | // It stores a copy of the provided raw JSON input without any validation. |
| 122 | func (v *RawValuescip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/RawValue#) UnmarshalJSONscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/RawValue#UnmarshalJSON().(b []byte) error { |
| 123 | // NOTE: This matches the behavior of v1 json.RawMessage.UnmarshalJSON. |
| 124 | if v == nil { |
| 125 | return errorsscip-go gomod github.com/golang/go/src go1.21 errors/.Newscip-go gomod github.com/golang/go/src go1.21 errors/New().("json.RawValue: UnmarshalJSON on nil pointer") |
| 126 | } |
| 127 | *v = append((*v)[:0], b...) |
| 128 | return nil |
| 129 | } |
| 130 | |
| 131 | // Kind returns the starting token kind. |
| 132 | // For a valid value, this will never include '}' or ']'. |
| 133 | func (v RawValuescip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/RawValue#) Kindscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/RawValue#Kind().() Kindscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/Kind# { |
| 134 | if v := v[consumeWhitespacescip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/consumeWhitespace().(v):]; len(v) > 0 { |
| 135 | return Kindscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/Kind#(v[0]).normalizescip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/Kind#normalize().() |
| 136 | } |
| 137 | return invalidKindscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/invalidKind. |
| 138 | } |
| 139 | |
| 140 | func (v *RawValuescip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/RawValue#) reformatscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/RawValue#reformat().(canonical, multiline bool, prefix, indent string) error { |
| 141 | var eo EncodeOptionsscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/EncodeOptions# |
| 142 | if canonical { |
| 143 | eo.AllowInvalidUTF8scip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/EncodeOptions#AllowInvalidUTF8. = false // per RFC 8785, section 3.2.4 |
| 144 | eo.AllowDuplicateNamesscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/EncodeOptions#AllowDuplicateNames. = false // per RFC 8785, section 3.1 |
| 145 | eo.canonicalizeNumbersscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/EncodeOptions#canonicalizeNumbers. = true // per RFC 8785, section 3.2.2.3 |
| 146 | eo.EscapeRunescip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/EncodeOptions#EscapeRune. = nil // per RFC 8785, section 3.2.2.2 |
| 147 | eo.multilinescip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/EncodeOptions#multiline. = false // per RFC 8785, section 3.2.1 |
| 148 | } else { |
| 149 | if s := trimLeftSpaceTabscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/trimLeftSpaceTab().(prefix); len(s) > 0 { |
| 150 | panic("json: invalid character " + quoteRunescip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/quoteRune().([]byte(s)) + " in indent prefix") |
| 151 | } |
| 152 | if s := trimLeftSpaceTabscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/trimLeftSpaceTab().(indent); len(s) > 0 { |
| 153 | panic("json: invalid character " + quoteRunescip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/quoteRune().([]byte(s)) + " in indent") |
| 154 | } |
| 155 | eo.AllowInvalidUTF8scip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/EncodeOptions#AllowInvalidUTF8. = true |
| 156 | eo.AllowDuplicateNamesscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/EncodeOptions#AllowDuplicateNames. = true |
| 157 | eo.preserveRawStringsscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/EncodeOptions#preserveRawStrings. = true |
| 158 | eo.multilinescip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/EncodeOptions#multiline. = multiline // in case indent is empty |
| 159 | eo.IndentPrefixscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/EncodeOptions#IndentPrefix. = prefix |
| 160 | eo.Indentscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/EncodeOptions#Indent. = indent |
| 161 | } |
| 162 | eo.omitTopLevelNewlinescip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/EncodeOptions#omitTopLevelNewline. = true |
| 163 | |
| 164 | // Write the entire value to reformat all tokens and whitespace. |
| 165 | e := getBufferedEncoderscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/getBufferedEncoder().(eo) |
| 166 | defer putBufferedEncoderscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/putBufferedEncoder().(e) |
| 167 | if err := e.WriteValuescip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/Encoder#WriteValue().(*v); err != nil { |
| 168 | return err |
| 169 | } |
| 170 | |
| 171 | // For canonical output, we may need to reorder object members. |
| 172 | if canonical { |
| 173 | // Obtain a buffered encoder just to use its internal buffer as |
| 174 | // a scratch buffer in reorderObjects for reordering object members. |
| 175 | e2 := getBufferedEncoderscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/getBufferedEncoder().(EncodeOptionsscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/EncodeOptions#{}) |
| 176 | defer putBufferedEncoderscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/putBufferedEncoder().(e2) |
| 177 | |
| 178 | // Disable redundant checks performed earlier during encoding. |
| 179 | d := getBufferedDecoderscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/getBufferedDecoder().(e.bufscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/encodeBuffer#buf., DecodeOptionsscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/DecodeOptions#{AllowInvalidUTF8scip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/DecodeOptions#AllowInvalidUTF8.: true, AllowDuplicateNamesscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/DecodeOptions#AllowDuplicateNames.: true}) |
| 180 | defer putBufferedDecoderscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/putBufferedDecoder().(d) |
| 181 | reorderObjectsscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/reorderObjects().(d, &e2.bufscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/encodeBuffer#buf.) // per RFC 8785, section 3.2.3 |
| 182 | } |
| 183 | |
| 184 | // Store the result back into the value if different. |
| 185 | if !bytesscip-go gomod github.com/golang/go/src go1.21 bytes/.Equalscip-go gomod github.com/golang/go/src go1.21 bytes/Equal().(*v, e.bufscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/encodeBuffer#buf.) { |
| 186 | *v = append((*v)[:0], e.bufscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/encodeBuffer#buf....) |
| 187 | } |
| 188 | return nil |
| 189 | } |
| 190 | |
| 191 | func trimLeftSpaceTabscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/trimLeftSpaceTab().(s string) string { |
| 192 | for i, r := range s { |
| 193 | switch r { |
| 194 | case ' ', '\t': |
| 195 | default: |
| 196 | return s[i:] |
| 197 | } |
| 198 | } |
| 199 | return "" |
| 200 | } |
| 201 | |
| 202 | type memberNamescip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/memberName# struct { |
| 203 | // name is the unescaped name. |
| 204 | namescip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/memberName#name. []byte |
| 205 | // before and after are byte offsets into Decoder.buf that represents |
| 206 | // the entire name/value pair. It may contain leading commas. |
| 207 | beforescip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/memberName#before., afterscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/memberName#after. int64 |
| 208 | } |
| 209 | |
| 210 | var memberNamePoolscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/memberNamePool. = syncscip-go gomod github.com/golang/go/src go1.21 sync/.Poolscip-go gomod github.com/golang/go/src go1.21 sync/Pool#{Newscip-go gomod github.com/golang/go/src go1.21 sync/Pool#New.: func() any { return new(memberNamesscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/memberNames#) }} |
| 211 | |
| 212 | func getMemberNamesscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/getMemberNames().() *memberNamesscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/memberNames# { |
| 213 | ns := memberNamePoolscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/memberNamePool..Getscip-go gomod github.com/golang/go/src go1.21 sync/Pool#Get().().(*memberNamesscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/memberNames#) |
| 214 | *ns = (*ns)[:0] |
| 215 | return ns |
| 216 | } |
| 217 | func putMemberNamesscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/putMemberNames().(ns *memberNamesscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/memberNames#) { |
| 218 | if cap(*ns) < 1<<10 { |
| 219 | for i := range *ns { |
| 220 | (*ns)[i] = memberNamescip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/memberName#{} // avoid pinning name |
| 221 | } |
| 222 | memberNamePoolscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/memberNamePool..Putscip-go gomod github.com/golang/go/src go1.21 sync/Pool#Put().(ns) |
| 223 | } |
| 224 | } |
| 225 | |
| 226 | type memberNamesscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/memberNames# []memberNamescip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/memberName# |
| 227 | |
| 228 | func (m *memberNamesscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/memberNames#) Lenscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/memberNames#Len().() int { return len(*m) } |
| 229 | func (m *memberNamesscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/memberNames#) Lessscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/memberNames#Less().(i, j int) bool { return lessUTF16scip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/lessUTF16().((*m)[i].namescip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/memberName#name., (*m)[j].namescip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/memberName#name.) } |
| 230 | func (m *memberNamesscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/memberNames#) Swapscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/memberNames#Swap().(i, j int) { (*m)[i], (*m)[j] = (*m)[j], (*m)[i] } |
| 231 | |
| 232 | // reorderObjects recursively reorders all object members in place |
| 233 | // according to the ordering specified in RFC 8785, section 3.2.3. |
| 234 | // |
| 235 | // Pre-conditions: |
| 236 | // - The value is valid (i.e., no decoder errors should ever occur). |
| 237 | // - The value is compact (i.e., no whitespace is present). |
| 238 | // - Initial call is provided a Decoder reading from the start of v. |
| 239 | // |
| 240 | // Post-conditions: |
| 241 | // - Exactly one JSON value is read from the Decoder. |
| 242 | // - All fully-parsed JSON objects are reordered by directly moving |
| 243 | // the members in the value buffer. |
| 244 | // |
| 245 | // The runtime is approximately O(n·log(n)) + O(m·log(m)), |
| 246 | // where n is len(v) and m is the total number of object members. |
| 247 | func reorderObjectsscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/reorderObjects().(d *Decoderscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/Decoder#, scratch *[]byte) { |
| 248 | switch tok, _ := d.ReadTokenscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/Decoder#ReadToken().(); tok.Kindscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/Token#Kind().() { |
| 249 | case '{': |
| 250 | // Iterate and collect the name and offsets for every object member. |
| 251 | members := getMemberNamesscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/getMemberNames().() |
| 252 | defer putMemberNamesscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/putMemberNames().(members) |
| 253 | var prevName []byte |
| 254 | isSorted := true |
| 255 | |
| 256 | beforeBody := d.InputOffsetscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/Decoder#InputOffset().() // offset after '{' |
| 257 | for d.PeekKindscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/Decoder#PeekKind().() != '}' { |
| 258 | beforeName := d.InputOffsetscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/Decoder#InputOffset().() |
| 259 | var flags valueFlagsscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/valueFlags# |
| 260 | name, _ := d.readValuescip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/Decoder#readValue().(&flags) |
| 261 | name = unescapeStringMayCopyscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/unescapeStringMayCopy().(name, flags.isVerbatimscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/valueFlags#isVerbatim().()) |
| 262 | reorderObjectsscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/reorderObjects().(d, scratch) |
| 263 | afterValue := d.InputOffsetscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/Decoder#InputOffset().() |
| 264 | |
| 265 | if isSorted && len(*members) > 0 { |
| 266 | isSorted = lessUTF16scip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/lessUTF16().(prevName, []byte(name)) |
| 267 | } |
| 268 | *members = append(*members, memberNamescip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/memberName#{name, beforeName, afterValue}) |
| 269 | prevName = name |
| 270 | } |
| 271 | afterBody := d.InputOffsetscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/Decoder#InputOffset().() // offset before '}' |
| 272 | d.ReadTokenscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/Decoder#ReadToken().() |
| 273 | |
| 274 | // Sort the members; return early if it's already sorted. |
| 275 | if isSorted { |
| 276 | return |
| 277 | } |
| 278 | // TODO(https://go.dev/issue/47619): Use slices.Sort. |
| 279 | sortscip-go gomod github.com/golang/go/src go1.21 sort/.Sortscip-go gomod github.com/golang/go/src go1.21 sort/Sort().(members) |
| 280 | |
| 281 | // Append the reordered members to a new buffer, |
| 282 | // then copy the reordered members back over the original members. |
| 283 | // Avoid swapping in place since each member may be a different size |
| 284 | // where moving a member over a smaller member may corrupt the data |
| 285 | // for subsequent members before they have been moved. |
| 286 | // |
| 287 | // The following invariant must hold: |
| 288 | // sum([m.after-m.before for m in members]) == afterBody-beforeBody |
| 289 | sorted := (*scratch)[:0] |
| 290 | for i, member := range *members { |
| 291 | if d.bufscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/decodeBuffer#buf.[member.beforescip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/memberName#before.] == ',' { |
| 292 | member.beforescip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/memberName#before.++ // trim leading comma |
| 293 | } |
| 294 | sorted = append(sorted, d.bufscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/decodeBuffer#buf.[member.beforescip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/memberName#before.:member.afterscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/memberName#after.]...) |
| 295 | if i < len(*members)-1 { |
| 296 | sorted = append(sorted, ',') // append trailing comma |
| 297 | } |
| 298 | } |
| 299 | if int(afterBody-beforeBody) != len(sorted) { |
| 300 | panic("BUG: length invariant violated") |
| 301 | } |
| 302 | copy(d.bufscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/decodeBuffer#buf.[beforeBody:afterBody], sorted) |
| 303 | |
| 304 | // Update scratch buffer to the largest amount ever used. |
| 305 | if len(sorted) > len(*scratch) { |
| 306 | *scratch = sorted |
| 307 | } |
| 308 | case '[': |
| 309 | for d.PeekKindscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/Decoder#PeekKind().() != ']' { |
| 310 | reorderObjectsscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/reorderObjects().(d, scratch) |
| 311 | } |
| 312 | d.ReadTokenscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/Decoder#ReadToken().() |
| 313 | } |
| 314 | } |
| 315 | |
| 316 | // lessUTF16 reports whether x is lexicographically less than y according |
| 317 | // to the UTF-16 codepoints of the UTF-8 encoded input strings. |
| 318 | // This implements the ordering specified in RFC 8785, section 3.2.3. |
| 319 | // The inputs must be valid UTF-8, otherwise this may panic. |
| 320 | func lessUTF16scip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json`/lessUTF16().[Bytes []byte | string](x, y Bytes) bool { |
| 321 | // NOTE: This is an optimized, allocation-free implementation |
| 322 | // of lessUTF16Simple in fuzz_test.go. FuzzLessUTF16 verifies that the |
| 323 | // two implementations agree on the result of comparing any two strings. |
| 324 | |
| 325 | isUTF16Self := func(r rune) bool { |
| 326 | return ('\u0000' <= r && r <= '\uD7FF') || ('\uE000' <= r && r <= '\uFFFF') |
| 327 | } |
| 328 | |
| 329 | var invalidUTF8 bool |
| 330 | x0, y0 := x, y |
| 331 | for { |
| 332 | if len(x) == 0 || len(y) == 0 { |
| 333 | if len(x) == len(y) && invalidUTF8 { |
| 334 | return string(x0) < string(y0) |
| 335 | } |
| 336 | return len(x) < len(y) |
| 337 | } |
| 338 | |
| 339 | // ASCII fast-path. |
| 340 | if x[0] < utf8scip-go gomod github.com/golang/go/src go1.21 `unicode/utf8`/.RuneSelfscip-go gomod github.com/golang/go/src go1.21 `unicode/utf8`/RuneSelf. || y[0] < utf8scip-go gomod github.com/golang/go/src go1.21 `unicode/utf8`/.RuneSelfscip-go gomod github.com/golang/go/src go1.21 `unicode/utf8`/RuneSelf. { |
| 341 | if x[0] != y[0] { |
| 342 | return x[0] < y[0] |
| 343 | } |
| 344 | x, y = x[1:], y[1:] |
| 345 | continue |
| 346 | } |
| 347 | |
| 348 | // Decode next pair of runes as UTF-8. |
| 349 | // TODO(https://go.dev/issue/56948): Use a generic implementation |
| 350 | // of utf8.DecodeRune, or rely on a compiler optimization to statically |
| 351 | // hide the cost of a type switch (https://go.dev/issue/57072). |
| 352 | var rx, ry rune |
| 353 | var nx, ny int |
| 354 | switch any(x).(type) { |
| 355 | case string: |
| 356 | rx, nx = utf8scip-go gomod github.com/golang/go/src go1.21 `unicode/utf8`/.DecodeRuneInStringscip-go gomod github.com/golang/go/src go1.21 `unicode/utf8`/DecodeRuneInString().(string(x)) |
| 357 | ry, ny = utf8scip-go gomod github.com/golang/go/src go1.21 `unicode/utf8`/.DecodeRuneInStringscip-go gomod github.com/golang/go/src go1.21 `unicode/utf8`/DecodeRuneInString().(string(y)) |
| 358 | case []byte: |
| 359 | rx, nx = utf8scip-go gomod github.com/golang/go/src go1.21 `unicode/utf8`/.DecodeRunescip-go gomod github.com/golang/go/src go1.21 `unicode/utf8`/DecodeRune().([]byte(x)) |
| 360 | ry, ny = utf8scip-go gomod github.com/golang/go/src go1.21 `unicode/utf8`/.DecodeRunescip-go gomod github.com/golang/go/src go1.21 `unicode/utf8`/DecodeRune().([]byte(y)) |
| 361 | } |
| 362 | |
| 363 | selfx := isUTF16Self(rx) |
| 364 | selfy := isUTF16Self(ry) |
| 365 | switch { |
| 366 | // The x rune is a single UTF-16 codepoint, while |
| 367 | // the y rune is a surrogate pair of UTF-16 codepoints. |
| 368 | case selfx && !selfy: |
| 369 | ry, _ = utf16scip-go gomod github.com/golang/go/src go1.21 `unicode/utf16`/.EncodeRunescip-go gomod github.com/golang/go/src go1.21 `unicode/utf16`/EncodeRune().(ry) |
| 370 | // The y rune is a single UTF-16 codepoint, while |
| 371 | // the x rune is a surrogate pair of UTF-16 codepoints. |
| 372 | case selfy && !selfx: |
| 373 | rx, _ = utf16scip-go gomod github.com/golang/go/src go1.21 `unicode/utf16`/.EncodeRunescip-go gomod github.com/golang/go/src go1.21 `unicode/utf16`/EncodeRune().(rx) |
| 374 | } |
| 375 | if rx != ry { |
| 376 | return rx < ry |
| 377 | } |
| 378 | invalidUTF8 = invalidUTF8 || (rx == utf8scip-go gomod github.com/golang/go/src go1.21 `unicode/utf8`/.RuneErrorscip-go gomod github.com/golang/go/src go1.21 `unicode/utf8`/RuneError. && nx == 1) || (ry == utf8scip-go gomod github.com/golang/go/src go1.21 `unicode/utf8`/.RuneErrorscip-go gomod github.com/golang/go/src go1.21 `unicode/utf8`/RuneError. && ny == 1) |
| 379 | x, y = x[nx:], y[ny:] |
| 380 | } |
| 381 | } |