MCPcopy Index your code
hub / github.com/ByteStorage/FlyDB / interfaceToBytes

Function interfaceToBytes

structure/types.go:32–50  ·  view source on GitHub ↗

interfaceToBytes converts an interface to a byte slice

(value interface{})

Source from the content-addressed store, hash-verified

30
31// interfaceToBytes converts an interface to a byte slice
32func interfaceToBytes(value interface{}) ([]byte, error, string) {
33 switch value := value.(type) {
34
35 case string:
36 return []byte(value), nil, "string"
37 case int:
38 return []byte(strconv.Itoa(value)), nil, "int"
39 case int64:
40 return []byte(strconv.FormatInt(value, 10)), nil, "int64"
41 case float64:
42 return []byte(strconv.FormatFloat(value, 'f', -1, 64)), nil, "float64"
43 case bool:
44 return []byte(strconv.FormatBool(value)), nil, "bool"
45 case []byte:
46 return value, nil, "[]byte"
47 default:
48 return nil, errors.New("unsupported type"), ""
49 }
50}
51
52func interfaceToString(value interface{}) (string, error) {
53 switch value := value.(type) {

Callers 15

HSetMethod · 0.85
HGetMethod · 0.85
HMGetMethod · 0.85
HDelMethod · 0.85
HExistsMethod · 0.85
HUpdateMethod · 0.85
HIncrByMethod · 0.85
HIncrByFloatMethod · 0.85
HDecrByMethod · 0.85
HStrLenMethod · 0.85
HMoveMethod · 0.85
HSetNXMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected