peteroupc / CBOR

A C# implementation of Concise Binary Object Representation (RFC 8949).
The Unlicense
206 stars 29 forks source link

Data model changed in Draft to separate floating point from integer types #31

Closed jimsch closed 5 years ago

jimsch commented 5 years ago

In the current working group document, the data model distinguishes between a floating point and an integer type. Section 2 - bullets 1 and 3. What are the plans for moving this into the current codebase?

peteroupc commented 5 years ago

Here is the current situation:

jimsch commented 5 years ago

First, I assume you meant to say tags 0 and 1 not 2 and 3 - Kind of hard to store a text string in an EInteger.

What I am currently playing with is CoRAL (https://datatracker.ietf.org/doc/draft-hartke-t2trg-coral/). There is a optimization with dictionaries that I need to figure out how to program. Looking inside of the object might be one way, but I would worry if you changed it again.

The hack is that you can replace specific elements in an array with an integer that comes from a dictionary so that [1, "ABCDE", "FGHIJ"] can be converted to [1, 10, 11] which is much shorter. The problem is that it is supposed to be possible to replace an integer value as well. Thus [1, "ABCDE", 99999] can be mapped to [1, 10, TBD(12)]. The value is tagged so that one can distinguish between it being an integer and being something else like a string. When doing the reverse mapping that means I need to figure out the difference between a floating point and an integer so that [1, 10, 12.0] is not mapped back. The model assumes that the tag that was decoded is visible to the application but I don't believe that is true for you systems.

peteroupc commented 5 years ago

Yes, when my library encounters CBOR objects with certain tags, it converts that object to a "native" version with a different form of storage and discards the tag; see ConvertToNativeObject in the CBORNativeConvert class of my library. However, it preserves the tag information in the case of all other tags.

I will work at rewriting the code to eliminate this kind of conversion and to preserve the distinction between integers and IEEE floating point numbers in the public API.

jimsch commented 5 years ago

Thanks

peteroupc commented 5 years ago

Issue addressed in version 4.0.0-beta2, just released.