Replies: 1 comment
|
I think there may be a misunderstanding here about how FlatBuffers stores strings. FlatBuffers strings are already stored as a sequence of bytes containing UTF-8 text, and plain ASCII text is a valid subset of UTF-8. For a string like: const char *name = "Sword";the characters themselves are stored as: (one byte per character), plus the terminating null byte that FlatBuffers includes for convenience. If you're seeing a lot of
For example, UTF-8 does not automatically store ASCII characters as: That's UTF-16-style encoding, not UTF-8. The schema documentation's statement that strings may contain "UTF-8 or 7-bit ASCII" means that the string contents must be valid UTF-8, and pure ASCII strings are naturally valid UTF-8 strings. There isn't a separate "ASCII mode" that changes how strings are serialized. So if your strings only contain ASCII characters, they are already being stored using one byte per character. The extra If you can share a small hex dump of the buffer, it would be easier to identify exactly which bytes are string data versus alignment, offsets, or other FlatBuffers metadata. |
Uh oh!
There was an error while loading. Please reload this page.
I've went through the quick tutorial (C++), and I noticed the
stringmembers in the output binary is having a lot of0x00characters. My initial guess was that thestringmembers are writen in UTF-8 mode, then I found the schema guide mentioned:"
string, which may only hold UTF-8 or 7-bit ASCII."It sounds like we could change it to ASCII mode, however I tried to explicitly use
const char * name = "Sword";and pass this explicit char variable toCreateStringand its still written in UTF-8 mode.I'm not sure if my deductions are accurate so I'll write my question in a more generic sense, I would like to know if its possible to write in single byte per character for
string, if it is then how do we changestringto write to binary in such manner?All reactions