boost::serialization - trying to serialize derived class and base class.

I am writing a packet base class that can be serialized. The class so far looks like: class packet_base { using namespace boost; public: packet_base(); ~packet_base(); friend class boost::serialization::access; template <typename Archive> void serialize(Archive & ar, const unsigned int version) { ar & m_length; ar & m_type; ar & m_method; } private: uint16_t m_length; uint16_t m_type; uint16_t m_method; }; The question now is how can I derive class A from packet_base and have both packet_base and A's variables serialized? Obviously base_class needs to be archived first so it's variables are at the front of the buffer. Thanks in advance. J

lookup base_object in the documentation.
Robert Ramey
"j.c."

Sweet, just what I was looking for, thanks. On Apr 14, 2008, at 8:31 AM, Robert Ramey wrote:
lookup base_object in the documentation.
Robert Ramey
"j.c."
wrote in message news:CB290CFC-9ABD-4FF9-80C1-766E3063F8A6@mac.com ... I am writing a packet base class that can be serialized. The class so far looks like: class packet_base { using namespace boost;
public: packet_base(); ~packet_base();
friend class boost::serialization::access; template <typename Archive> void serialize(Archive & ar, const unsigned int version) { ar & m_length; ar & m_type; ar & m_method; }
private:
uint16_t m_length; uint16_t m_type; uint16_t m_method; };
The question now is how can I derive class A from packet_base and have both packet_base and A's variables serialized? Obviously base_class needs to be archived first so it's variables are at the front of the buffer.
Thanks in advance. J
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

ok I have this working, however... packet_base: 12 packet_ping: 44 0 1 0 0 0 1001 44 2 3 7 32 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ^ packet actually starts here(packet_length). There are 6 extra bytes overhead I know that 1001 is my class version. What are 0, 1, 0, 0 and 0? I need this info for writing packet de-serialization in other languages. Thanks in advance. On Apr 14, 2008, at 8:21 AM, j.c. wrote:
Sweet, just what I was looking for, thanks.
On Apr 14, 2008, at 8:31 AM, Robert Ramey wrote:
lookup base_object in the documentation.
Robert Ramey
"j.c."
wrote in message news:CB290CFC-9ABD-4FF9-80C1-766E3063F8A6@mac.com ... I am writing a packet base class that can be serialized. The class so far looks like: class packet_base { using namespace boost;
public: packet_base(); ~packet_base();
friend class boost::serialization::access; template <typename Archive> void serialize(Archive & ar, const unsigned int version) { ar & m_length; ar & m_type; ar & m_method; }
private:
uint16_t m_length; uint16_t m_type; uint16_t m_method; };
The question now is how can I derive class A from packet_base and have both packet_base and A's variables serialized? Obviously base_class needs to be archived first so it's variables are at the front of the buffer.
Thanks in advance. J
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

try using the xml_archive - all the "extra" bytes show up as labeled attributes.
Robert Ramey
"j.c."

Nothing lines up, if I set class version then the last parameter is
set. Also I think these are int's which is quite large(6 *
sizefof(int)) for a packet header.
packet_ping: 44
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE boost_serialization>
try using the xml_archive - all the "extra" bytes show up as labeled attributes.
Robert Ramey "j.c."
wrote in message news:F58B74D0-78DC-4E07-ABD5-3F0C7BAC831B@mac.com ... ok I have this working, however... packet_base: 12 packet_ping: 44 0 1 0 0 0 1001 44 2 3 7 32 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ^ packet actually starts here(packet_length).
There are 6 extra bytes overhead I know that 1001 is my class version. What are 0, 1, 0, 0 and 0?
I need this info for writing packet de-serialization in other languages.
Thanks in advance.
On Apr 14, 2008, at 8:21 AM, j.c. wrote:
Sweet, just what I was looking for, thanks.
On Apr 14, 2008, at 8:31 AM, Robert Ramey wrote:
lookup base_object in the documentation.
Robert Ramey
"j.c."
wrote in message news:CB290CFC-9ABD-4FF9-80C1-766E3063F8A6@mac.com ... I am writing a packet base class that can be serialized. The class so far looks like: class packet_base { using namespace boost;
public: packet_base(); ~packet_base();
friend class boost::serialization::access; template <typename Archive> void serialize(Archive & ar, const unsigned int version) { ar & m_length; ar & m_type; ar & m_method; }
private:
uint16_t m_length; uint16_t m_type; uint16_t m_method; };
The question now is how can I derive class A from packet_base and have both packet_base and A's variables serialized? Obviously base_class needs to be archived first so it's variables are at the front of the buffer.
Thanks in advance. J
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (2)
-
j.c.
-
Robert Ramey