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

Function internalGet

parser.go:1233–1258  ·  view source on GitHub ↗

SYS-REQ-001

(data []byte, keys ...string)

Source from the content-addressed store, hash-verified

1231
1232// SYS-REQ-001
1233func internalGet(data []byte, keys ...string) (value []byte, dataType ValueType, offset, endOffset int, err error) {
1234 if len(keys) > 0 {
1235 if offset = searchKeys(data, keys...); offset == -1 {
1236 return nil, NotExist, -1, -1, KeyPathNotFoundError
1237 }
1238 }
1239
1240 // Go to closest value
1241 nO := nextToken(data[offset:])
1242 if nO == -1 {
1243 return nil, NotExist, offset, -1, MalformedJsonError
1244 }
1245
1246 offset += nO
1247 value, dataType, endOffset, err = getType(data, offset)
1248 if err != nil {
1249 return value, dataType, offset, endOffset, err
1250 }
1251
1252 // Strip quotes from string values
1253 if dataType == String {
1254 value = value[1 : len(value)-1]
1255 }
1256
1257 return value[:len(value):len(value)], dataType, offset, endOffset, nil
1258}
1259
1260// SYS-REQ-006, SYS-REQ-028, SYS-REQ-029, SYS-REQ-052, SYS-REQ-053, SYS-REQ-055, SYS-REQ-083
1261// ArrayEach is used when iterating arrays, accepts a callback function with the same return arguments as `Get`.

Callers 4

DeleteFunction · 0.85
SetFunction · 0.85
GetFunction · 0.85

Calls 3

searchKeysFunction · 0.85
nextTokenFunction · 0.85
getTypeFunction · 0.85

Tested by 1