Closed snakeru closed 2 years ago
Hey Alexey,
thanks for sharing your thoughts about a new encoding scheme. As you know, we have published a CBOR-based encoding format with LwM2M v1.2 and it was developed with the help of group members to define a generic mechanism. In particular, it works also well if you have resources with higher resource ids. There are a large number of objects, which use re-usable resources. These tend to have resource ids starting at resource id 4000 upwards (see https://technical.openmobilealliance.org/OMNA/LwM2M/LwM2MRegistry.html). When applied to your encoding, this would lead to a lot of inefficiency.
Regardless of this issue, you are always welcome to join the OMA to help us make LwM2M better (not just the CBOR encoding).
Hi Hannes.
I don't think this will lead to inefficiency. There is this line in my proposal:
let the encoder choose the most efficient [encoding]
So for such objects this encoding just won't be used.
What I had in mind is the non-standard, vendor-developed objects where the numbering doesn't have this limitation. If CBOR is used for encoding of messages sent over the air then the difference between 23 and 29 bytes could be, for example, having N and 1.26N collisions per day and correspondingly more battery consumption (for retransmission etc).
Using standard objects for that purpose would make matters only worse because ID 4000+ requires one more byte for encoding so we are speaking already about 23 vs 35 bytes.
It is, of course, possible to develop an additional encoding as you suggest. Per OMA by-laws you will, however, have to join the OMA to contribute this new encoding.
Problem description
In current version of the specification (OMA-TS-LightweightM2M_Core-V1_2-20201110-A) the
map
type is used to represent an object. While this makes sense if we want to update a single resource of a single object, this is not necessarily the most efficient encoding if a whole object has to be transmitted.For example, in section 7.4.4.4 an example serialization is provided for an object with resources 0,1,2,3,5,6,7 (in fact that section looks at two instances, but I'll only be considering first one here). That means that 7 bytes are spent for explicit listing of resource ids:
A json representation of that would have been:
{0:101,1:86400,2:300,3:6000,5:86400,6:true,7:"U"}
Possible solution
If instead an array were used, then the resource 4 had to be explicitly listed as
undefined
, but that would have still saved 6 bytes out of 29 on the wire:A json representation of such array would have been:
[101,86400,300,6000,undefined,86400,true,"U"]
This is of course also applicable to multiple objects encoding, though with significantly smaller impact.
Implementation strategy
Would it be reasonable to support both representation formats and let the encoder choose the most efficient? The encoder could select the array representation if highest resource ID doesn't differ much from number of resources to be encoded and fall back to map encoding otherwise.