Of course the programmer needs explicitly specify the serialization
of
the data-members of the struct/class typically using the member
functions
- Obj::encode(std::ostream & os) const
- Obj::decode(std::istream & is) const
I have also implemented "automatic management" of two-way-relations
to
realized unordered graph structures.
These are realized as enum-typed double-linked/way pointers.
These could be (un)serialized automatically
Could we reuse boost::graph and boost::serialization somehow?
If not, what structures (balanced tree, hashmap, sorted arrays, ...)
should I use to construct file-format?
Thanks in advance,
Nordlöw
No, but I recently wrote a serialization routine for my own Graph
class. It wrote the class as an adjacency list with the form (using
grammar notation -- not pointer notation)
((sourceNode)(destNodeID*) Terminator1)* Terminator2
Then I (naively) iterate over every node:
void Graph::serialize(ostream& o) {
for (int i = 0; i < numNodes; ++i) {
o << node[i]; // assume node is serializable
for (int j = 0; j < numNodes; ++j) {
if (adjacent(i,j)) encode(o, j);
}
o << Terminator1;
}
o << Terminator2;
}
In practice encode(o,j) writes j as a UTF-8 like variable length
integer. Then Terminator1 == '\0xFE' and Terminator2 == '\0xFF' for
the simple reason that 0xFE and 0xFF cannot occur in that encoding.
--Jonathan