capnproto / node-capnp

Cap'n Proto bindings for Node.js
BSD 2-Clause "Simplified" License
258 stars 35 forks source link

unions with Void variants can change value through a serialization round trip #24

Closed dwrensha closed 8 years ago

dwrensha commented 9 years ago
# test.capnp

@0xd9e3377e4e6ce441;

struct Foo {
  union {
   a @0 :Void;
   b @1 :Void;
 }
}
// test.js

Capnp = require('capnp');
Foo = Capnp.import('test.capnp').Foo;

var foo = {b: false}; // any falsey value is allowed for a Void field.

var outputBuffer = Capnp.serialize(Foo, foo);
var obj = Capnp.parse(Foo, outputBuffer);

console.log(obj); // "{ b: null }", as expected

var outputBuffer2 = Capnp.serialize(Foo, obj);
var obj2 = Capnp.parse(Foo, outputBuffer2);

console.log(obj2); // "{ a: null }", not as expected; the value has changed!

It looks like this problem was introduced in https://github.com/kentonv/node-capnp/pull/17.

kentonv commented 8 years ago

Probably fixed by 10e269d.

dwrensha commented 8 years ago

I just confirmed that this program now has the expected output.