MCPcopy Create free account
hub / github.com/buger/jsonparser / calcAllocateSpace

Function calcAllocateSpace

parser.go:1106–1146  ·  view source on GitHub ↗

SYS-REQ-009, SYS-REQ-111

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

Source from the content-addressed store, hash-verified

1104
1105// SYS-REQ-009, SYS-REQ-111
1106func calcAllocateSpace(keys []string, setValue []byte, comma, object bool) int {
1107 // guard: empty key component — not an array index.
1108 isIndex := len(keys[0]) > 0 && string(keys[0][0]) == "["
1109 lk := 0
1110 if comma {
1111 // ,
1112 lk += 1
1113 }
1114 if isIndex && !comma {
1115 // []
1116 lk += 2
1117 } else {
1118 if object {
1119 // {
1120 lk += 1
1121 }
1122 if !isIndex {
1123 // "keys[0]"
1124 lk += len(keys[0]) + 3
1125 }
1126 }
1127
1128 lk += len(setValue)
1129 for i := 1; i < len(keys); i++ {
1130 // guard: empty key component — treat as object key, not array index.
1131 if len(keys[i]) > 0 && string(keys[i][0]) == "[" {
1132 // []
1133 lk += 2
1134 } else {
1135 // {"keys[i]":setValue}
1136 lk += len(keys[i]) + 5
1137 }
1138 }
1139
1140 if object && !isIndex {
1141 // }
1142 lk += 1
1143 }
1144
1145 return lk
1146}
1147
1148// SYS-REQ-009
1149func WriteToBuffer(buffer []byte, str string) int {

Calls

no outgoing calls