mirror of
https://github.com/EchoVault/SugarDB.git
synced 2025-10-15 04:20:57 +08:00

Created encoding functions for the following commands: ping, set, setnx, get, mget, incr, incrby, incrbyfloat. Created utils packages for shared utility functions.
33 lines
436 B
Go
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)
|
|
}
|
|
}
|
|
}
|
|
}
|