3 ms·
I looked at their implementation at http://google.github.io/flatbuffers/md__internals.html http://google.github.io/flatbuffers/md__internals.html and found this
by userbinator 12y ago
I looked at their implementation at http://google.github.io/flatbuffers/md__internals.html http://google.github.io/flatbuffers/md__internals.html and found this rather confusing paragraph:
Strings are simply a vector of bytes, and are always null-terminated. Vectors are stored as contiguous aligned scalar elements prefixed by a 32bit element count (not including any null termination).
So... does the count include the null terminator byte or not?
- zeroxfe 12y agoThat sounds like an unambiguous no to me (null-terminator not included in count.)
- robert_tweed 12y agoI believe you are correct, mainly because the basic purpose of the protocol is "no parsing", so therefore it must work when loaded directly into RAM. The spec is a bit confusing though, because of the statement that "Strings are simply a vector of bytes". The way I understand it is that a string is a vector FOLLOWED BY a null terminator. The spec should probably say that rather than the current wording. This would appear to be necessary so that a string can be treated as either a vector like any other (with the correct number of elements) and can also be accessed directly by a (char *) pointer without things going awry. Disclaimer: I haven't read the whole spec yet; this is my off-the-top-of-my-head interpretation and I may have misunderstood it completely.
- mockery 12y agoI'd expect that strings are just a vector of bytes, with strlen()+1 bytes, the last of which is always null.
- ultimape 12y agoI think the first use of the term 'vector' is more conceptual - but is actually defining a string type that is implemented using a c-style string strategy. The second mention "Vector" is a more direct reference to the C++/Java Vector class and its imlementation. Technically speaking, you an implement a c-style string using a STD:Vector by ignoring the length preamble and ensuring room is made for the null character. I got away with this in my intro to c++ class after showing the teacher that I already knew how to implement strings in C from a previous class. C-style strings: http://www.learncpp.com/cpp-tutorial/66-c-style-strings/ http://www.learncpp.com/cpp-tutorial/66-c-style-strings/ C++ Vector class: http://en.cppreference.com/w/cpp/container/vector http://en.cppreference.com/w/cpp/container/vector Java Vector Class: http://docs.oracle.com/javase/7/docs/api/java/util/Vector.html http://docs.oracle.com/javase/7/docs/api/java/util/Vector.ht...