mirror of
https://github.com/EchoVault/SugarDB.git
synced 2025-10-14 04:03:50 +08:00

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.
32 lines
564 B
Go
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
|
|
}
|