MCPcopy Index your code
hub / github.com/keploy/keploy / ReadNextDocJSON

Method ReadNextDocJSON

pkg/platform/yaml/mockreader.go:214–230  ·  view source on GitHub ↗

ReadNextDocJSON reads the next NDJSON line and returns it as a NetworkTrafficDocJSON with the spec kept as a json.RawMessage. Only valid when the reader's format is JSON; panics (via error) otherwise. This is the read-side companion to EncodeMockJSON: the entire round-trip for a JSON mocks file can

()

Source from the content-addressed store, hash-verified

212// for a JSON mocks file can now stay on encoding/json with no yaml.Node
213// allocation or gopkg.in/yaml.v3 emit/parse.
214func (r *MockReader) ReadNextDocJSON() (*NetworkTrafficDocJSON, error) {
215 if r.format != FormatJSON {
216 return nil, fmt.Errorf("mockreader: ReadNextDocJSON called on %s reader", r.format)
217 }
218 data, err := r.ReadNextDocument()
219 if err != nil {
220 return nil, err
221 }
222 if len(bytes.TrimSpace(data)) == 0 {
223 return r.ReadNextDocJSON()
224 }
225 var doc NetworkTrafficDocJSON
226 if err := json.Unmarshal(data, &doc); err != nil {
227 return nil, fmt.Errorf("failed to decode JSON at line %d: %w", r.lineNum, err)
228 }
229 return &doc, nil
230}
231
232// Close closes the file.
233func (r *MockReader) Close() error {

Callers 6

UpdateMocksMethod · 0.80
PersistMockNoiseMethod · 0.80
GetFilteredMocksMethod · 0.80
GetUnFilteredMocksMethod · 0.80

Calls 2

ReadNextDocumentMethod · 0.95
UnmarshalMethod · 0.80