MCPcopy Create free account
hub / github.com/IceFireDB/IceFireDB / Parse

Function Parse

IceFireDB-PubSub/test/proto/proto.go:234–292  ·  view source on GitHub ↗

Parse into interfaces. `b` must contain exactly a single command (which can be nested).

(b string)

Source from the content-addressed store, hash-verified

232
233// Parse into interfaces. `b` must contain exactly a single command (which can be nested).
234func Parse(b string) (any, error) {
235 if len(b) < 1 {
236 return nil, ErrUnexpected
237 }
238
239 switch b[0] {
240 default:
241 return "", ErrProtocol
242 case '+':
243 return readInline(b)
244 case '-':
245 e, err := readInline(b)
246 if err != nil {
247 return nil, err
248 }
249 return errors.New(e), nil
250 case ':':
251 e, err := readInline(b)
252 if err != nil {
253 return nil, err
254 }
255 return strconv.Atoi(e)
256 case '$':
257 return ReadString(b)
258 case '*':
259 elems, err := ReadArray(b)
260 if err != nil {
261 return nil, err
262 }
263 var res []any
264 for _, elem := range elems {
265 e, err := Parse(elem)
266 if err != nil {
267 return nil, err
268 }
269 res = append(res, e)
270 }
271 return res, nil
272 case '%':
273 elems, err := ReadArray(b)
274 if err != nil {
275 return nil, err
276 }
277 res := map[any]any{}
278 for len(elems) > 1 {
279 key, err := Parse(elems[0])
280 if err != nil {
281 return nil, err
282 }
283 value, err := Parse(elems[1])
284 if err != nil {
285 return nil, err
286 }
287 res[key] = value
288 elems = elems[2:]
289 }
290 return res, nil
291 }

Callers 7

directDoStringFunction · 0.92
directDoStringErrFunction · 0.92
directDoIntFunction · 0.92
directDoIntErrFunction · 0.92
directDoBoolFunction · 0.92
directDoBoolErrFunction · 0.92
TestParseFunction · 0.70

Calls 3

readInlineFunction · 0.70
ReadStringFunction · 0.70
ReadArrayFunction · 0.70

Tested by 7

directDoStringFunction · 0.74
directDoStringErrFunction · 0.74
directDoIntFunction · 0.74
directDoIntErrFunction · 0.74
directDoBoolFunction · 0.74
directDoBoolErrFunction · 0.74
TestParseFunction · 0.56