Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Unpacking of std.variant.VariantN #62

Open
nordlow opened this issue Jun 29, 2015 · 2 comments
Open

Support Unpacking of std.variant.VariantN #62

nordlow opened this issue Jun 29, 2015 · 2 comments

Comments

@nordlow
Copy link
Contributor

nordlow commented Jun 29, 2015

How can I extend msgpack and submit a PR to support unpacking of std.variant.VariantN?

import std.variant: Algebraic;
import std.conv;
import std.stdio;
import std.traits;
import std.array: array;

import msgpack;

void main()
{
    auto v = Algebraic!(long, double)(5.to!long);

    assert(v == 5.to!long);
    assert(v == 5.to!double);
    assert(*(v.peek!long) == 5);
    assert(v.peek!double is null);

    writeln(`typeof(v.peek!double).stringof: `, typeof(v.peek!double).stringof);
    writeln(`typeof(v).stringof: `, typeof(v).stringof);
    writeln(`string.sizeof: `, string.sizeof);
    writeln(`v.sizeof: `, v.sizeof);
    writeln(`v.AllowedTypes.stringof: `, v.AllowedTypes.stringof);

    auto vp = v.pack;

    writeln(`typeof(v).stringof: `, typeof(v.pack).stringof);
    writeln(`typeof(vp.unpack).stringof: `, typeof(vp.unpack).stringof);

    writeln("v.pack.array: ", vp.array);

    auto vr = vp.unpack;

    assert(vp == vr);
}

compiles but deserialization errors at run-time as

typeof(v.peek!double).stringof: double*
typeof(v).stringof: VariantN!(8LU, long, double)
string.sizeof: 16
v.sizeof: 16
v.AllowedTypes.stringof: (long, double)
v.pack.array: [146, 168, 5, 0, 0, 0, 0, 0, 0, 0]
msgpack.UnpackException@/home/per/Work/justd/msgpack.d(305): Deserialization failure

Why does msgpack allow serialization but not deserialization?

Notice that VariantN is a struct type.

@nordlow nordlow changed the title Support std.variant.Algebraic Support Unpacking of std.variant.VariantN Jun 29, 2015
@repeatedly
Copy link
Member

Why does msgpack allow serialization but not deserialization?

msgpack-d tries to pack Variant as normal struct. There is no check.
Maybe serialized result doesn't fit for deserialization because Variant uses union.
I will check it later.

@nordlow
Copy link
Contributor Author

nordlow commented Jul 5, 2015

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants