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

Function byteToInterface

structure/types.go:90–123  ·  view source on GitHub ↗

func byteToInterface(value []byte, dataType string) (interface{}, error) { switch dataType { case "string": return string(value), nil case "int": return strconv.Atoi(string(value)) case "int64": return strconv.ParseInt(string(value), 10, 64) case "float64": return strconv.ParseFloat(str

(value []byte, dataType string)

Source from the content-addressed store, hash-verified

88//}
89
90func byteToInterface(value []byte, dataType string) (interface{}, error) {
91 switch dataType {
92 case "string":
93 return string(value), nil
94 case "int":
95 intValue, err := strconv.Atoi(string(value))
96 if err != nil {
97 return nil, errors.New("cannot convert to int: " + err.Error())
98 }
99 return intValue, nil
100 case "int64":
101 int64Value, err := strconv.ParseInt(string(value), 10, 64)
102 if err != nil {
103 return nil, errors.New("cannot convert to int64: " + err.Error())
104 }
105 return int64Value, nil
106 case "float64":
107 float64Value, err := strconv.ParseFloat(string(value), 64)
108 if err != nil {
109 return nil, errors.New("cannot convert to float64: " + err.Error())
110 }
111 return float64Value, nil
112 case "bool":
113 boolValue, err := strconv.ParseBool(string(value))
114 if err != nil {
115 return nil, errors.New("cannot convert to bool: " + err.Error())
116 }
117 return boolValue, nil
118 case "[]byte":
119 return value, nil
120 default:
121 return nil, errors.New("unsupported type")
122 }
123}
124
125// convertToInt converts an interface to an int
126func convertToInt(Value interface{}) (int, error) {

Callers 3

HGetMethod · 0.85
HMGetMethod · 0.85
GetMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected