msoucy / dproto

D Protocol Buffer mixins to create structures at compile time
Boost Software License 1.0
37 stars 16 forks source link

[de]serialization issue -- [packed = true] sint32, sint64, and double #89

Closed bloche closed 8 years ago

bloche commented 8 years ago
import dproto.dproto;

mixin ProtocolBufferFromString!q{
    message Test {
        repeated sint32 id = 1 [packed = true];
    }

};

unittest {
    Test t;

    t.id = [123];

    std.stdio.writeln(t);

    auto s = t.serialize();
    t = Test(s);

    std.stdio.writeln(t);

    assert(t.id == [123]);
}

Deserializing a packed array of signed numbers appears to append a zero.

Test([123])
Test([123, 0])
core.exception.AssertError@src/test.d(22): unittest failure

If id were a double I get:

Test([123])
core.exception.RangeError@std/bitmanip.d(2987): Range violation

The other number types run though fine. e.g. int32, uint64, etc.

msoucy commented 8 years ago

I have confirmed that the in both cases, it's an issue with deserialization, by serializing it via Python and comparing the serialized data. I'm looking at actually fixing the issue now.