Files
SugarDB/serialization/decode.go
Kelvin Clement Mwinuka 40be716513 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.
2023-06-24 05:38:59 +08:00

33 lines
436 B
Go

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)
}
}
}
}