Boost class/struct serialization to byte array
Posted
by Dave18
on Stack Overflow
See other posts from Stack Overflow
or by Dave18
Published on 2010-04-27T09:22:49Z
Indexed on
2010/04/27
11:13 UTC
Read the original article
Hit count: 367
does boost library provide functions to pack the class/struct data into a byte array to shorten the length of serialized data? Currently i'm using stringstream to get the serialized data, for example -
struct data
{
std::string s1;
std::string s2;
int i;
};
template <typename Archive>
void serialize(Archive &ar, data &d, const unsigned int version)
{
ar & d.s1;
ar & d.s2;
ar & d.i;
}
int main()
{
data d;
d.s1 = "This is my first string";
d.s2 = "This is my second string";
d.i = 10000;
std::stringstream archive_stream;
boost::archive::text_oarchive archive(archive_stream);
archive.operator <<(d);
}
How would i use a byte array instead of stringstream for data?
© Stack Overflow or respective owner