The Cpp API references a CreateSharedString
function to perform String deduplication. It seems there is also a specific shared
attribute in the flatbuffers DSL.
Unfortunately, I cannot find an equivalent in the Java API nor any documentation about the shared
attribute.
Is it possible to create shared strings with the Java API? if yes, how to do?
Should I maintain a map of Strings and their offset for calls to FlatBufferBuilder#createString and perform a check against this map, or is flatbuffers providing a better mean in Java?
Yes, you can do this yourself, if need be. If you serialize an offset you get from createString
in 2 or more places, you are using sharing. Using your own map to see if you have already serialized a string and reusing its offset is fine.
Sadly of course this makes the serialization process slower (and use more memory), but this may be worth it if you have a lot of repeating strings.