MCPcopy Index your code
hub / github.com/apache/iotdb-client-go / valuesToBytes

Function valuesToBytes

client/session.go:1113–1196  ·  view source on GitHub ↗
(dataTypes []TSDataType, values []interface{}, measurementNames []string)

Source from the content-addressed store, hash-verified

1111}
1112
1113func valuesToBytes(dataTypes []TSDataType, values []interface{}, measurementNames []string) ([]byte, error) {
1114 buff := &bytes.Buffer{}
1115 for i, t := range dataTypes {
1116 binary.Write(buff, binary.BigEndian, byte(t))
1117 v := values[i]
1118 if v == nil {
1119 return nil, fmt.Errorf("values[%d] can't be nil", i)
1120 }
1121
1122 switch t {
1123 case BOOLEAN:
1124 switch v.(type) {
1125 case bool:
1126 binary.Write(buff, binary.BigEndian, v)
1127 default:
1128 return nil, fmt.Errorf("measurement %s values[%d] %v(%v) must be bool", measurementNames[i], i, v, reflect.TypeOf(v))
1129 }
1130 case INT32:
1131 switch v.(type) {
1132 case int32:
1133 binary.Write(buff, binary.BigEndian, v)
1134 default:
1135 return nil, fmt.Errorf("measurement %s values[%d] %v(%v) must be int32", measurementNames[i], i, v, reflect.TypeOf(v))
1136 }
1137 case INT64, TIMESTAMP:
1138 switch v.(type) {
1139 case int64:
1140 binary.Write(buff, binary.BigEndian, v)
1141 default:
1142 return nil, fmt.Errorf("measurement %s values[%d] %v(%v) must be int64", measurementNames[i], i, v, reflect.TypeOf(v))
1143 }
1144 case FLOAT:
1145 switch v.(type) {
1146 case float32:
1147 binary.Write(buff, binary.BigEndian, v)
1148 default:
1149 return nil, fmt.Errorf("measurement %s values[%d] %v(%v) must be float32", measurementNames[i], i, v, reflect.TypeOf(v))
1150 }
1151 case DOUBLE:
1152 switch v.(type) {
1153 case float64:
1154 binary.Write(buff, binary.BigEndian, v)
1155 default:
1156 return nil, fmt.Errorf("measurement %s values[%d] %v(%v) must be float64", measurementNames[i], i, v, reflect.TypeOf(v))
1157 }
1158 case TEXT, STRING:
1159 switch s := v.(type) {
1160 case string:
1161 size := len(s)
1162 binary.Write(buff, binary.BigEndian, int32(size))
1163 binary.Write(buff, binary.BigEndian, []byte(s))
1164 case []byte:
1165 size := len(s)
1166 binary.Write(buff, binary.BigEndian, int32(size))
1167 binary.Write(buff, binary.BigEndian, s)
1168 default:
1169 return nil, fmt.Errorf("measurement %s values[%d] %v(%v) must be string or []byte", measurementNames[i], i, v, reflect.TypeOf(v))
1170 }

Callers 4

genTSInsertRecordReqMethod · 0.85
genInsertRecordsReqMethod · 0.85

Calls 2

DateToInt32Function · 0.85
WriteMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…