November 20, 2013
> assert(foo2.a[1] == 10); // will this pass?

Ah, I see. No, it won't. Which answers the other question about serialising references to objects. I'm told this is a common problem, but this being my first bash at a serialisation library...

I was certain that Orange would be more mature and handle more corner cases than this library (or else it wouldn't be considered for inclusion in the std lib), but I wanted to share it since it works for what I'm doing, does things a bit differently and does what I need. Also, it was fun coding it.

If anything, if you think some of these ideas are worth it, feel free to use them. I'm just glad to not have to write the same old bit twiddling code for networking headers again!

> Even if you know the identifier in the header file you need a static type when deserializing:
>
> decerealiser.value!(Foo)
>
> Even if you can instantiate the right subclass you need to have the static type information to deserialize it.
>
> It is possible to do, as I have done in Orange. The requirement is to register the subclasses that need to be serialized through a base class reference. See https://github.com/jacob-carlborg/orange/blob/master/orange/serialization/Serializer.d#L241..L262 and https://github.com/jacob-carlborg/orange/blob/master/orange/serialization/Serializer.d#L787..L788

True, I thought of doing something like it to simplify my MQTT broker implementation but ended up deciding against it.

November 20, 2013
On 2013-11-20 18:26, Atila Neves wrote:

> Ah, I see. No, it won't. Which answers the other question about
> serialising references to objects. I'm told this is a common problem,
> but this being my first bash at a serialisation library...

It's a lot easier to add support for references than slices. The reason is that you always know when there is a reference type. With arrays you don't know if it's a slice of some array or an actual array. The type system treats both slices and arrays the same.

-- 
/Jacob Carlborg
September 08, 2014
Hello Atila,
I've seen that cerealed has made much progress, it's now at v0.5.0
This post is for a feature request, I would like to use it with a struct like this:

import cerealed;

struct nested_associative_array { nested_associative_array[int] x; }

struct some_struct {
	string[] x;
	int[][] y;
	nested_associative_array[] z;
};

void main(char[][] args) {
	some_struct original, restored;

	auto enc = Cerealiser();
	enc ~= original;
	auto dec = Decerealiser(enc.bytes);
	restored = dec.value!(some_struct);

	assert(original==restored);
}

The serialization process compiles fine, but the restoring part fails to compile.
I've tried to figure out how to do it, but I am still a beginner on D.
How difficult do you think it is?
The alternative, orange, works fine, but the struct I'm trying to export to disk is a few hundreds of MB in size and orange takes hours to complete and may also run out of memory. Your implementation, instead, is really fast and efficient!
September 09, 2014
I'll take a look. It's easier to post this on github though.

Atila

On Monday, 8 September 2014 at 19:09:30 UTC, Vicente wrote:
> Hello Atila,
> I've seen that cerealed has made much progress, it's now at v0.5.0
> This post is for a feature request, I would like to use it with a struct like this:
>
> import cerealed;
>
> struct nested_associative_array { nested_associative_array[int] x; }
>
> struct some_struct {
> 	string[] x;
> 	int[][] y;
> 	nested_associative_array[] z;
> };
>
> void main(char[][] args) {
> 	some_struct original, restored;
>
> 	auto enc = Cerealiser();
> 	enc ~= original;
> 	auto dec = Decerealiser(enc.bytes);
> 	restored = dec.value!(some_struct);
>
> 	assert(original==restored);
> }
>
> The serialization process compiles fine, but the restoring part fails to compile.
> I've tried to figure out how to do it, but I am still a beginner on D.
> How difficult do you think it is?
> The alternative, orange, works fine, but the struct I'm trying to export to disk is a few hundreds of MB in size and orange takes hours to complete and may also run out of memory. Your implementation, instead, is really fast and efficient!

September 11, 2014
Done.

Thanks for the feature request and using Cerealed! I hope it's useful to you.

Atila

On Monday, 8 September 2014 at 19:09:30 UTC, Vicente wrote:
> Hello Atila,
> I've seen that cerealed has made much progress, it's now at v0.5.0
> This post is for a feature request, I would like to use it with a struct like this:
>
> import cerealed;
>
> struct nested_associative_array { nested_associative_array[int] x; }
>
> struct some_struct {
> 	string[] x;
> 	int[][] y;
> 	nested_associative_array[] z;
> };
>
> void main(char[][] args) {
> 	some_struct original, restored;
>
> 	auto enc = Cerealiser();
> 	enc ~= original;
> 	auto dec = Decerealiser(enc.bytes);
> 	restored = dec.value!(some_struct);
>
> 	assert(original==restored);
> }
>
> The serialization process compiles fine, but the restoring part fails to compile.
> I've tried to figure out how to do it, but I am still a beginner on D.
> How difficult do you think it is?
> The alternative, orange, works fine, but the struct I'm trying to export to disk is a few hundreds of MB in size and orange takes hours to complete and may also run out of memory. Your implementation, instead, is really fast and efficient!

1 2
Next ›   Last »