MCPcopy Create free account
hub / github.com/bcicen/jstream / object

Method object

decoder.go:459–541  ·  view source on GitHub ↗

object accept valid JSON array value

()

Source from the content-addressed store, hash-verified

457
458// object accept valid JSON array value
459func (d *Decoder) object() (map[string]interface{}, error) {
460 d.depth++
461
462 var (
463 c byte
464 k string
465 v interface{}
466 t ValueType
467 err error
468 obj map[string]interface{}
469 )
470
471 // skip allocating map if it will not be emitted
472 if d.depth > d.emitDepth {
473 obj = make(map[string]interface{})
474 }
475
476 // if the object has no keys
477 if c = d.skipSpaces(); c == '}' {
478 goto out
479 }
480
481scan:
482 for {
483 offset := d.pos - 1
484
485 // read string key
486 if c != '"' {
487 err = d.mkError(ErrSyntax, "looking for beginning of object key string")
488 break
489 }
490 if k, err = d.string(); err != nil {
491 break
492 }
493
494 // read colon before value
495 if c = d.skipSpaces(); c != ':' {
496 err = d.mkError(ErrSyntax, "after object key")
497 break
498 }
499
500 // read value
501 d.skipSpaces()
502 if d.emitKV {
503 if v, t, err = d.any(); err != nil {
504 break
505 }
506 if d.willEmit() {
507 d.metaCh <- &MetaValue{
508 Offset: int(offset),
509 Length: int(d.pos - offset),
510 Depth: d.depth,
511 Value: KV{k, v},
512 ValueType: t,
513 }
514 }
515 } else {
516 if v, err = d.emitAny(); err != nil {

Callers 1

anyMethod · 0.95

Calls 6

skipSpacesMethod · 0.95
mkErrorMethod · 0.95
stringMethod · 0.95
anyMethod · 0.95
willEmitMethod · 0.95
emitAnyMethod · 0.95

Tested by

no test coverage detected