@@ -23,6 +23,7 @@ import (
23
23
"strings"
24
24
25
25
jsoniter "github.com/json-iterator/go"
26
+ "sigs.k8s.io/structured-merge-diff/v4/internal/jsonstream"
26
27
yaml "sigs.k8s.io/yaml/goyaml.v2"
27
28
)
28
29
@@ -90,15 +91,25 @@ func FromJSON(input []byte) (Value, error) {
90
91
func FromJSONFast (input []byte ) (Value , error ) {
91
92
iter := readPool .BorrowIterator (input )
92
93
defer readPool .ReturnIterator (iter )
93
- return ReadJSONIter (iter )
94
+ return read (iter )
95
+ }
96
+
97
+ // this is a local copy of jsonstream.Read to avoid cyclic dependencies
98
+ // TODO: eliminate this https://github.com/kubernetes-sigs/structured-merge-diff/issues/202
99
+ func read (iter * jsoniter.Iterator ) (value.Value , error ) {
100
+ v := iter .Read ()
101
+ if iter .Error != nil && iter .Error != io .EOF {
102
+ return nil , iter .Error
103
+ }
104
+ return value .NewValueInterface (v ), nil
94
105
}
95
106
96
107
// ToJSON is a helper function for producing a JSon document.
97
108
func ToJSON (v Value ) ([]byte , error ) {
98
109
buf := bytes.Buffer {}
99
110
stream := writePool .BorrowStream (& buf )
100
111
defer writePool .ReturnStream (stream )
101
- WriteJSONStream (v , stream )
112
+ jsonstream . Write (v , stream )
102
113
b := stream .Buffer ()
103
114
err := stream .Flush ()
104
115
// Help jsoniter manage its buffers--without this, the next
@@ -109,17 +120,22 @@ func ToJSON(v Value) ([]byte, error) {
109
120
return buf .Bytes (), err
110
121
}
111
122
112
- // ReadJSONIter reads a Value from a JSON iterator.
113
- func ReadJSONIter (iter * jsoniter.Iterator ) (Value , error ) {
123
+ // DO NOT EXPORT
124
+ // readJSONIter reads a Value from a JSON iterator.
125
+ // TODO: eliminate this https://github.com/kubernetes-sigs/structured-merge-diff/issues/202
126
+ func readJSONIter (iter * jsoniter.Iterator ) (Value , error ) {
114
127
v := iter .Read ()
115
128
if iter .Error != nil && iter .Error != io .EOF {
116
129
return nil , iter .Error
117
130
}
118
131
return NewValueInterface (v ), nil
119
132
}
120
133
121
- // WriteJSONStream writes a value into a JSON stream.
122
- func WriteJSONStream (v Value , stream * jsoniter.Stream ) {
134
+ // DO NOT EXPORT
135
+
136
+ // writeJSONStream writes a value into a JSON stream.
137
+ // TODO: eliminate this https://github.com/kubernetes-sigs/structured-merge-diff/issues/202
138
+ func writeJSONStream (v Value , stream * jsoniter.Stream ) {
123
139
stream .WriteVal (v .Unstructured ())
124
140
}
125
141
0 commit comments