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

Mapping JSON to CBOR #8

Open
mmccool opened this issue Oct 10, 2017 · 2 comments
Open

Mapping JSON to CBOR #8

mmccool opened this issue Oct 10, 2017 · 2 comments
Labels
data mapping discussions on data mapping concepts Has Use Case Potential The use case can be extracted and explained Selected for Use Case

Comments

@mmccool
Copy link
Contributor

mmccool commented Oct 10, 2017

Many target protocols will use CBOR for payload data; an example is OCF. The current proposal uses JSON for the payload template and will depend on an automatic conversion to CBOR.

However, the CBOR definition (https://tools.ietf.org/html/rfc7049) includes the following text, emphasis mine:

This specification puts no restrictions on CBOR-based protocols. An
encoder can be capable of encoding as many or as few types of values
as is required by the protocol in which it is used; a decoder can be
capable of understanding as many or as few types of values as is
required by the protocols in which it is used.
This lack of
restrictions allows CBOR to be used in extremely constrained
environments.

In other words, a CBOR decoder does not need to support all CBOR features. This can lead to some issues when using general conversion from JSON, since specific JSON values can map to several different CBOR data types, depending on range and precision requirements. For example, suppose a particular decoder assumes that all floating-point numbers are 32-bit (single precision) and does not support other floating-point formats in the CBOR specification, such as 16-bit (half precision) floats. A general encoder might choose to use such a format unsupported by a target decoder for a given element of data given no other constraints.

Other features of CBOR that might not be supported on all devices are streaming string data (due to memory limitations) and specific number representations, such as bignums or 64-bit integers.

One possible resolution to the above situation would be to add some global options to the encoder to disallow certain CBOR features to ensure compatibility with the target device. These can be global options, rather than options on specific data items, since they arise from limitations of the CBOR encoder itself.

@mmccool
Copy link
Contributor Author

mmccool commented Oct 10, 2017

There are some other CBOR quirks that may be hard to target from standard JSON:

  • Support for NaN and Infinity values for floating-point numbers
  • Support for bignums and rational numbers
  • Support for non-string values (for example, integers) in the "tag" position of object maps

One way around many of these would be to use the JSON-like "diagnostic notation" form of CBOR described (but unfortunately not formally defined...) in the CBOR specification rather than "pure" JSON. However, in addition to the problem that the CBOR reference does not define it formally, the CBOR diagnostic notation is not standard JSON so it cannot be embedded directly within a JSON TD. Instead any such extended representation would have to be embedded inside another data type, such as a string.

@mmccool mmccool changed the title Mapping JSON to partial CBOR implementations Mapping JSON to CBOR Oct 10, 2017
@egekorkan
Copy link
Contributor

@mmccool Are there any updates regarding this?

@egekorkan egekorkan added Has Use Case Potential The use case can be extracted and explained Selected for Use Case data mapping discussions on data mapping concepts labels Jan 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
data mapping discussions on data mapping concepts Has Use Case Potential The use case can be extracted and explained Selected for Use Case
Projects
None yet
Development

No branches or pull requests

2 participants