Loading go-packages/meep-sss-mgr/onem2m-mgr.go +107 −56 Changes for go-packages/meep-sss-mgr/onem2m-mgr.go: 107 added lines, 56 removed lines. Original line number Diff line number Diff line Loading @@ -1054,9 +1054,8 @@ func (tm *SssMgr) oneM2M_deserialize(sensor SensorDiscoveryInfo, response map[st for k, v := range response[s].(map[string]interface{}) { log.Debug("oneM2M_deserialize: Processing k= ", k, ", v= ", v) if e, ok := response[s].(map[string]interface{})[k]; ok { log.Debug("oneM2M_deserialize: ", k, " is a flex attribute: ", v) sensorResp.Flex[k] = e //delete(response[s].(map[string]interface{}), k) log.Debug("oneM2M_deserialize: ", k, " is a flex attribute: ", e) sensorResp.Flex[k] = interface_to_string(e) } } // End of 'for' statement log.Debug("oneM2M_deserialize: After s=", s) Loading Loading @@ -1093,6 +1092,8 @@ func (tm *SssMgr) oneM2M_deserialize(sensor SensorDiscoveryInfo, response map[st sensorResp.SensorType = "CNT" case 4: sensorResp.SensorType = "CIN" case 28: sensorResp.SensorType = "FLX" default: sensorResp.SensorType = strconv.FormatFloat(item, 'f', -1, 64) } Loading @@ -1100,78 +1101,128 @@ func (tm *SssMgr) oneM2M_deserialize(sensor SensorDiscoveryInfo, response map[st log.Error("oneM2M_deserialize: Failed to process ", k) } } else { if item, ok := v.(string); ok { sensorResp.SensorCharacteristicList = append( sensorResp.SensorCharacteristicList, SensorCharacteristic{ CharacteristicName: k, CharacteristicValue: string(item), CharacteristicValue: interface_to_string(v), }) // FIXME FSCOM To be removed // 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.Warn("oneM2M_deserialize: Failed to convert list of int64 into string: ", item) // } else if item, ok := v.(map[string]interface{}); ok { // v, err := json.Marshal(item) // if err == nil { // sensorResp.SensorCharacteristicList = append( // sensorResp.SensorCharacteristicList, // SensorCharacteristic{ // CharacteristicName: k, // CharacteristicValue: string(v), // }) // } else { // log.Warn("oneM2M_deserialize: ", err.Error()) // } // } else if item, ok := v.([]interface{}); ok { // log.Debug("oneM2M_deserialize: Got []interface {} for ", k) // log.Debug("oneM2M_deserialize: ValueOf ", reflect.ValueOf(item)) // v, err := json.Marshal(item) // if err == nil { // sensorResp.SensorCharacteristicList = append( // sensorResp.SensorCharacteristicList, // SensorCharacteristic{ // CharacteristicName: k, // CharacteristicValue: string(v), // }) // } else { // log.Warn("oneM2M_deserialize: ", err.Error()) // } // } else { // log.Warn("oneM2M_deserialize: Failed to process: ", k) // } } } // End of 'for' loop } // End of 'for' loop } log.Debug("oneM2M_deserialize: sensorResp: ", sensorResp) return sensorResp, nil } func interface_to_string(v interface{}) (s string) { if item, ok := v.(string); ok { return string(item) } else if item, ok := v.(float64); ok { sensorResp.SensorCharacteristicList = append( sensorResp.SensorCharacteristicList, SensorCharacteristic{ CharacteristicName: k, CharacteristicValue: strconv.FormatFloat(item, 'f', -1, 64), }) return 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), }) return strconv.FormatInt(item, 10) } else if item, ok := v.(bool); ok { sensorResp.SensorCharacteristicList = append( sensorResp.SensorCharacteristicList, SensorCharacteristic{ CharacteristicName: k, CharacteristicValue: strconv.FormatBool(item), }) return strconv.FormatBool(item) } else if item, ok := v.([]string); ok { sensorResp.SensorCharacteristicList = append( sensorResp.SensorCharacteristicList, SensorCharacteristic{ CharacteristicName: k, CharacteristicValue: strings.Join(item, ","), }) return strings.Join(item, ",") } else if item, ok := v.([]int64); ok { log.Warn("oneM2M_deserialize: Failed to convert list of int64 into string: ", item) log.Debug("interface_to_string: Got []interface {} for ", v) log.Debug("interface_to_string: ValueOf ", reflect.ValueOf(item)) val, err := json.Marshal(item) if err == nil { return string(val) } else { log.Warn("interface_to_string: ", err.Error()) } } else if item, ok := v.(map[string]interface{}); ok { v, err := json.Marshal(item) val, err := json.Marshal(item) if err == nil { sensorResp.SensorCharacteristicList = append( sensorResp.SensorCharacteristicList, SensorCharacteristic{ CharacteristicName: k, CharacteristicValue: string(v), }) return string(val) } else { log.Warn("oneM2M_deserialize: ", err.Error()) log.Warn("interface_to_string: ", err.Error()) } } else if item, ok := v.([]interface{}); ok { log.Debug("oneM2M_deserialize: Got []interface {} for ", k) log.Debug("oneM2M_deserialize: ValueOf ", reflect.ValueOf(item)) v, err := json.Marshal(item) log.Debug("interface_to_string: Got []interface {} for ", v) log.Debug("interface_to_string: ValueOf ", reflect.ValueOf(item)) val, err := json.Marshal(item) if err == nil { sensorResp.SensorCharacteristicList = append( sensorResp.SensorCharacteristicList, SensorCharacteristic{ CharacteristicName: k, CharacteristicValue: string(v), }) return string(val) } else { log.Warn("oneM2M_deserialize: ", err.Error()) log.Warn("interface_to_string: ", err.Error()) } } else { log.Warn("oneM2M_deserialize: Failed to process: ", k) } log.Warn("interface_to_string: Failed to process: ", v) } } // End of 'for' loop } // End of 'for' loop } log.Debug("oneM2M_deserialize: sensorResp: ", sensorResp) return sensorResp, nil return "" } Loading
go-packages/meep-sss-mgr/onem2m-mgr.go +107 −56 Changes for go-packages/meep-sss-mgr/onem2m-mgr.go: 107 added lines, 56 removed lines. Original line number Diff line number Diff line Loading @@ -1054,9 +1054,8 @@ func (tm *SssMgr) oneM2M_deserialize(sensor SensorDiscoveryInfo, response map[st for k, v := range response[s].(map[string]interface{}) { log.Debug("oneM2M_deserialize: Processing k= ", k, ", v= ", v) if e, ok := response[s].(map[string]interface{})[k]; ok { log.Debug("oneM2M_deserialize: ", k, " is a flex attribute: ", v) sensorResp.Flex[k] = e //delete(response[s].(map[string]interface{}), k) log.Debug("oneM2M_deserialize: ", k, " is a flex attribute: ", e) sensorResp.Flex[k] = interface_to_string(e) } } // End of 'for' statement log.Debug("oneM2M_deserialize: After s=", s) Loading Loading @@ -1093,6 +1092,8 @@ func (tm *SssMgr) oneM2M_deserialize(sensor SensorDiscoveryInfo, response map[st sensorResp.SensorType = "CNT" case 4: sensorResp.SensorType = "CIN" case 28: sensorResp.SensorType = "FLX" default: sensorResp.SensorType = strconv.FormatFloat(item, 'f', -1, 64) } Loading @@ -1100,78 +1101,128 @@ func (tm *SssMgr) oneM2M_deserialize(sensor SensorDiscoveryInfo, response map[st log.Error("oneM2M_deserialize: Failed to process ", k) } } else { if item, ok := v.(string); ok { sensorResp.SensorCharacteristicList = append( sensorResp.SensorCharacteristicList, SensorCharacteristic{ CharacteristicName: k, CharacteristicValue: string(item), CharacteristicValue: interface_to_string(v), }) // FIXME FSCOM To be removed // 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.Warn("oneM2M_deserialize: Failed to convert list of int64 into string: ", item) // } else if item, ok := v.(map[string]interface{}); ok { // v, err := json.Marshal(item) // if err == nil { // sensorResp.SensorCharacteristicList = append( // sensorResp.SensorCharacteristicList, // SensorCharacteristic{ // CharacteristicName: k, // CharacteristicValue: string(v), // }) // } else { // log.Warn("oneM2M_deserialize: ", err.Error()) // } // } else if item, ok := v.([]interface{}); ok { // log.Debug("oneM2M_deserialize: Got []interface {} for ", k) // log.Debug("oneM2M_deserialize: ValueOf ", reflect.ValueOf(item)) // v, err := json.Marshal(item) // if err == nil { // sensorResp.SensorCharacteristicList = append( // sensorResp.SensorCharacteristicList, // SensorCharacteristic{ // CharacteristicName: k, // CharacteristicValue: string(v), // }) // } else { // log.Warn("oneM2M_deserialize: ", err.Error()) // } // } else { // log.Warn("oneM2M_deserialize: Failed to process: ", k) // } } } // End of 'for' loop } // End of 'for' loop } log.Debug("oneM2M_deserialize: sensorResp: ", sensorResp) return sensorResp, nil } func interface_to_string(v interface{}) (s string) { if item, ok := v.(string); ok { return string(item) } else if item, ok := v.(float64); ok { sensorResp.SensorCharacteristicList = append( sensorResp.SensorCharacteristicList, SensorCharacteristic{ CharacteristicName: k, CharacteristicValue: strconv.FormatFloat(item, 'f', -1, 64), }) return 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), }) return strconv.FormatInt(item, 10) } else if item, ok := v.(bool); ok { sensorResp.SensorCharacteristicList = append( sensorResp.SensorCharacteristicList, SensorCharacteristic{ CharacteristicName: k, CharacteristicValue: strconv.FormatBool(item), }) return strconv.FormatBool(item) } else if item, ok := v.([]string); ok { sensorResp.SensorCharacteristicList = append( sensorResp.SensorCharacteristicList, SensorCharacteristic{ CharacteristicName: k, CharacteristicValue: strings.Join(item, ","), }) return strings.Join(item, ",") } else if item, ok := v.([]int64); ok { log.Warn("oneM2M_deserialize: Failed to convert list of int64 into string: ", item) log.Debug("interface_to_string: Got []interface {} for ", v) log.Debug("interface_to_string: ValueOf ", reflect.ValueOf(item)) val, err := json.Marshal(item) if err == nil { return string(val) } else { log.Warn("interface_to_string: ", err.Error()) } } else if item, ok := v.(map[string]interface{}); ok { v, err := json.Marshal(item) val, err := json.Marshal(item) if err == nil { sensorResp.SensorCharacteristicList = append( sensorResp.SensorCharacteristicList, SensorCharacteristic{ CharacteristicName: k, CharacteristicValue: string(v), }) return string(val) } else { log.Warn("oneM2M_deserialize: ", err.Error()) log.Warn("interface_to_string: ", err.Error()) } } else if item, ok := v.([]interface{}); ok { log.Debug("oneM2M_deserialize: Got []interface {} for ", k) log.Debug("oneM2M_deserialize: ValueOf ", reflect.ValueOf(item)) v, err := json.Marshal(item) log.Debug("interface_to_string: Got []interface {} for ", v) log.Debug("interface_to_string: ValueOf ", reflect.ValueOf(item)) val, err := json.Marshal(item) if err == nil { sensorResp.SensorCharacteristicList = append( sensorResp.SensorCharacteristicList, SensorCharacteristic{ CharacteristicName: k, CharacteristicValue: string(v), }) return string(val) } else { log.Warn("oneM2M_deserialize: ", err.Error()) log.Warn("interface_to_string: ", err.Error()) } } else { log.Warn("oneM2M_deserialize: Failed to process: ", k) } log.Warn("interface_to_string: Failed to process: ", v) } } // End of 'for' loop } // End of 'for' loop } log.Debug("oneM2M_deserialize: sensorResp: ", sensorResp) return sensorResp, nil return "" }