(De)Serializing interfaces
nims via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sun Aug 23 03:17:41 PDT 2015
On Sunday, 23 August 2015 at 08:38:14 UTC, Rikki Cattermole wrote:
> What I was thinking was having a serialize method take an
> output range which you will just pass in a value.
I'm not really sure what you mean. Replacing the operator by a
range function or serializing everything automatically?
> A hash? Yeah, TypeInfo_Class should. It will take a pointer.
> https://github.com/D-Programming-Language/druntime/blob/master/src/object.d#L261
>
> size_t hash = typeid(avalue).getHash(&avalue);
>
> But keep in mind avalue must be an rvalue.
Sounds good! How do I then create an instance having the same
type?
> My suggestion would be evaluate the type "down" aka get
> immutable(char) from immutable(char)[] aka string. So don't try
> to serialize the string straight. Grab the length put that to
> the output range, then try to serialize each of the values of
> the array individually as another function call to itself.
>
> Same sort of deal with other classes, check that they have the
> interface and if so, call it's serialize method with yourself.
>
> A little confusing I must admit.
I'm sorry I didn't get that. Would you have a piece of code for
illustration?
More information about the Digitalmars-d-learn
mailing list