Write struct to file
Andrej Mitrovic
andrej.mitrovich at gmail.com
Sun Feb 26 16:52:01 PST 2012
On 2/27/12, Ali Çehreli <acehreli at yahoo.com> wrote:
> D is awesome compared to C as it enables serializing/deserializing data
> with its generic programming and compile-time reflection features like this:
>
> http://dlang.org/traits.html#allMembers
ae's json uses .tupleof, and does it in 40(!)* lines of code.
* Well there's a helper function that escapes some strings, but in
essence it's 40 lines of code that do most of the work.
I think I'm going to print this out, frame it, and put it on a wall
because it's just so damn concise:
https://github.com/CyberShadow/ae/blob/master/utils/json.d#L69
(This is Vladimir's code for those not in the know)
> > ae.utils.json <-- this will be not as "cool" as writing it raw binary? :p
>
> Must be subjective. I find json output cooler that binary. :p
Yeah and again if there are no references he can simply use the
cast(void*)[0..len] trick. The challenge would be to implement this
for reference types.
More information about the Digitalmars-d-learn
mailing list