MCPcopy
hub / github.com/buger/jsonparser / calcAllocateSpace

Function calcAllocateSpace

parser.go:682–720  ·  view source on GitHub ↗

SYS-REQ-009

(keys []string, setValue []byte, comma, object bool)

Source from the content-addressed store, hash-verified

680
681// SYS-REQ-009
682func calcAllocateSpace(keys []string, setValue []byte, comma, object bool) int {
683 isIndex := string(keys[0][0]) == "["
684 lk := 0
685 if comma {
686 // ,
687 lk += 1
688 }
689 if isIndex && !comma {
690 // []
691 lk += 2
692 } else {
693 if object {
694 // {
695 lk += 1
696 }
697 if !isIndex {
698 // "keys[0]"
699 lk += len(keys[0]) + 3
700 }
701 }
702
703 lk += len(setValue)
704 for i := 1; i < len(keys); i++ {
705 if string(keys[i][0]) == "[" {
706 // []
707 lk += 2
708 } else {
709 // {"keys[i]":setValue}
710 lk += len(keys[i]) + 5
711 }
712 }
713
714 if object && !isIndex {
715 // }
716 lk += 1
717 }
718
719 return lk
720}
721
722// SYS-REQ-009
723func WriteToBuffer(buffer []byte, str string) int {

Callers 1

createInsertComponentFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…