Skip to content

Commit fd780ae

Browse files
walzsijhedberg
authored andcommitted
net: lwm2m: fix missing name entries for time-serialized resource instances
The LwM2M SENML JSON/CBOR decoder expects a name entry for every time-serialized record. While this was already the case for resources, resource instances were missing their corresponding name entries. This change ensures consistency by adding name entries for resource instances as well. Signed-off-by: Simon Walz <[email protected]>
1 parent 20be667 commit fd780ae

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

subsys/net/lib/lwm2m/lwm2m_rw_senml_cbor.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -346,19 +346,19 @@ static int put_begin_ri(struct lwm2m_output_context *out, struct lwm2m_obj_path
346346

347347
static int put_name_nth_ri(struct lwm2m_output_context *out, struct lwm2m_obj_path *path)
348348
{
349-
int ret = 0;
350349
struct cbor_out_fmt_data *fd = LWM2M_OFD_CBOR(out);
351350
struct record *record = GET_CBOR_FD_REC(fd);
352351

353352
/* With the first ri the resource name (and ri name) are already in place*/
354-
if (path->res_inst_id > 0) {
355-
ret = put_begin_ri(out, path);
356-
} else if (record && record->record_t_present) {
357-
/* Name need to be add for each time serialized record */
358-
ret = put_begin_r(out, path);
353+
if (record == NULL || !record->record_t_present) {
354+
return 0;
355+
}
356+
/* Name need to be add for each time serialized record */
357+
if (path->level == LWM2M_PATH_LEVEL_RESOURCE_INST) {
358+
return put_begin_ri(out, path);
359359
}
360360

361-
return ret;
361+
return put_begin_r(out, path);
362362
}
363363

364364
static int put_value(struct lwm2m_output_context *out, struct lwm2m_obj_path *path, int64_t value)

0 commit comments

Comments
 (0)