FlexBuffers needs a dedicated bool type

58 views
Skip to first unread message

Maxim Zaks

unread,
Aug 3, 2017, 8:52:46 AM8/3/17
to FlatBuffers
I am using my FlexBuffers Swift port in production.
I implemented a FlexBuffers to JSON converter which surfaces the problem of FlexBuffers not having a dedicated bool type.
When exporting to JSON there is no intrinsic way to generate "true" or "false" as a bool value will be stored as Int type with byte_width 1.
For now I can provide a set of keys where the values has to be converted to "true" or "false" but this is a dirty non scalable hack :).
As we need to add bool type apriori it will have the index 26 and make "IsInline" and "IsTypedVectorElementType" a bit more complicated.
However I would suggest to also add a special type for vector of bools, which internally can be implemented as BitField.
This will make the change simpler and introduce another positive advantage for FlexBuffers compared to other formats, which store vector of bools in more wasteful way.
 

Wouter van Oortmerssen

unread,
Aug 3, 2017, 12:33:20 PM8/3/17
to Maxim Zaks, FlatBuffers
This is already being worked on: https://github.com/google/flatbuffers/pull/4386

We may add a special bit-vector, but it would be separate from a vector of bool, which will still store bools as one byte, such that it can be compatible with all other scalars. We wouldn't want lots of conditional code just for booleans.


--
You received this message because you are subscribed to the Google Groups "FlatBuffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flatbuffers+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Maxim Zaks

unread,
Aug 4, 2017, 4:54:24 AM8/4/17
to FlatBuffers, maxim...@googlemail.com
That's great news, I will have a look and bring it to FlexBuffersSwift.
To unsubscribe from this group and stop receiving emails from it, send an email to flatbuffers...@googlegroups.com.

Wouter van Oortmerssen

unread,
Aug 4, 2017, 11:05:10 AM8/4/17
to Maxim Zaks, FlatBuffers

To unsubscribe from this group and stop receiving emails from it, send an email to flatbuffers+unsubscribe@googlegroups.com.

Maxim Zaks

unread,
Aug 10, 2017, 6:15:21 AM8/10/17
to FlatBuffers, maxim...@googlemail.com
Have you tested vector of bools?
I had to change somme things like `IsTypedVectorElementType` to make my tests pass.

Wouter van Oortmerssen

unread,
Aug 10, 2017, 12:57:01 PM8/10/17
to Maxim Zaks, FlatBuffers
Thanks, that may well be.. I've noted it on the PR: https://github.com/google/flatbuffers/pull/4386

To unsubscribe from this group and stop receiving emails from it, send an email to flatbuffers+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages