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

Function calcAllocateSpace

parser.go:1125–1165  ·  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

1123
1124// SYS-REQ-009, SYS-REQ-111
1125func calcAllocateSpace(keys []string, setValue []byte, comma, object bool) int {
1126 // guard: empty key component — not an array index.
1127 isIndex := len(keys[0]) > 0 && string(keys[0][0]) == "["
1128 lk := 0
1129 if comma {
1130 // ,
1131 lk += 1
1132 }
1133 if isIndex && !comma {
1134 // []
1135 lk += 2
1136 } else {
1137 if object {
1138 // {
1139 lk += 1
1140 }
1141 if !isIndex {
1142 // "keys[0]"
1143 lk += len(keys[0]) + 3
1144 }
1145 }
1146
1147 lk += len(setValue)
1148 for i := 1; i < len(keys); i++ {
1149 // guard: empty key component — treat as object key, not array index.
1150 if len(keys[i]) > 0 && string(keys[i][0]) == "[" {
1151 // []
1152 lk += 2
1153 } else {
1154 // {"keys[i]":setValue}
1155 lk += len(keys[i]) + 5
1156 }
1157 }
1158
1159 if object && !isIndex {
1160 // }
1161 lk += 1
1162 }
1163
1164 return lk
1165}
1166
1167// SYS-REQ-009
1168func WriteToBuffer(buffer []byte, str string) int {

Calls

no outgoing calls