How to use the AnyPointer type?
See original GitHub issueHi,
I have a Request
struct with the following schema:
struct Request {
timestamp @0: UInt64;
payload @1: AnyPointer;
}
The payload
can either be a capnp.Data
struct filled from a Node.js Buffer, or another user-defined struct (let’s say a Todo
struct for example). How am I supposed to create a message with such payload?
I tried the following:
const msg = new capnp.Message();
const req = msg.initRoot(Request);
req.setTimestamp(capnp.Uint64.fromNumber(0));
// With a capnp.Data struct:
const payload = capnp.Struct.initStructAt(0, capnp.Data, req);
payload.copyBuffer(Buffer.from("coucou"));
req.setPayload(payload);
// or with a Todo struct:
const payload = capnp.Struct.initStrutAt(0, Todo, req);
payload.setText("Masterize capnp-ts");
payload.setDone(false);
res.setPayload(payload);
The payload is transmitted but the timestamp
field seems corrupted when I set the payload. So, what is the correct way to fill this AnyPointer payload
field?
Issue Analytics
- State:
- Created 4 years ago
- Comments:9 (1 by maintainers)
Top Results From Across the Web
any-pointer - CSS: Cascading Style Sheets - MDN Web Docs
The any-pointer CSS media feature tests whether the user has any pointing device (such as a mouse), and if so, how accurate it...
Read more >Pointer and ANY Pointer - 253126 - Industry Support Siemens
In the helps file, i just know about pointer contains 6 bytes and ANY contains 10 bytes. I need to take the DB...
Read more >Siemens S7 How to use ANY Pointer in Siemens step-7
In this video we have explained ANY pointer in simple way with an example.SFC 20 used with any pointer with dynamic Parameterization.
Read more >C: Pointers to any type? - Stack Overflow
Yes, you can use a void* to point to anything, and then cast it to the proper type when needed (that's how malloc...
Read more >Pointers and Pointer Types (Delphi) - RAD Studio
Any data type that requires large, dynamically allocated blocks of memory uses pointers. Long-string variables, for instance, are implicitly pointers, as are ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I finally found a very hacky way to fill the
capnp.Data
struct. First, I created aDataBox
struct with the following schema:Then I use it like this:
It is obviously not ideal so I won’t close this issue, but it seems to work.
Sorry for the necro thread, but this still seems to be an issue: this could definitely be user error, but as far as I can tell a few data types (Data & AnyPointer are the ones tested) are near impossible to use because
copyBuffer
has some fundamental issues in that it assumes your destination buffer is (at least) the right size.In my setup, I’m working with a protobuf struct like
Accompanying JS code looks like
I’d like to copy an externally populated Uint8Array
prepopulatedBuffer
todata
. However, passing both the raw Uint8Array and the Uint8Array as an ArrayBuffer (viaprepopulatedBuffer.buffer
) don’t accomplish this because copyBuffer truncates based on the destination size (which I haven’t found a way to not be 0 yet) and results in the same behavior @jonathan-roy was seeing.