ID/Static content from schema

51 views
Skip to first unread message

Matthias Gabriel

unread,
Jul 5, 2017, 3:11:15 AM7/5/17
to FlatBuffers
Hi,

I'd like to transport static information (such as an identifier) from the schema file into the implementation. I would want specify an identifier that could be a text in the schema file, to identify this class of information. and store it with the binary/serialized data. Later I read the identifier and compare it to a bunch of expected data to know which buffer of which type I have.

I saw that the fully qualified name has been exposed in the C++-API for a similar reason, but that's not sufficient. First its impossible to set this to a freely chosen identifier and second its only exposed in the C++ API.

I had a look at the source code of flatbuffers and its surprisingly short and I think that "copying a certain entry" into the generated code for a static function might not be that much effort. I'd give it a go but first i want to know whether such functionality is already available (apart from fully qualified names) and whether such a patch would be accepted?

Regards,
Matthias

Wouter van Oortmerssen

unread,
Jul 5, 2017, 1:43:29 PM7/5/17
to Matthias Gabriel, FlatBuffers
I'm not quite sure what you want to accomplish.

It sounds what you need is the file_identifier functionality, which is an identifier stored in the serialized data, and supported in all languages.

If you want it in the generated code, can you give an example?

You can store all manner of identifiers with schema items as custom attributes, which are queryable when you parse a schema, or by loading a binary schema file.

--
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.

Matthias Gabriel

unread,
Jul 5, 2017, 2:30:01 PM7/5/17
to FlatBuffers, gab...@gmail.com
I want to declare an identifier in the schema file for each message that can be read by the implementation. The file identifier accomplishes the same but it has just too less characters for a random pool. But thanks for pointing me to the attributes, they are indeed what I want... thanks!
To unsubscribe from this group and stop receiving emails from it, send an email to flatbuffers...@googlegroups.com.

mikkelfj

unread,
Jul 7, 2017, 3:02:37 PM7/7/17
to FlatBuffers, gab...@gmail.com
I want to declare an identifier in the schema file for each message that can be read by the implementation. The file identifier accomplishes the same but it has just too less characters for a random pool. But thanks for pointing me to the attributes, they are indeed what I want... thanks!

Perhaps this is what you are looking for, but it is for C generated code:



It generates an 32-bit fnv1a hash of the fully qualified name. It is not guaranteed unique, but close enough.
If you check for several buffer types in a switch you will get a compile error on conflicting values and then you can change a name of one type slightly.

I should have added this to the C++ generator, but I never got around to it. You can use this header file to compute your own:


I principle it can be supported by all languages more or less directly, because most languages have fnv1a support
 - you just need the fully qualified name to start with and you can get that from the binary schema bfbs if nothing else.

If you are up to it, perhaps you could this functionality if Wouter is ok with it?

Note that the 32-bit file identifier in the buffer is optional an can make buffers larger depending on alignment.
Reply all
Reply to author
Forward
0 new messages