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

Function ReadArray

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

Read an array, with all elements are the raw redis commands Also reads sets and maps.

(b string)

Source from the content-addressed store, hash-verified

28// Read an array, with all elements are the raw redis commands
29// Also reads sets and maps.
30func ReadArray(b string) ([]string, error) {
31 r := bufio.NewReader(strings.NewReader(b))
32 line, err := readLine(r)
33 if err != nil {
34 return nil, err
35 }
36
37 elems := 0
38 switch line[0] {
39 default:
40 return nil, ErrUnexpected
41 case '*', '>', '~':
42 // *: array
43 // >: push data
44 // ~: set
45 length, err := strconv.Atoi(line[1 : len(line)-2])
46 if err != nil {
47 return nil, err
48 }
49 elems = length
50 case '%':
51 // we also read maps.
52 length, err := strconv.Atoi(line[1 : len(line)-2])
53 if err != nil {
54 return nil, err
55 }
56 elems = length * 2
57 }
58
59 var res []string
60 for i := 0; i < elems; i++ {
61 next, err := Read(r)
62 if err != nil {
63 return nil, err
64 }
65 next, err = ReadString(next)
66 if err != nil {
67 return nil, err
68 }
69 res = append(res, next)
70 }
71 return res, nil
72}
73
74func ReadString(b string) (string, error) {
75 r := bufio.NewReader(strings.NewReader(b))

Callers 4

directDoStringArrErrFunction · 0.92
ReadStringsFunction · 0.70
ParseFunction · 0.70
TestReadArrayFunction · 0.70

Calls 3

readLineFunction · 0.70
ReadFunction · 0.70
ReadStringFunction · 0.70

Tested by 2

directDoStringArrErrFunction · 0.74
TestReadArrayFunction · 0.56