net: lwm2m: SenML CBOR optimisations
Regenerates the encoder and decoder. Treats integers and floating-point values as separate entities instead of saying that those are numerical values. Brings some memory savings. Signed-off-by: Veijo Pesonen <veijo.pesonen@nordicsemi.no>
This commit is contained in:
parent
b78dd2498a
commit
98b22a1850
|
@ -304,9 +304,8 @@ static int put_value(struct lwm2m_output_context *out, struct lwm2m_obj_path *pa
|
|||
struct record *record = CONSUME_CBOR_FD_REC(LWM2M_OFD_CBOR(out));
|
||||
|
||||
/* Write the value */
|
||||
record->_record_union._record_union_choice = _union_v;
|
||||
record->_record_union._union_v._numeric_choice = _numeric_int;
|
||||
record->_record_union._union_v._numeric_int = value;
|
||||
record->_record_union._record_union_choice = _union_vi;
|
||||
record->_record_union._union_vi = value;
|
||||
record->_record_union_present = 1;
|
||||
|
||||
return 0;
|
||||
|
@ -343,9 +342,8 @@ static int put_time(struct lwm2m_output_context *out, struct lwm2m_obj_path *pat
|
|||
struct record *record = CONSUME_CBOR_FD_REC(LWM2M_OFD_CBOR(out));
|
||||
|
||||
/* Write the value */
|
||||
record->_record_union._record_union_choice = _union_v;
|
||||
record->_record_union._union_v._numeric_choice = _numeric_int;
|
||||
record->_record_union._union_v._numeric_int = value;
|
||||
record->_record_union._record_union_choice = _union_vi;
|
||||
record->_record_union._union_vi = value;
|
||||
record->_record_union_present = 1;
|
||||
|
||||
return 0;
|
||||
|
@ -362,9 +360,8 @@ static int put_float(struct lwm2m_output_context *out, struct lwm2m_obj_path *pa
|
|||
struct record *record = CONSUME_CBOR_FD_REC(LWM2M_OFD_CBOR(out));
|
||||
|
||||
/* Write the value */
|
||||
record->_record_union._record_union_choice = _union_v;
|
||||
record->_record_union._union_v._numeric_choice = _numeric_float;
|
||||
record->_record_union._union_v._numeric_float = *value;
|
||||
record->_record_union._record_union_choice = _union_vf;
|
||||
record->_record_union._union_vf = *value;
|
||||
record->_record_union_present = 1;
|
||||
|
||||
return 0;
|
||||
|
@ -477,7 +474,7 @@ static int get_s32(struct lwm2m_input_context *in, int32_t *value)
|
|||
return -EINVAL;
|
||||
}
|
||||
|
||||
*value = fd->current->_record_union._union_v._numeric_int;
|
||||
*value = fd->current->_record_union._union_vi;
|
||||
fd->current = NULL;
|
||||
|
||||
return 0;
|
||||
|
@ -492,7 +489,7 @@ static int get_s64(struct lwm2m_input_context *in, int64_t *value)
|
|||
return -EINVAL;
|
||||
}
|
||||
|
||||
*value = fd->current->_record_union._union_v._numeric_int;
|
||||
*value = fd->current->_record_union._union_vi;
|
||||
fd->current = NULL;
|
||||
|
||||
return 0;
|
||||
|
@ -507,7 +504,7 @@ static int get_float(struct lwm2m_input_context *in, double *value)
|
|||
return -EINVAL;
|
||||
}
|
||||
|
||||
*value = fd->current->_record_union._union_v._numeric_float;
|
||||
*value = fd->current->_record_union._union_vf;
|
||||
fd->current = NULL;
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
/*
|
||||
* Generated using zcbor version 0.3.99
|
||||
* Generated using zcbor version 0.4.0
|
||||
* https://github.com/zephyrproject-rtos/zcbor
|
||||
* Generated with a --default-max-qty of 99
|
||||
*/
|
||||
|
@ -43,47 +43,31 @@ static bool decode_repeated_record_n(zcbor_state_t *state, struct record_n *resu
|
|||
return tmp_result;
|
||||
}
|
||||
|
||||
static bool decode_numeric(zcbor_state_t *state, struct numeric_ *result)
|
||||
{
|
||||
zcbor_print("%s\r\n", __func__);
|
||||
bool int_res;
|
||||
|
||||
bool tmp_result =
|
||||
(((zcbor_union_start_code(state) &&
|
||||
(int_res = ((((zcbor_int64_decode(state, (&(*result)._numeric_int))) &&
|
||||
((((*result)._numeric_int >= -9223372036854775807LL) &&
|
||||
((*result)._numeric_int <= 9223372036854775807LL)) ||
|
||||
(zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false))) &&
|
||||
(((*result)._numeric_choice = _numeric_int) || 1)) ||
|
||||
(((zcbor_float_decode(state, (&(*result)._numeric_float)))) &&
|
||||
(((*result)._numeric_choice = _numeric_float) || 1))),
|
||||
zcbor_union_end_code(state), int_res))));
|
||||
|
||||
if (!tmp_result)
|
||||
zcbor_trace();
|
||||
|
||||
return tmp_result;
|
||||
}
|
||||
|
||||
static bool decode_repeated_record_union(zcbor_state_t *state, struct record_union_ *result)
|
||||
{
|
||||
zcbor_print("%s\r\n", __func__);
|
||||
bool int_res;
|
||||
|
||||
bool tmp_result = (((zcbor_union_start_code(state) &&
|
||||
(int_res = (((((zcbor_uint32_expect_union(state, (2)))) &&
|
||||
(decode_numeric(state, (&(*result)._union_v)))) &&
|
||||
(((*result)._record_union_choice = _union_v) || 1)) ||
|
||||
((((zcbor_uint32_expect_union(state, (3)))) &&
|
||||
(zcbor_tstr_decode(state, (&(*result)._union_vs)))) &&
|
||||
(((*result)._record_union_choice = _union_vs) || 1)) ||
|
||||
((((zcbor_uint32_expect_union(state, (4)))) &&
|
||||
(zcbor_bool_decode(state, (&(*result)._union_vb)))) &&
|
||||
(((*result)._record_union_choice = _union_vb) || 1)) ||
|
||||
((((zcbor_uint32_expect_union(state, (8)))) &&
|
||||
(zcbor_bstr_decode(state, (&(*result)._union_vd)))) &&
|
||||
(((*result)._record_union_choice = _union_vd) || 1))),
|
||||
zcbor_union_end_code(state), int_res))));
|
||||
bool tmp_result = (((zcbor_union_start_code(state) && (int_res = (
|
||||
((((zcbor_uint32_expect_union(state, (2)))) &&
|
||||
(zcbor_int64_decode(state, (&(*result)._union_vi))) &&
|
||||
((((*result)._union_vi >= -9223372036854775807LL) &&
|
||||
((*result)._union_vi <= 9223372036854775807LL)) ||
|
||||
(zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false))) &&
|
||||
(((*result)._record_union_choice = _union_vi) || 1)) ||
|
||||
((((zcbor_uint32_expect_union(state, (2)))) &&
|
||||
(zcbor_float_decode(state, (&(*result)._union_vf)))) &&
|
||||
(((*result)._record_union_choice = _union_vf) || 1)) ||
|
||||
((((zcbor_uint32_expect_union(state, (3)))) &&
|
||||
(zcbor_tstr_decode(state, (&(*result)._union_vs)))) &&
|
||||
(((*result)._record_union_choice = _union_vs) || 1)) ||
|
||||
((((zcbor_uint32_expect_union(state, (4)))) &&
|
||||
(zcbor_bool_decode(state, (&(*result)._union_vb)))) &&
|
||||
(((*result)._record_union_choice = _union_vb) || 1)) ||
|
||||
((((zcbor_uint32_expect_union(state, (8)))) &&
|
||||
(zcbor_bstr_decode(state, (&(*result)._union_vd)))) &&
|
||||
(((*result)._record_union_choice = _union_vd) || 1))),
|
||||
zcbor_union_end_code(state), int_res))));
|
||||
|
||||
if (!tmp_result)
|
||||
zcbor_trace();
|
||||
|
@ -97,18 +81,21 @@ static bool decode_value(zcbor_state_t *state, struct value_ *result)
|
|||
bool int_res;
|
||||
|
||||
bool tmp_result =
|
||||
(((zcbor_union_start_code(state) &&
|
||||
(int_res = ((((zcbor_tstr_decode(state, (&(*result)._value_tstr)))) &&
|
||||
(((zcbor_union_start_code(state) && (int_res = (
|
||||
(((zcbor_tstr_decode(state, (&(*result)._value_tstr)))) &&
|
||||
(((*result)._value_choice = _value_tstr) || 1)) ||
|
||||
(((zcbor_bstr_decode(state, (&(*result)._value_bstr)))) &&
|
||||
(((zcbor_bstr_decode(state, (&(*result)._value_bstr)))) &&
|
||||
(((*result)._value_choice = _value_bstr) || 1)) ||
|
||||
(zcbor_union_elem_code(state) &&
|
||||
(((decode_numeric(state, (&(*result)._value__numeric)))) &&
|
||||
(((*result)._value_choice = _value__numeric) || 1))) ||
|
||||
(zcbor_union_elem_code(state) &&
|
||||
(((zcbor_bool_decode(state, (&(*result)._value_bool)))) &&
|
||||
(((*result)._value_choice = _value_bool) || 1)))),
|
||||
zcbor_union_end_code(state), int_res))));
|
||||
(((zcbor_int64_decode(state, (&(*result)._value_int))) &&
|
||||
((((*result)._value_int >= -9223372036854775807LL) &&
|
||||
((*result)._value_int <= 9223372036854775807LL)) ||
|
||||
(zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false))) &&
|
||||
(((*result)._value_choice = _value_int) || 1)) ||
|
||||
(((zcbor_float_decode(state, (&(*result)._value_float)))) &&
|
||||
(((*result)._value_choice = _value_float) || 1)) ||
|
||||
(((zcbor_bool_decode(state, (&(*result)._value_bool)))) &&
|
||||
(((*result)._value_choice = _value_bool) || 1))),
|
||||
zcbor_union_end_code(state), int_res))));
|
||||
|
||||
if (!tmp_result)
|
||||
zcbor_trace();
|
||||
|
@ -163,7 +150,7 @@ static bool decode_record(zcbor_state_t *state, struct record *result)
|
|||
state, (&(*result)._record__key_value_pair),
|
||||
sizeof(struct record__key_value_pair))) ||
|
||||
(zcbor_list_map_end_force_decode(state), false)) &&
|
||||
zcbor_map_end_decode(state))));
|
||||
zcbor_map_end_decode(state))));
|
||||
|
||||
if (!tmp_result)
|
||||
zcbor_trace();
|
||||
|
@ -190,10 +177,10 @@ static bool decode_lwm2m_senml(zcbor_state_t *state, struct lwm2m_senml *result)
|
|||
return tmp_result;
|
||||
}
|
||||
|
||||
uint_fast8_t cbor_decode_lwm2m_senml(const uint8_t *payload, size_t payload_len,
|
||||
int cbor_decode_lwm2m_senml(const uint8_t *payload, size_t payload_len,
|
||||
struct lwm2m_senml *result, size_t *payload_len_out)
|
||||
{
|
||||
zcbor_state_t states[6];
|
||||
zcbor_state_t states[5];
|
||||
|
||||
zcbor_new_state(states, sizeof(states) / sizeof(zcbor_state_t), payload, payload_len, 1);
|
||||
|
||||
|
@ -204,7 +191,7 @@ uint_fast8_t cbor_decode_lwm2m_senml(const uint8_t *payload, size_t payload_len,
|
|||
}
|
||||
|
||||
if (!ret) {
|
||||
uint_fast8_t ret = zcbor_pop_error(states);
|
||||
int ret = zcbor_pop_error(states);
|
||||
|
||||
return (ret == ZCBOR_SUCCESS) ? ZCBOR_ERR_UNKNOWN : ret;
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
/*
|
||||
* Generated using zcbor version 0.3.99
|
||||
* Generated using zcbor version 0.4.0
|
||||
* https://github.com/zephyrproject-rtos/zcbor
|
||||
* Generated with a --default-max-qty of 99
|
||||
*/
|
||||
|
@ -19,7 +19,7 @@
|
|||
#include "zcbor_decode.h"
|
||||
#include "lwm2m_senml_cbor_types.h"
|
||||
|
||||
uint_fast8_t cbor_decode_lwm2m_senml(const uint8_t *payload, size_t payload_len,
|
||||
int cbor_decode_lwm2m_senml(const uint8_t *payload, size_t payload_len,
|
||||
struct lwm2m_senml *result, size_t *payload_len_out);
|
||||
|
||||
#endif /* LWM2M_SENML_CBOR_DECODE_H__ */
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
/*
|
||||
* Generated using zcbor version 0.3.99
|
||||
* Generated using zcbor version 0.4.0
|
||||
* https://github.com/zephyrproject-rtos/zcbor
|
||||
* Generated with a --default-max-qty of 99
|
||||
*/
|
||||
|
@ -43,45 +43,29 @@ static bool encode_repeated_record_n(zcbor_state_t *state, const struct record_n
|
|||
return tmp_result;
|
||||
}
|
||||
|
||||
static bool encode_numeric(zcbor_state_t *state, const struct numeric_ *input)
|
||||
{
|
||||
zcbor_print("%s\r\n", __func__);
|
||||
|
||||
bool tmp_result =
|
||||
(((((*input)._numeric_choice == _numeric_int) ?
|
||||
(((((*input)._numeric_int >= -9223372036854775807LL) &&
|
||||
((*input)._numeric_int <= 9223372036854775807LL)) ||
|
||||
(zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false)) &&
|
||||
(zcbor_int64_encode(state, (&(*input)._numeric_int)))) :
|
||||
(((*input)._numeric_choice == _numeric_float) ?
|
||||
((zcbor_float64_encode(state, (&(*input)._numeric_float)))) :
|
||||
false))));
|
||||
|
||||
if (!tmp_result)
|
||||
zcbor_trace();
|
||||
|
||||
return tmp_result;
|
||||
}
|
||||
|
||||
static bool encode_repeated_record_union(zcbor_state_t *state, const struct record_union_ *input)
|
||||
{
|
||||
zcbor_print("%s\r\n", __func__);
|
||||
|
||||
bool tmp_result =
|
||||
(((((*input)._record_union_choice == _union_v) ?
|
||||
(((zcbor_uint32_put(state, (2)))) &&
|
||||
(encode_numeric(state, (&(*input)._union_v)))) :
|
||||
(((*input)._record_union_choice == _union_vs) ?
|
||||
(((zcbor_uint32_put(state, (3)))) &&
|
||||
(zcbor_tstr_encode(state, (&(*input)._union_vs)))) :
|
||||
(((*input)._record_union_choice == _union_vb) ?
|
||||
(((zcbor_uint32_put(state, (4)))) &&
|
||||
(zcbor_bool_encode(state, (&(*input)._union_vb)))) :
|
||||
(((*input)._record_union_choice == _union_vd) ?
|
||||
(((zcbor_uint32_put(state, (8)))) &&
|
||||
(zcbor_bstr_encode(state,
|
||||
(&(*input)._union_vd)))) :
|
||||
false))))));
|
||||
(((((*input)._record_union_choice == _union_vi) ?
|
||||
(((zcbor_uint32_put(state, (2)))) &&
|
||||
((((*input)._union_vi >= -9223372036854775807LL) &&
|
||||
((*input)._union_vi <= 9223372036854775807LL)) ||
|
||||
(zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false)) &&
|
||||
(zcbor_int64_encode(state, (&(*input)._union_vi)))) :
|
||||
(((*input)._record_union_choice == _union_vf) ?
|
||||
(((zcbor_uint32_put(state, (2)))) &&
|
||||
(zcbor_float64_encode(state, (&(*input)._union_vf)))) :
|
||||
(((*input)._record_union_choice == _union_vs) ?
|
||||
(((zcbor_uint32_put(state, (3)))) &&
|
||||
(zcbor_tstr_encode(state, (&(*input)._union_vs)))) :
|
||||
(((*input)._record_union_choice == _union_vb) ?
|
||||
(((zcbor_uint32_put(state, (4)))) &&
|
||||
(zcbor_bool_encode(state, (&(*input)._union_vb)))) :
|
||||
(((*input)._record_union_choice == _union_vd) ?
|
||||
(((zcbor_uint32_put(state, (8)))) &&
|
||||
(zcbor_bstr_encode(state, (&(*input)._union_vd)))) : false)))))));
|
||||
|
||||
if (!tmp_result)
|
||||
zcbor_trace();
|
||||
|
@ -95,15 +79,18 @@ static bool encode_value(zcbor_state_t *state, const struct value_ *input)
|
|||
|
||||
bool tmp_result = ((
|
||||
(((*input)._value_choice == _value_tstr) ?
|
||||
((zcbor_tstr_encode(state, (&(*input)._value_tstr)))) :
|
||||
(((*input)._value_choice == _value_bstr) ?
|
||||
((zcbor_bstr_encode(state, (&(*input)._value_bstr)))) :
|
||||
(((*input)._value_choice == _value__numeric) ?
|
||||
((encode_numeric(state, (&(*input)._value__numeric)))) :
|
||||
(((*input)._value_choice == _value_bool) ?
|
||||
((zcbor_bool_encode(state,
|
||||
(&(*input)._value_bool)))) :
|
||||
false))))));
|
||||
((zcbor_tstr_encode(state, (&(*input)._value_tstr)))) :
|
||||
(((*input)._value_choice == _value_bstr) ?
|
||||
((zcbor_bstr_encode(state, (&(*input)._value_bstr)))) :
|
||||
(((*input)._value_choice == _value_int) ?
|
||||
(((((*input)._value_int >= -9223372036854775807LL) &&
|
||||
((*input)._value_int <= 9223372036854775807LL)) ||
|
||||
(zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false)) &&
|
||||
(zcbor_int64_encode(state, (&(*input)._value_int)))) :
|
||||
(((*input)._value_choice == _value_float) ?
|
||||
((zcbor_float64_encode(state, (&(*input)._value_float)))) :
|
||||
(((*input)._value_choice == _value_bool) ?
|
||||
((zcbor_bool_encode(state, (&(*input)._value_bool)))) : false)))))));
|
||||
|
||||
if (!tmp_result)
|
||||
zcbor_trace();
|
||||
|
@ -188,10 +175,10 @@ static bool encode_lwm2m_senml(zcbor_state_t *state, const struct lwm2m_senml *i
|
|||
return tmp_result;
|
||||
}
|
||||
|
||||
uint_fast8_t cbor_encode_lwm2m_senml(uint8_t *payload, size_t payload_len,
|
||||
int cbor_encode_lwm2m_senml(uint8_t *payload, size_t payload_len,
|
||||
const struct lwm2m_senml *input, size_t *payload_len_out)
|
||||
{
|
||||
zcbor_state_t states[6];
|
||||
zcbor_state_t states[5];
|
||||
|
||||
zcbor_new_state(states, sizeof(states) / sizeof(zcbor_state_t), payload, payload_len, 1);
|
||||
|
||||
|
@ -202,7 +189,7 @@ uint_fast8_t cbor_encode_lwm2m_senml(uint8_t *payload, size_t payload_len,
|
|||
}
|
||||
|
||||
if (!ret) {
|
||||
uint_fast8_t ret = zcbor_pop_error(states);
|
||||
int ret = zcbor_pop_error(states);
|
||||
|
||||
return (ret == ZCBOR_SUCCESS) ? ZCBOR_ERR_UNKNOWN : ret;
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
/*
|
||||
* Generated using zcbor version 0.3.99
|
||||
* Generated using zcbor version 0.4.0
|
||||
* https://github.com/zephyrproject-rtos/zcbor
|
||||
* Generated with a --default-max-qty of 99
|
||||
*/
|
||||
|
@ -19,7 +19,7 @@
|
|||
#include "zcbor_encode.h"
|
||||
#include "lwm2m_senml_cbor_types.h"
|
||||
|
||||
uint_fast8_t cbor_encode_lwm2m_senml(uint8_t *payload, size_t payload_len,
|
||||
int cbor_encode_lwm2m_senml(uint8_t *payload, size_t payload_len,
|
||||
const struct lwm2m_senml *input, size_t *payload_len_out);
|
||||
|
||||
#endif /* LWM2M_SENML_CBOR_ENCODE_H__ */
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
/*
|
||||
* Generated using zcbor version 0.3.99
|
||||
* Generated using zcbor version 0.4.0
|
||||
* https://github.com/zephyrproject-rtos/zcbor
|
||||
* Generated with a --default-max-qty of 99
|
||||
*/
|
||||
|
@ -35,20 +35,13 @@ struct record_n {
|
|||
struct zcbor_string _record_n;
|
||||
};
|
||||
|
||||
struct numeric_ {
|
||||
union {
|
||||
int64_t _numeric_int;
|
||||
double _numeric_float;
|
||||
};
|
||||
enum { _numeric_int,
|
||||
_numeric_float,
|
||||
} _numeric_choice;
|
||||
};
|
||||
|
||||
struct record_union_ {
|
||||
union {
|
||||
struct {
|
||||
struct numeric_ _union_v;
|
||||
int64_t _union_vi;
|
||||
};
|
||||
struct {
|
||||
double _union_vf;
|
||||
};
|
||||
struct {
|
||||
struct zcbor_string _union_vs;
|
||||
|
@ -60,10 +53,12 @@ struct record_union_ {
|
|||
struct zcbor_string _union_vd;
|
||||
};
|
||||
};
|
||||
enum { _union_v,
|
||||
_union_vs,
|
||||
_union_vb,
|
||||
_union_vd,
|
||||
enum {
|
||||
_union_vi,
|
||||
_union_vf,
|
||||
_union_vs,
|
||||
_union_vb,
|
||||
_union_vd,
|
||||
} _record_union_choice;
|
||||
};
|
||||
|
||||
|
@ -71,13 +66,16 @@ struct value_ {
|
|||
union {
|
||||
struct zcbor_string _value_tstr;
|
||||
struct zcbor_string _value_bstr;
|
||||
struct numeric_ _value__numeric;
|
||||
int64_t _value_int;
|
||||
double _value_float;
|
||||
bool _value_bool;
|
||||
};
|
||||
enum { _value_tstr,
|
||||
_value_bstr,
|
||||
_value__numeric,
|
||||
_value_bool,
|
||||
enum {
|
||||
_value_tstr,
|
||||
_value_bstr,
|
||||
_value_int,
|
||||
_value_float,
|
||||
_value_bool,
|
||||
} _value_choice;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue