Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make lwm2m object response body pointer to avoid decode failed #1084

Merged
merged 1 commit into from
Dec 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions pkg/gateway/lwm2m/client/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@
}

type ObjectData struct {
ParameterName string `json:"n,omitempty"`
FloatValue float64 `json:"v,omitempty"`
StringValue string `json:"sv,omitempty"`
ParameterName *string `json:"n,omitempty"`
FloatValue *float64 `json:"v,omitempty"`
StringValue *string `json:"sv,omitempty"`
// Pointer to avoid marshal false value
BoolValue *bool `json:"bv,omitempty"`
}
Expand Down Expand Up @@ -113,16 +113,19 @@

switch newData := data.(type) {
case int, int32, int64, int16, int8:
objectDataList = append(objectDataList, ObjectData{ParameterName: basePath, FloatValue: float64(newData.(int))})
var floatValue = float64(newData.(int))
objectDataList = append(objectDataList, ObjectData{ParameterName: &basePath, FloatValue: &floatValue})

Check warning on line 117 in pkg/gateway/lwm2m/client/object.go

View check run for this annotation

Codecov / codecov/patch

pkg/gateway/lwm2m/client/object.go#L116-L117

Added lines #L116 - L117 were not covered by tests
case float32, float64:
objectDataList = append(objectDataList, ObjectData{ParameterName: basePath, FloatValue: newData.(float64)})
var floatValue = newData.(float64)
objectDataList = append(objectDataList, ObjectData{ParameterName: &basePath, FloatValue: &floatValue})

Check warning on line 120 in pkg/gateway/lwm2m/client/object.go

View check run for this annotation

Codecov / codecov/patch

pkg/gateway/lwm2m/client/object.go#L119-L120

Added lines #L119 - L120 were not covered by tests
case string:
objectDataList = append(objectDataList, ObjectData{ParameterName: basePath, StringValue: newData})
objectDataList = append(objectDataList, ObjectData{ParameterName: &basePath, StringValue: &newData})
case bool:
objectDataList = append(objectDataList, ObjectData{ParameterName: basePath, BoolValue: &newData})
objectDataList = append(objectDataList, ObjectData{ParameterName: &basePath, BoolValue: &newData})

Check warning on line 124 in pkg/gateway/lwm2m/client/object.go

View check run for this annotation

Codecov / codecov/patch

pkg/gateway/lwm2m/client/object.go#L124

Added line #L124 was not covered by tests
default:
// default to string
objectDataList = append(objectDataList, ObjectData{ParameterName: basePath, StringValue: fmt.Sprintf("%v", data)})
var stringValue = fmt.Sprintf("%v", data)
objectDataList = append(objectDataList, ObjectData{ParameterName: &basePath, StringValue: &stringValue})

Check warning on line 128 in pkg/gateway/lwm2m/client/object.go

View check run for this annotation

Codecov / codecov/patch

pkg/gateway/lwm2m/client/object.go#L127-L128

Added lines #L127 - L128 were not covered by tests
}
}

Expand Down
Loading