Reason for not supporting float/double etc in attributes? #8570
Replies: 1 comment
-
|
That's an interesting question. Looking at it from a schema/compiler design perspective, my guess is that attributes were intentionally kept simple because they're primarily used as metadata for code generation rather than data serialization. A few possible reasons for only supporting integers and strings:
That said, your use case seems reasonable. If attributes are being used to drive code generation and the value is conceptually numeric (such as a scale factor, unit conversion ratio, threshold, etc.), native float/double support would be more convenient and less error-prone than encoding the value as a string and parsing it later. I'd be curious whether this limitation was a deliberate design decision from the beginning or simply a case where nobody has needed floating-point attributes strongly enough to justify expanding the schema grammar. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
So, I wanted to declare some custom attributes for containing scaling value, in double/float.
I noticed flatc will give error claiming unsupported type. Also noted on doc, only string and int types are supported.
Any idea why?
I am considering adding double support by parsing string containing real numbers with decimal point as double, eg) "0.001". Seeing how this is rather simple matter, was wondering if there was a strict reason to forbid floats for attributes.
Beta Was this translation helpful? Give feedback.
All reactions