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

Function ReadString

IceFireDB-PubSub/test/proto/proto.go:74–107  ·  view source on GitHub ↗
(b string)

Source from the content-addressed store, hash-verified

72}
73
74func ReadString(b string) (string, error) {
75 r := bufio.NewReader(strings.NewReader(b))
76 line, err := readLine(r)
77 if err != nil {
78 return "", err
79 }
80
81 switch line[0] {
82 default:
83 return "", ErrUnexpected
84 case '$':
85 // bulk strings are: `$5\r\nhello\r\n`
86 length, err := strconv.Atoi(line[1 : len(line)-2])
87 if err != nil {
88 return "", err
89 }
90 if length < 0 {
91 // -1 is a nil response
92 return "", nil
93 }
94 var (
95 buf = make([]byte, length+2)
96 pos = 0
97 )
98 for pos < length+2 {
99 n, err := r.Read(buf[pos:])
100 if err != nil {
101 return "", err
102 }
103 pos += n
104 }
105 return string(buf[:len(buf)-2]), nil
106 }
107}
108
109func readInline(b string) (string, error) {
110 if len(b) < 3 {

Callers 5

directDoFloatErrFunction · 0.92
ReadArrayFunction · 0.70
ReadStringsFunction · 0.70
ParseFunction · 0.70
TestReadStringFunction · 0.70

Calls 2

readLineFunction · 0.70
ReadMethod · 0.45

Tested by 2

directDoFloatErrFunction · 0.74
TestReadStringFunction · 0.56