Added resp package for encoding and decoding resp messages.

Created encoding functions for the following commands: ping, set, setnx, get, mget, incr, incrby, incrbyfloat.
Created utils packages for shared utility functions.
This commit is contained in:
Kelvin Clement Mwinuka
2023-06-24 05:38:59 +08:00
parent 0b1c76f8b6
commit 40be716513
16 changed files with 1412 additions and 79 deletions

View File

@@ -1 +1,32 @@
package serialization
import (
"bytes"
"fmt"
"io"
"github.com/tidwall/resp"
)
func Decode(raw string) {
rd := resp.NewReader(bytes.NewBufferString(raw))
for {
v, _, err := rd.ReadValue()
if err == io.EOF {
break
}
if err != nil {
fmt.Println(err)
}
fmt.Println(v)
if v.Type().String() == "Array" {
for _, elem := range v.Array() {
fmt.Printf("%s: %v\n", elem.Type().String(), elem)
}
}
}
}