Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I need a serialization framework for D

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.

like image 473
BCS Avatar asked Apr 23 '09 20:04

BCS


People also ask

What is a serialization framework?

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.

How do you create serialization?

To make a Java object serializable we implement the java. io. Serializable interface. The ObjectOutputStream class contains writeObject() method for serializing an Object.

What are two popular methods of data serialization?

XML , JSON , BSON, YAML , MessagePack, and protobuf are some commonly used data serialization formats.

Which method is used for serialization?

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.


2 Answers

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.

like image 29
DK. Avatar answered Sep 25 '22 18:09

DK.


Have a look at Google Protocol Buffers. Maybe you can use the C++ or C bindings directly, or write D bindings yourself.

like image 67
JesperE Avatar answered Sep 26 '22 18:09

JesperE