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

Reading AnyPointer value #7

Open
nilya opened this issue Dec 11, 2014 · 1 comment
Open

Reading AnyPointer value #7

nilya opened this issue Dec 11, 2014 · 1 comment

Comments

@nilya
Copy link

nilya commented Dec 11, 2014

Hi Kenton,

It seems that capnp-message with AnyPointer value can be serialized, but can't be parsed.

  1. to serialize you should first serialize AnyPointer value and add resulting Buffer to object that you serialize (am i right?).
  2. parse code always returns undefined https://github.com/kentonv/node-capnp/blob/dc538dd4ce390a2615bd645f782c381033632123/src/node-capnp/capnp.cc#L1585

It will be good if parse method returned Buffer object ({ any: <Buffer ...> in the example, which can be parsed itself too) to be consistent with serialize api. Is this possible?

Example:

@0xdbb9ad1f14bf0b36;  # unique file ID, generated by `capnp id`

struct Person {
  any @0 :AnyPointer;
}

struct Date {
  year @0 :Int16;
  month @1 :UInt8;
  day @2 :UInt8;
}
var capnp = require("capnp");
var person = require('./person_any2.capnp');

var objDate = {
  year: 2014,
  month: 12,
  day: 1
}, obj = {
  any: capnp.serialize(person.Date, objDate)
};

var s = capnp.serialize(person.Person, obj);
console.log(s, s.length);

var o = capnp.parse(person.Person, s);
console.log(o);

Output is:

<SlowBuffer 00 00 00 00 03 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 01 00 00 00 de 07 0c 01 00 00 00 00> 32
{ any: undefined }
@kentonv
Copy link
Member

kentonv commented Dec 12, 2014

Indeed, it looks like a missing implementation at capnp.cc:1586:

  case capnp::DynamicValue::ANY_POINTER:
    // TODO(soon):  How do we represent AnyPointer?
    return v8::Undefined();

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