[odb-users] Persist Google's Protocol Buffers...

Boris Kolpackov boris at codesynthesis.com
Wed Jan 29 04:01:10 EST 2014


Hi Alon,

Alon Moshayov <alon.moshayov at myheritage.com> writes:

> I'm now trying to compile a protocol buffer source header with ODB complier
> and facing several mapping issues of:

There will most likely be some data members that are used for protobuf's
house-keeping and which should probably not be stored in the database.
You will need to mark such data members as transient, for example:

#pragma db member(Foo:bar) transient

 
>    - ::google::protobuf::UnknownFieldSet

>From the protobuf's documentation:

"UnknownFieldSet is used to keep track of fields which were seen when
 parsing a protocol message but whose field numbers or types are
 unrecognized."

You probably don't want to store it in the database.


>    - ::std::string*

What is the semantics of this data member? Does it store actual
data? Is it dynamically allocated and if so, by whom? Are there
accessors/modifiers that can be used to get/set this data?


>    - ::google::protobuf::RepeatedPtrField

Again, by reading the protobuf's documentation, this class
template (and RepeatedField) are containers. You will need
to provide a container traits specialization for these class
templates in order for ODB to recognize them as containers.

This is pretty simple to do and you can see the example of how
this is done for std::vector in libodb/odb/std-vector-traits.hxx.

If you save your implementation to, say, protobuf-container-traits.hxx,
then you can include it into the ODB compilation using the
--hxx-prologue option:

odb --hxx-prologue "#include \"protobuf-container-traits.hxx.hxx\"" ...


>    - ::google::protobuf::uint32 _has_bits_[(9 + 31) / 32]

You will need to check what the semantics of this array is. My
guess is that it is a vector of bit flags that specify whether
the optional members are present. Im this case you don't want
to store it in the database.

Boris



More information about the odb-users mailing list