-
Notifications
You must be signed in to change notification settings - Fork 667
Description
What is your use-case and why do you need this feature?
Use Case: I need to send a CBOR payload to an external device, who's firmware expects certain data to be in the Byte String format.
As I can't modify the firmware to accept an array of bytes as opposed to a byte string, I need this library to support encoding CBOR's Byte String type.
Describe the solution you'd like
As described by the Major Types section in CBOR RFC-7049, CBOR includes a major type specifically for byte strings. In instances where a service or receiver expects a byte string, a user of this library's existing CBOR serialization implementation would be unable to send a byte string as the Cbor class only includes support for the Text, Negative Integer, Array and Map major types.
Ideally, as a user of the library, it would be great to be able to either
-
Wrap my
ByteArrayin a type that has its own serializer (could probably be the same as theByteArraySerializer) and a descriptor that defaults to a CBOR specificSerialKind(BYTE_STRING); or -
Use a
ByteStringSerializer()to provide to my own custom serializer; or -
Create my own serializer within my class and instruct the encoder to explicitly encode a provided
ByteArrayas a ByteString.
The Cbor class would need to include the byte string header type (0b010_00000) in its Default companion object and update the CborWriter, CborEncoder, CborReader, and CborDecoder to handle that type appropriately.