Using Serialization for binary marshalling

Is anyone else interested in using Robert Ramey's serialization library for the purpose of marshalling data into pre-determined binary formats? This is not related to serialization in a general sense, but employing the syntax and underlying fundamentals of the library, to a somewhat related purpose. This is a test program demonstrating what I'm doing - I'm interested to know if anyone else is doing anything similar... Matt test.cpp: ------------------------------------------------------------------ #include <sstream> #include <cassert> #include "marshall.hpp" #include "network_oarchive.hpp" #include "network_iarchive.hpp" class test { struct subobject; // Basic fixed-size primitives uint8_t a; uint16_t b; uint32_t c; uint64_t d; // String data that must be serialized to a pre-determined length marshall::fixed_length<std::string, 20> e; marshall::fixed_length<std::wstring, 10> f; // String data that must be serialized with a prepended length // (whose size is itself predetermined) marshall::variable_length<std::string, uint8_t> g; marshall::variable_length<std::wstring, uint8_t> h; // Arbitrary data that must be serialized to a pre-determined length marshall::fixed_length<std::vector<uint16_t>, 5> i; marshall::fixed_length<std::vector<subobject>, 2> j; // Arbitrary data that must be serialized with a prepended length // (whose size is itself predetermined) marshall::variable_length<std::vector<uint16_t>, uint32_t> k; marshall::variable_length<std::vector<char>, uint32_t> l; // A sub-object of arbitrary complexity struct subobject { subobject(void) : a(0), b(0) {} subobject(uint32_t x, uint32_t y) : a(x), b(y) {} bool operator== (const subobject& other) const { return (a == other.a && b == other.b); } private: uint32_t a; uint32_t b; friend class boost::serialization::access; template <class Archive> void serialize(Archive& archive, const unsigned version) { archive & a & b; } }; friend class boost::serialization::access; template <class Archive> void serialize(Archive& archive, const unsigned version) { archive & a & b & c & d & e & f & g & h & i & j & k & l; } public: test(void) : a(0x01), b(0x0203), c(0x04050607), d(0x08090a0b0c0d0e0f), e("abcdefg"), g("xyz") { f[0] = 'A'; f[1] = 'B'; f[2] = 'C'; h.push_back('w'); i[0] = 255; i[1] = 254; i[2] = 253; j[0] = subobject(99, 100); k.push_back(1); k.push_back(2); k.push_back(3); l.push_back('l'); } test(bool) {} // Don't initialize everything bool operator== (const test& other) const { return (a == other.a && b == other.b && c == other.c && d == other.d && e == other.e && f == other.f && g == other.g && h == other.h && i == other.i && j == other.j && k == other.k && l == other.l); } }; int main(int, char**) { test t1; // Serialize object to binary format, in network byte order std::ostringstream oss; boost::archive::network_oarchive oa(oss); oa << t1; // Create uninitialized object test t2(false); // De-serialize object from binary format, in network byte order std::istringstream iss(oss.str()); boost::archive::network_iarchive ia(iss); ia >> t2; assert(t1 == t2); return 0; } This produces the following binary output: ------------------------------- 0000000 |01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 61 |a |b |c |d |e 0000020 |62 63 64 65 66 67 00 00 00 00 00 00 00 00 00 00 | 0000040 |00 00 00 00 00 00 41 00 00 00 42 00 00 00 43 00 | | f 0000060 |00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | 0000100 |00 00 00 00 00 00 00 00 00 00 00 03 78 79 7a 01 | |g |h 0000120 |00 00 00 77 00 ff 00 fe 00 fd 00 00 00 00 00 00 | |i |j 0000140 |00 63 00 00 00 64 00 00 00 00 00 00 00 00 00 00 | |k 0000160 |00 03 00 01 00 02 00 03 00 00 00 01 6c | |l

On Mon, 22 Mar 2004 01:27:53 +0000 (UTC), Matthew Vogt wrote
Is anyone else interested in using Robert Ramey's serialization library for the purpose of marshalling data into pre-determined binary formats?
Yes. In particular, I believe a CDR (Common Data Representation), which is CORBA's binary format would be highly useful for network apps.
This is not related to serialization in a general sense, but employing the syntax and underlying fundamentals of the library, to a somewhat related purpose.
Well, I believe that one of the design changes that was requested in the first review. That is, to make the archive seperate from serialization -- and hence in the current version the Robert has created the boost/archive directory.
This is a test program demonstrating what I'm doing - I'm interested to know if anyone else is doing anything similar... ... code snipped ...
I'm not building such a thing, but if you do I'm sure I'll use it. And your experiences in extending the library would be interesting for the upcoming re-review of serialization :-) Jeff

Jeff Garland <jeff <at> crystalclearsoftware.com> writes:
Is anyone else interested in using Robert Ramey's serialization library for the purpose of marshalling data into pre-determined binary formats?
Yes. In particular, I believe a CDR (Common Data Representation), which is CORBA's binary format would be highly useful for network apps.
Yes, it's interesting. Looks simple enough from the basic descriptions I've found - is there an authoritative specification freely available? Or do you have sufficient access to the spec to answer my questions?
This is not related to serialization in a general sense, but employing the syntax and underlying fundamentals of the library, to a somewhat related purpose.
Well, I believe that one of the design changes that was requested in the first review. That is, to make the archive seperate from serialization -- and hence in the current version the Robert has created the boost/archive directory.
Yes, this is certainly the case - it's very little effort to change the behaviour.
This is a test program demonstrating what I'm doing - I'm interested to know if anyone else is doing anything similar... ... code snipped ...
I'm not building such a thing, but if you do I'm sure I'll use it. And your experiences in extending the library would be interesting for the upcoming re-review of serialization
Good, thanks for your interest. I hope to whip up enough support to convince Robert that this is generally useful - if I can get accepted, I'll never need to recreate this code *again*! Matt

On Mon, 22 Mar 2004 03:29:47 +0000 (UTC), Matthew Vogt wrote
Yes. In particular, I believe a CDR (Common Data Representation), which is CORBA's binary format would be highly useful for network apps.
Yes, it's interesting. Looks simple enough from the basic descriptions I've found - is there an authoritative specification freely available? Or do you have sufficient access to the spec to answer my questions?
You can get it directly from the OMG website http://www.omg.org/technology/documents/formal/corba_2.htm See chapter 15 http://www.omg.org/docs/formal/02-06-51.pdf Jeff

In addition to an XDR archive, a CDR archive implementation would be quite useful I think. -- Jeremy Maitin-Shepard
participants (3)
-
Jeff Garland
-
Jeremy Maitin-Shepard
-
Matthew Vogt