Newer
Older
log.Error("oneM2M_deserialize: CharacteristicName not found")
}
for i, m := range response {
log.Debug("==> ", i, " value is ", m)
// m is a map[string]interface.
// loop over keys and values in the map.
for k, v := range m {
log.Debug(k, " value is ", v)
log.Debug("oneM2M_deserialize: type(v): ", reflect.TypeOf(v))
if k == "ri" {
if item, ok := v.(string); ok {
sensor.SensorIdentifier = item
} else {
log.Error("populateSensors: Failed to process ", k)
}
} else if k == "ty" {
if item, ok := v.(string); ok {
sensor.SensorType = item
} else {
log.Error("populateSensors: Failed to process ", k)
}
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
if item, ok := v.(string); ok {
sensorResp.SensorCharacteristicList = append(
sensorResp.SensorCharacteristicList,
SensorCharacteristic{
CharacteristicName: k,
CharacteristicValue: string(item),
})
} else if item, ok := v.(float64); ok {
sensorResp.SensorCharacteristicList = append(
sensorResp.SensorCharacteristicList,
SensorCharacteristic{
CharacteristicName: k,
CharacteristicValue: strconv.FormatFloat(item, 'f', -1, 64),
})
} else if item, ok := v.(int64); ok {
sensorResp.SensorCharacteristicList = append(
sensorResp.SensorCharacteristicList,
SensorCharacteristic{
CharacteristicName: k,
CharacteristicValue: strconv.FormatInt(item, 10),
})
} else if item, ok := v.(bool); ok {
sensorResp.SensorCharacteristicList = append(
sensorResp.SensorCharacteristicList,
SensorCharacteristic{
CharacteristicName: k,
CharacteristicValue: strconv.FormatBool(item),
})
} else if item, ok := v.([]string); ok {
sensorResp.SensorCharacteristicList = append(
sensorResp.SensorCharacteristicList,
SensorCharacteristic{
CharacteristicName: k,
CharacteristicValue: strings.Join(item, ","),
})
} else if item, ok := v.([]int64); ok {
log.Error("oneM2M_deserialize: Failed to convert list of int64 into string: ", item)
} else if item, ok := v.([]interface{}); ok {
log.Debug("populateSensors: Got []interface {} for ", k)
log.Debug("populateSensors: ValueOf ", reflect.ValueOf(item))
s := SensorCharacteristic{
CharacteristicName: k,
}
var buf bytes.Buffer
fmt.Fprintf(&buf, "%T", item)
s.CharacteristicValue = buf.String()
sensor.SensorCharacteristicList = append(sensor.SensorCharacteristicList, s)
} else {
log.Error("oneM2M_deserialize: Failed to process: ", k)
}
}
} // End of 'for' loop
} // End of 'for' loop