concise-encoding
concise-encoding copied to clipboard
What's the reasoning behind array types cb and u8x being separate?
I can't see how the separation of those types is useful.
It's mainly about signalling the intent and structure of the data.
-
u8(and all variants such asu8x) is simply an array of values in the range 0-255, with no inherent structure other than the individual element values (like all array types). It's for sending large series of simple data in an efficient manner. For example you might send a series of integer percentage values ranging from 0-100. Any decoder can take in this data because it is exactly what it is: a series of integers. -
cbandctsignal that the contents of this object are not simply array elements or text, but have special structure and meaning that goes beyond the capabilities of the Concise Encoding format. The receiving end would use this signalling information to call some special process to decode this complex type. If it cannot understand the type or lacks any custom type decoding at all, it can either ignore it or raise an issue about it (depending on how important the data is for the receiver).
For example, suppose your application had downloaded the following data (shown in CTE for convenience):
{
"company name" = "ABC Corp"
"logo mesh" = |cb 01 f3 dd a5 ...|
"logo texture" = |image/png 94 aa 1f 39 ...|
"recording from date" = 2021-12-01
"daily tornadoes" = |u8 0 0 0 0 0 1 0 ...|
}
The mesh data is a custom type that your generic decoder doesn't understand, but that's fine because your program is text-only and couldn't display the logo anyway. So "logo mesh" is ignored, and any decoding issue with the custom type is moot. Even if this was a graphical application, it might be more desirable to display without the logo than not at all...