wakaama
wakaama copied to clipboard
Json data format parsing when resource is of data type OPAQUE
Currently wakaama is parsing Resource data type OPAQUE as is (lwm2m_data_encode_opaque) while according to the TS If the Resource data type is opaque the string value holds the Base64 encoded representation of the Resource. i think that it will be not easy to implement since the parsing function needs data type information to choose correct parsing.
As stated in #263, my opinion is that the Object plugin should do the base64 decoding. The base64 decoding is required if, for an opaque resource, the lwm2m_data_t is of type LWM2M_TYPE_STRING.
if so then why the encoding is done in the core? it could be the solution, but don't you think that parsing logic should stay in the core? i think that to achieve the parsing within the core(json_parse) the prv_convertRecord API should gain knowledge about resource type under parsing, and to perform the base64 conversion in case of string
The encoding is done in the core because the Object plugin sets the lwm2m_data_t::type to LWM2M_TYPE_OPAQUE. Then the core knows it has to base64 encode the data for JSON format.
For decoding, getting knowledge of the resource type would require each Object plugin to provide this information to the core and the core to maintain a database thus increasing the memory usage.
the core is not necessary need to maintain database, we can for example define additional object api which retrieves resource type.
The SenML JSON encoding is aware of opaque values and does the decoding. The original JSON encoding does not allow for this and decoding must be done in the Object plugin.
@sbertin-telular any thoughts on the way forward for this issue? Would like to reduce the number of open bugs...
I always felt that lwm2m_data_decode_opaque() and lwm2m_data_decode_string() functions were missing to round out the set of functions in data.c. Maybe adding lwm2m_data_decode_opaque() that would just copy opaque data or base64 decode string data would resolve this.