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 reply 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
parent Cym13 <cpicard openmailbox.org> writes:
On Saturday, 16 September 2017 at 13:15:54 UTC, Azi Hassan wrote:
 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/
Cerealed is definitely my favourite library out there for binary serialization. High quality.
Dec 08
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 reply =?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
parent reply kdevel <kdevel vogtner.de> writes:
On Tuesday, 19 September 2017 at 06:32:52 UTC, Nordlöw wrote:
 I want something straight forward without allot of plumbing on 
 my end.
https://github.com/msgpack/msgpack-d
I can't unittest my 32-bit code: $ MODEL=32 make -f posix.mak unittest [...] src/msgpack/packer.d(1139): Error: function core.stdc.stdlib.malloc (uint size) is not callable using argument types (ulong)
Dec 07
parent Daniel Kozak <kozzi11 gmail.com> writes:
You should use size_t instead of ulong, but on 32bit you would have still
problem because you are trying assign 2^32 which is too big to hold in 32bi=
t

On Thu, Dec 7, 2017 at 11:42 PM, kdevel via Digitalmars-d-learn <
digitalmars-d-learn puremagic.com> wrote:

 On Tuesday, 19 September 2017 at 06:32:52 UTC, Nordl=C3=B6w wrote:

 I want something straight forward without allot of plumbing on my end.

 https://github.com/msgpack/msgpack-d
I can't unittest my 32-bit code: $ MODEL=3D32 make -f posix.mak unittest [...] src/msgpack/packer.d(1139): Error: function core.stdc.stdlib.malloc (uint size) is not callable using argument types (ulong)
Dec 08