mirror of
https://github.com/EchoVault/SugarDB.git
synced 2025-10-15 20:40:43 +08:00
32 lines
555 B
Go
32 lines
555 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"}, 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
|
|
}
|