I'm looking for a D template library to take an arbitrary variable and marshal it into a transportable bundle. The variable might be a basic value type (int
, char[]
, real
) or might be a struct
or class
and even might contain or be a reference type. A system that can do this without any per type help would be nice but I suspect that it's to much to ask so I'd be happy with something that uses light weight annotations.
If nothing like that exists suggestions on how to structure it would be nice. I can think of a few ways to do the sterilization but I'm not sure how to specify the annotations.
Background: After trying to use ASMX and WCF web services and not likening them I'm felling like I want to try my hand at the RPC problem.
edit: BTW I don't care to much what the format in the middle is (XML, JASON, YAML, binary) as long as it's portable.
Serialization is the process of converting an object into a format that can be readily persisted or transported. For example, you can serialize an object, transport it over the Internet using HTTP, and deserialized it at the destination machine.
To make a Java object serializable we implement the java. io. Serializable interface. The ObjectOutputStream class contains writeObject() method for serializing an Object.
XML , JSON , BSON, YAML , MessagePack, and protobuf are some commonly used data serialization formats.
For serializing the object, we call the writeObject() method of ObjectOutputStream class, and for deserialization we call the readObject() method of ObjectInputStream class. We must have to implement the Serializable interface for serializing the object.
Here's a basic one I wrote for D 1.x. It was written quite some time ago, so it might be possible to improve it, but it does work. The actual format is basically network byte-order binary, so it should be safe to store and transfer the bytes.
http://gist.github.com/100885
It doesn't support classes or arbitrary pointers. To do that properly, you'd want something which memorised what references it had already serialised. If you restrict yourself to value types, arrays and AAs, it'll do the job.
If you do want to extend it to support classes, my advice would be to require toStream and fromStream methods to be defined.
Have a look at Google Protocol Buffers. Maybe you can use the C++ or C bindings directly, or write D bindings yourself.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With