Debian Codegraph @

pkg/internal/third_party/go-json-experiment/json/jsontext/export.go

raw
1 // Copyright 2023 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 jsontext
6
7 import (
8 "io"
9
10 "k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json/internal"
11 )
12
13 // Internal is for internal use only.
14 // This is exempt from the Go compatibility agreement.
15 var Internal exporter
16
17 type exporter struct{}
18
19 // Export exposes internal functionality from "jsontext" to "json".
20 // This cannot be dynamically called by other packages since
21 // they cannot obtain a reference to the internal.AllowInternalUse value.
22 func (exporter) Export(p *internal.NotForPublicUse) export {
23 if p != &internal.AllowInternalUse {
24 panic("unauthorized call to Export")
25 }
26 return export{}
27 }
28
29 // The export type exposes functionality to packages with visibility to
30 // the internal.AllowInternalUse variable. The "json" package uses this
31 // to modify low-level state in the Encoder and Decoder types.
32 // It mutates the state directly instead of calling ReadToken or WriteToken
33 // since this is more performant. The public APIs need to track state to ensure
34 // that users are constructing a valid JSON value, but the "json" implementation
35 // guarantees that it emits valid JSON by the structure of the code itself.
36 type export struct{}
37
38 // Encoder returns a pointer to the underlying encoderState.
39 func (export) Encoder(e *Encoder) *encoderState { return &e.s }
40
41 // Decoder returns a pointer to the underlying decoderState.
42 func (export) Decoder(d *Decoder) *decoderState { return &d.s }
43
44 func (export) GetBufferedEncoder(o ...Options) *Encoder {
45 return getBufferedEncoder(o...)
46 }
47 func (export) PutBufferedEncoder(e *Encoder) {
48 putBufferedEncoder(e)
49 }
50
51 func (export) GetStreamingEncoder(w io.Writer, o ...Options) *Encoder {
52 return getStreamingEncoder(w, o...)
53 }
54 func (export) PutStreamingEncoder(e *Encoder) {
55 putStreamingEncoder(e)
56 }
57
58 func (export) GetBufferedDecoder(b []byte, o ...Options) *Decoder {
59 return getBufferedDecoder(b, o...)
60 }
61 func (export) PutBufferedDecoder(d *Decoder) {
62 putBufferedDecoder(d)
63 }
64
65 func (export) GetStreamingDecoder(r io.Reader, o ...Options) *Decoder {
66 return getStreamingDecoder(r, o...)
67 }
68 func (export) PutStreamingDecoder(d *Decoder) {
69 putStreamingDecoder(d)
70 }
71
72 func (export) IsIOError(err error) bool {
73 _, ok := err.(*ioError)
74 return ok
75 }