Files
SugarDB/serialization/decode.go
Kelvin Clement Mwinuka f3d36b3c3d Added Error to decoded types.
Removed cmd_functions.go as it is replaced by plugin system.
Consolidated get and set plugins into one plugin setget that handles GET, SET and MGET commands.
Plugins can declare multiple commands that they handle.
2023-07-03 12:35:37 +08:00

32 lines
564 B
Go

package serialization
import (
"bytes"
"github.com/kelvinmwinuka/memstore/utils"
"github.com/tidwall/resp"
)
func Decode(raw string) ([]string, error) {
rd := resp.NewReader(bytes.NewBufferString(raw))
res := []string{}
v, _, err := rd.ReadValue()
if err != nil {
return nil, err
}
if utils.Contains[string]([]string{"SimpleString", "Integer", "Error"}, v.Type().String()) {
return []string{v.String()}, nil
}
if v.Type().String() == "Array" {
for _, elem := range v.Array() {
res = append(res, elem.String())
}
}
return res, nil
}