On Monday, 4 August 2014 at 14:18:41 UTC, Jacob Carlborg wrote:
On Monday, 4 August 2014 at 14:02:22 UTC, Dicebot wrote:
Do you consider structs primitive types? This is probably #1
use case for JSON conversion.
No, only types that cannot be broken down in to smaller pieces,
i.e. integral, floating points, bool and strings.
That is exactly the problem - if `structToJson` won't be
provided, complaints are inevitable, it is too basic feature to
wait for std.serialization :(
http://forum.dlang.org/post/mzweposldwqdtmqol...@forum.dlang.org
I don't understand exactly how that binary serialization works.
I think I would need a code example.
Simplified serialization algorithm:
1) write (cast(void*) &struct)[0..struct.sizeof] to target buffer
2) write any of array content to the same buffer after the struct
3.1) if array contains structs, recursion
3.2) go back to buffer[0..struct.sizeof] slice and update array
fields to store an index in the same buffer instead of actual ptr
Simplified deserialization algorithm:
1) recursively traverse the struct and replace array index
offsets with real slices to the buffer
(I don't want to bother with getting copyright permissions to
publish actual code)
I am pretty sure that this is not the only optimized
serialization approach out there that does not fit in a
content-insensitive primitive-based traversal scheme. And we
won't Phobos stuff to be blazingly fast which can lead to
situation where new data module will circumvent the
std.serialization API to get more performance.