Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python-style pickling for C++?

Does anyone know of a "language level" facility for pickling in C++? I don't want something like Boost serialization, or Google Protocol Buffers. Instead, something that could automatically serialize all the members of a class (with an option to exclude some members, either because they're not serializable, or else because I just don't care to save them for later). This could be accomplished with an extra action at parse time, that would generate code to handle the automatic serialization. Has anyone heard of anything like that?

like image 372
Roni Choudhury Avatar asked Nov 10 '10 21:11

Roni Choudhury


People also ask

What is Python pickle format?

Pickle in Python is primarily used in serializing and deserializing a Python object structure. In other words, it's the process of converting a Python object into a byte stream to store it in a file/database, maintain program state across sessions, or transport data over the network.

Are Python pickles good?

Pickle constructs arbitrary Python objects by invoking arbitrary functions, that's why it is not secure. However, this enables it to serialise almost any Python object that JSON and other serialising methods will not do. Unpickling an object usually requires no “boilerplates”.

Is cPickle faster than pickle?

Difference between Pickle and cPickle: Pickle uses python class-based implementation while cPickle is written as C functions. As a result, cPickle is many times faster than pickle.

Is Python pickle human readable?

The Python pickle module is another way to serialize and deserialize objects in Python. It differs from the json module in that it serializes objects in a binary format, which means the result is not human readable.


2 Answers

I don't believe there's any way to do this in a language with no run-time introspection capabilities.

like image 160
Ferruccio Avatar answered Oct 31 '22 21:10

Ferruccio


perhaps xml Data Binding? gsoap is just one of many options. You can automatically generate code for mapping between data structure and xml schema. Not sure that setting this up would be easier than other options you mention

like image 42
davka Avatar answered Oct 31 '22 21:10

davka