www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Binary serialization of a struct

reply Joseph <JE342 gmail.com> writes:
Are there any simple direct serialization libraries where I can 
mark elements of a class or struct that I want serialized with an 
attribute and it will take care of all the rest(including 
recursive structures, arrays, etc) then deserialize back in to 
the structs?

I want something straight forward without allot of plumbing on my 
end.
Sep 15
next sibling parent Azi Hassan <azi.hassan live.fr> writes:
On Saturday, 16 September 2017 at 03:30:51 UTC, Joseph wrote:
 Are there any simple direct serialization libraries where I can 
 mark elements of a class or struct that I want serialized with 
 an attribute and it will take care of all the rest(including 
 recursive structures, arrays, etc) then deserialize back in to 
 the structs?

 I want something straight forward without allot of plumbing on 
 my end.
Have you checked Cerealed ? From the looks of it, it supports a NoCereal attribute which does the opposite of what you're looking for. Not sure how it handles nested structs, but there are examples in the test/directory : https://github.com/atilaneves/cerealed/
Sep 16
prev sibling next sibling parent Sergei Degtiarev <sdegtiarev yahoo.com> writes:
On Saturday, 16 September 2017 at 03:30:51 UTC, Joseph wrote:
 Are there any simple direct serialization libraries...
 I want something straight forward without allot of plumbing on 
 my end.
You may also take a look at https://github.com/sdegtiarev/persistentObject This is small module for binary serialization.
Sep 16
prev sibling next sibling parent spring <encounterspring 163.com> writes:
On Saturday, 16 September 2017 at 03:30:51 UTC, Joseph wrote:
 Are there any simple direct serialization libraries where I can 
 mark elements of a class or struct that I want serialized with 
 an attribute and it will take care of all the rest(including 
 recursive structures, arrays, etc) then deserialize back in to 
 the structs?

 I want something straight forward without allot of plumbing on 
 my end.
https://github.com/huntlabs/common/blob/master/source/zhang2018/common/Serialize.d only a single file . can serialize/deserialize struct,class,array.
Sep 18
prev sibling parent =?UTF-8?B?Tm9yZGzDtnc=?= <per.nordlow gmail.com> writes:
On Saturday, 16 September 2017 at 03:30:51 UTC, Joseph wrote:
 Are there any simple direct serialization libraries where I can 
 mark elements of a class or struct that I want serialized with 
 an attribute and it will take care of all the rest(including 
 recursive structures, arrays, etc) then deserialize back in to 
 the structs?

 I want something straight forward without allot of plumbing on 
 my end.
https://github.com/msgpack/msgpack-d is about as simple as it can get: import std.file; import msgpack; struct S { int x; float y; string z; } void main() { S input = S(10, 25.5, "message"); // serialize data ubyte[] inData = pack(input); // write data to a file write("file.dat", inData); // read data from a file ubyte[] outData = cast(ubyte[])read("file.dat"); // unserialize the data S target = outData.unpack!S(); // verify data is the same assert(target.x == input.x); assert(target.y == input.y); assert(target.z == input.z); }
Sep 18