func()

in ubjson/parse.go [610:665]


func (p *Parser) stepObjectCountedContent(b []byte, typed bool) (bool, []byte, error) {
	var (
		err  error
		st   = &p.state.current
		step = st.stateStep
		end  = false
	)

	switch step {
	case stWithLen:
		L := p.length.current
		err := p.visitor.OnObjectStart(int(L), structform.AnyType)
		if err != nil {
			return end, b, err
		}

		if L == 0 {
			end = p.length.current == 0
			break
		}

		st.stateStep = stFieldName
		fallthrough

	case stFieldName:
		end = p.length.current == 0
		if end {
			break
		}
		b, err = p.stepLen(b, st.withStep(stFieldNameLen))

	case stFieldNameLen:
		L := p.length.current
		var tmp []byte
		if b, tmp = p.collect(b, int(L)); tmp != nil {
			p.popLen()
			err = p.strVisitor.OnKeyRef(tmp)
		}
		st.stateStep = stCont

	case stCont:
		p.length.current--
		st.stateStep = stFieldName
		// handle object field value
		if typed {
			p.pushState(p.valueState.current)
		} else {
			b, _, err = p.stepValue(b)
		}
	}

	if end {
		err = p.visitor.OnObjectFinished()
	}
	return end, b, err
}