diff options
| author | alex <[email protected]> | 2026-07-04 22:37:16 +0200 |
|---|---|---|
| committer | alex <[email protected]> | 2026-07-04 22:37:16 +0200 |
| commit | 04d91d6e20ce2bdb01703c1ad1ac3073f237e42e (patch) | |
| tree | 3958feb5c93b7b7fa9d2827d27bafe50c4c395f5 /main.go | |
| parent | ced1427b43d68fe0f40cdf3cb304b06eefd6153f (diff) | |
| download | redis-clone-04d91d6e20ce2bdb01703c1ad1ac3073f237e42e.tar.xz redis-clone-04d91d6e20ce2bdb01703c1ad1ac3073f237e42e.zip | |
added bulk string parsing
Diffstat (limited to 'main.go')
| -rw-r--r-- | main.go | 19 |
1 files changed, 19 insertions, 0 deletions
@@ -172,7 +172,26 @@ func parseRESP(reader *bufio.Reader) ([]string, error) { args = append(args, string(buf)) } return args, nil + case '$': + strLen, _ := strconv.Atoi(strings.TrimSpace(line[1:])) + if strLen == -1 { + return []string{""}, nil + } + + buf := make([]byte, strLen) + + _, err = io.ReadFull(reader, buf) + if err != nil { + return nil, err + } + + _, err = reader.Discard(2) + if err != nil { + return nil, err + } + + return []string{string(buf)}, nil case '+': cleanStr := strings.TrimSpace(line[1:]) return []string{cleanStr}, nil |
