Questions tagged [boost-serialization]

Boost.Serialization is a cross-platform C++ serialization library.

Boost.Serialization is a cross-platform C++ serialization library. Here, we use the term "serialization" to mean the reversible deconstruction of an arbitrary set of C++ data structures to a sequence of bytes. Such a system can be used to reconstitute an equivalent structure in another program context. Depending on the context, this might be used to implement object persistence, remote parameter passing or other facility. In this system we use the term "archive" to refer to a specific rendering of this stream of bytes. This could be a file of binary data, text data, XML, or some other created by the user of this library.

Boost.Serialization goals:

  1. Code portability - depend only on ANSI C++ facilities.
  2. Code economy - exploit features of C++ such as RTTI, templates, and multiple inheritance, etc. where appropriate to make code shorter and simpler to use.
  3. Independent versioning for each class definition. That is, when a class definition changed, older files can still be imported to the new version of the class.
  4. Deep pointer save and restore. That is, save and restore of pointers saves and restores the data pointed to.
  5. Proper restoration of pointers to shared data.
  6. Serialization of STL containers and other commonly used templates.
  7. Data Portability - Streams of bytes created on one platform should be readable on any other.
  8. Orthogonal specification of class serialization and archive format. That is, any file format should be able to store serialization of any arbitrary set of C++ data structures without having to alter the serialization of any class.
  9. Non-intrusive. Permit serialization to be applied to unaltered classes. That is, don't require that classes to be serialized be derived from a specific base class or implement specified member functions. This is necessary to easily permit serialization to be applied to classes from class libraries that we cannot or don't want to have to alter.
  10. The archive interface must be simple enough to easily permit creation of a new type of archive.
  11. The archive interface must be rich enough to permit the creation of an archive that presents serialized data as XML in a useful manner.
448 questions
69
votes
11 answers

boost serialization vs google protocol buffers?

Does anyone with experience with these libraries have any comment on which one they preferred? Were there any performance differences or difficulties in using?
26
votes
2 answers

How to hook up Boost serialization & iostreams to serialize & gzip an object to string?

I've been using the Boost serialization library, which is actually pretty nice, and lets me make simple wrappers to save my serializable objects to strings, like so: namespace bar = boost::archive; namespace bio = boost::iostreams; template
cce
  • 4,874
  • 2
  • 28
  • 25
24
votes
7 answers

How can boost::serialization be used with std::shared_ptr from C++11?

I know that there is a Boost module for serialization of boost::shared_ptr, but I cannot find anything for std::shared_ptr. Also, I don't know how to implement it easily. I'm afraid that the following code namespace boost{namespace…
fiktor
  • 1,303
  • 2
  • 11
  • 22
17
votes
1 answer

Boost.Asio with google protocol buffers

I've currently investigating ways of improving our current c++ network hand-made serialization mechanism maintaining our existing binary protocol. The first approach taken was to code it using Boost.Asio with Boost.Serialisation using binary…
jvaz
  • 201
  • 2
  • 7
16
votes
2 answers

Serialize to XML using boost::serialization

This is a newbie question. I am trying to serialize some objects to XML, but the resulting XML contains a boost serialization signature, version information, class id, ...etc. that I do not need. Is there a way to get rid of them without…
navigator
  • 1,588
  • 1
  • 13
  • 19
15
votes
2 answers

Derived class serialization without class tracking in Boost (C++)

I have some problems with boost serialization when serializing derived class through base class pointer. I need a system which serializes some objects as they are being received in the system, so I need to serialize over time. This is not really a…
Alvaro Luis Bustamante
  • 8,157
  • 3
  • 28
  • 42
14
votes
2 answers

Linker errors when using boost serialization

I am using boost serialization. I compiled with: -L/opt/local/lib -lboost_serialization -stdlib=libc++, but got several (ungooglable) errors: Undefined symbols for architecture x86_64: …
user142019
14
votes
4 answers

Does Boost.Serialization serialize differently on different platforms?

I use Boost.Serialization to serialize a std::map. The code looks like this void Dictionary::serialize(std::string & buffer) { try { std::stringstream ss; boost::archive::binary_oarchive archive(ss); archive << dict_; buffer =…
Jan Deinhard
  • 19,645
  • 24
  • 81
  • 137
14
votes
3 answers

Does boost support serialization of c++11's std::tuple?

Does boost support serialization of c++11's std::tuple? I couldn't find a tuple.hpp header file at /boost/serialization/ I'm using boost 1.52.0 (happy to upgrade if need be, but it seems like the changes in version 1.53 doesn't have anything…
Ammar
  • 573
  • 1
  • 4
  • 14
11
votes
3 answers

Boost serialization: specifying a template class version

I have a template class that I serialize (call it C), for which I want to specify a version for boost serialization. As BOOST_CLASS_VERSION does not work for template classes. I tried this: namespace boost { namespace serialization { template<…
Jazz
  • 5,747
  • 5
  • 43
  • 55
11
votes
3 answers

portable archive not compiling under GCC

I need to (de)serialize data on both Windows and Linux (and transfer the files in between). I wanted to use the portable binary archives of Boost's serialization library which can be found in the examples, see e.g. at…
Philipp
  • 11,549
  • 8
  • 66
  • 126
11
votes
6 answers

Where to put BOOST_CLASS_EXPORT for boost::serialization?

I'm trying to serialize a pointer to a polymorphic class Shape. So I need to use the BOOST_CLASS_EXPORT macro to define a GUID for each subclass. The problem: where to put it? Let me show a minimal test case first: shapes.hpp #include…
Thomas
  • 174,939
  • 50
  • 355
  • 478
11
votes
1 answer

boost::asio read n bytes from socket to streambuf

I have a serialized structure, which is being sent via socket. I need to read it in chunks, since one of its fields contains the size of the data remaining: I need to read first few bytes, find out the length and read the rest. This is what I have…
11
votes
1 answer

c++11 std::shared_ptr + boost::serialization

Hi has anybody already managed to serialize a C++11 std::shared_ptr with boost::serialization. There are lots of obsolete posts out there but none with an acceptable solution. I am not going into discussion why I want to use the std::shared_ptr just…
denim
  • 1,329
  • 1
  • 15
  • 24
10
votes
3 answers

Boost Serialization Library upgrade

How do I know that I can safely upgrade Boost Serialization Library on a production system without breaking compatibility with the existing data ? Is there any test that I should perform in order to be sure that all data stored in the binary format…
Konstantin
  • 6,061
  • 8
  • 40
  • 48
1
2 3
29 30