Skip to content

Support native non-string map keys for formats that allow them #723

Description

@awake23

Some serialization formats supported by reflect-cpp, such as CBOR and
MessagePack, allow map keys to be types other than strings.

Currently, reflect-cpp's generic object/map abstraction uses string keys,
so integral keys are converted to strings. For example:

std::map<int, int> value{{1, 2}};

is represented as:

{"1": 2}

even when the target format can preserve it as:

{1: 2}

A practical use case is COSE_Key, whose fields are identified by integer
labels:

{
   1: 2,       // kty: EC2
   3: -7,      // alg: ES256
  -1: 1,       // crv: P-256
  -2: h'...',  // x
  -3: h'...'   // y
}

Converting these labels to strings changes the encoded data and produces an
invalid COSE_Key.

Could reflect-cpp preserve native map key types for formats that support them,
while keeping the existing string-key behavior for formats such as JSON?

This could apply both to associative containers and, if feasible, reflected
types with non-string field labels.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions