Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
TMaddox opened this issue Oct 21, 2019 · 4 comments
Closed

Comments

@TMaddox
Copy link

TMaddox commented Oct 21, 2019

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?

@jonassix
Copy link

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

@mcatanzariti
Copy link
Member

mcatanzariti commented Oct 28, 2019

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.

@TMaddox
Copy link
Author

TMaddox commented Oct 29, 2019

That sounds like a great solution!

Can you give us an approximate ETA?

@mcatanzariti
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants