mirror of
https://github.com/EchoVault/SugarDB.git
synced 2025-10-16 04:50:45 +08:00
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:
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user