MCPcopy
hub / github.com/keploy/keploy / ReadNextDoc

Method ReadNextDoc

pkg/platform/yaml/mockreader.go:181–205  ·  view source on GitHub ↗

ReadNextDoc reads and decodes the next document. For JSON files this still goes through the yaml.Node bridge (via UnmarshalDoc -> jsonDocToYamlDoc) so callers that rely on NetworkTrafficDoc.Spec.Decode(&concreteSpec) keep working. Hot paths that want to stay yaml-free on JSON files should use ReadN

()

Source from the content-addressed store, hash-verified

179// NetworkTrafficDoc.Spec.Decode(&concreteSpec) keep working. Hot paths that
180// want to stay yaml-free on JSON files should use ReadNextDocJSON instead.
181func (r *MockReader) ReadNextDoc() (*NetworkTrafficDoc, error) {
182 data, err := r.ReadNextDocument()
183 if err != nil {
184 return nil, err
185 }
186
187 if len(bytes.TrimSpace(data)) == 0 {
188 return r.ReadNextDoc()
189 }
190
191 if r.format == FormatJSON {
192 doc, err := UnmarshalDoc(FormatJSON, data)
193 if err != nil {
194 return nil, fmt.Errorf("failed to decode JSON at line %d: %w", r.lineNum, err)
195 }
196 return doc, nil
197 }
198
199 var doc NetworkTrafficDoc
200 if err := yamlLib.Unmarshal(data, &doc); err != nil {
201 return nil, fmt.Errorf("failed to decode YAML at line %d: %w", r.lineNum, err)
202 }
203
204 return &doc, nil
205}
206
207// ReadNextDocJSON reads the next NDJSON line and returns it as a
208// NetworkTrafficDocJSON with the spec kept as a json.RawMessage. Only valid

Callers 10

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

Calls 3

ReadNextDocumentMethod · 0.95
UnmarshalDocFunction · 0.85
UnmarshalMethod · 0.80