dahomey-technologies/Dahomey.Cbor

Feature request: Add and support int key for CborPropertyAttribute

Closed this issue · 2 comments

rmja commented

It would be really useful if the CborPropertyAttribute could support an int key similar to the KeyAttribute in MessagePack.

Edit: Mayby this is actually two feature requests:

  1. CborProperty(x) should be used in an map object mapping where the key is the integer x.
  2. CborKey(x) should be used in an array mapping where x is the array position just like messagepack.

plan:

  • add a property int Index to CborPropertyAttribute
  • add a CborObjectFormatAttribute to annotate a class or a struct

Current implementation does not yet support Discriminators nor CreatorMappings.

Supporting Discriminators is tricky, especially for the array format because the number of items in the array for a specific class could be variable if DiscriminatorPolicy is set to Auto.

One possible implementation is to use a Semantic Tag to identify the discriminator property/field.
Semating Tag 39 could be used for this purpose.