dahomey-technologies/Dahomey.Cbor

[Feature Request] Allow different ways of serializing a map to cbor

TMaddox opened this issue · 4 comments

Take these two serialized cbor objects: (as hex)

from your implementation:
a4686d65746144617461a16974696d657374616d7061306e7061727469636c6547726f75707381a3697061727469636c657381a4687061727469636c65a86562797465734401b5eb2d6c64657374696e6174696f6e73815102b54cee8bbc613404efca9e2e94e08d8d6466726f6d5827040a02fe22156c1fb8cc6868579b1cd0d3704ef9567a8442ee539951b2380a3f4371cc1406b8e7686d65746144617461a1636b65796576616c7565656e6f6e6365006a73657269616c697a65727772616469782e7061727469636c65732e6d65737361676562746f5827040a02fe22156c1fb8cc6868579b1cd0d3704ef9567a8442ee539951b2380a3f4371cc1406b8e76776657273696f6e18646a73657269616c697a65727372616469782e7370756e5f7061727469636c65647370696e016776657273696f6e18646a73657269616c697a65727472616469782e7061727469636c655f67726f75706776657273696f6e18646a73657269616c697a65726a72616469782e61746f6d6776657273696f6e1864

from the implementation we need to match:
bf686d65746144617461bf6974696d657374616d706130ff6e7061727469636c6547726f75707381bf697061727469636c657381bf687061727469636c65bf6562797465734401b5eb2d6c64657374696e6174696f6e73815102b54cee8bbc613404efca9e2e94e08d8d6466726f6d5827040a02fe22156c1fb8cc6868579b1cd0d3704ef9567a8442ee539951b2380a3f4371cc1406b8e7686d65746144617461bf636b65796576616c7565ff656e6f6e6365006a73657269616c697a65727772616469782e7061727469636c65732e6d65737361676562746f5827040a02fe22156c1fb8cc6868579b1cd0d3704ef9567a8442ee539951b2380a3f4371cc1406b8e76776657273696f6e1864ff6a73657269616c697a65727372616469782e7370756e5f7061727469636c65647370696e016776657273696f6e1864ff6a73657269616c697a65727472616469782e7061727469636c655f67726f75706776657273696f6e1864ff6a73657269616c697a65726a72616469782e61746f6d6776657273696f6e1864ff

as you can see (or better, verify with cbor.me) those result in the exact same object, but the hex above does not match. This is because you use map(4), and the foreign implementation uses map() and primitive() for arrays.

Your implementation is better as it requires fewer bytes for the same amount of data, but as I said I need to match the other implementations.

Can you allow customizing in which way it should be serialized?

Hi,

We have requested to the foreign party to change their implementation but this is their response.

Sorry guys, we aren't, the streaming encoding is used for performance reasons, so that we don't have to check ahead of time if a given field is empty(null, an empty array or an empty object, which should be excluded from the serialized result)

So we are kinda stuck atm. Could you take a look and let u know if you are willing to add this feature ?

Thank you

Yes, I could add the feature by decorating an object with a specific attribute (and expose the corresponding method in ObjectMapping). I could also add a general option to define the default behavior.
Same kind of feature could be implemented for arrays.

However, I won't be able to implement it in the short term.

That sounds like a great solution!

Can you give us an approximate ETA?

Implemented in 1.5.0

You can use either

  • CborOptions.LengthMode
  • ObjectMapping.SetLengthMode
  • CborLengthModeAttribute to decorate classes or properties

cf. ObjectIndefiniteLengthTests.cs for concrete examples.