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

capnp: AnyPointer support #220

Open
MostAwesomeDude opened this issue Dec 1, 2020 · 3 comments
Open

capnp: AnyPointer support #220

MostAwesomeDude opened this issue Dec 1, 2020 · 3 comments

Comments

@MostAwesomeDude
Copy link
Contributor

We can't really assign to AnyPointer fields in Capn Proto structures. This is a showstopper for continuing to implement CapTP over Capn Proto RPC.

A solution presumably allows us to decouple writers from schemata a bit more; we need to allow two different schemata to write to the same buffer at once in order to do this correctly. We also want to be able to read from AnyPointers, so we need some sort of casting operator.

@dckc
Copy link
Member

dckc commented Dec 1, 2020

Clue me in? Why would we want / need to assign to AnyPointer fields in Capn Proto structures?

I think I know what Capn Proto structures are. I don't recall off hand what AnyPointer is. I suspect I don't understand "assign" in this context.

@washort
Copy link

washort commented Dec 1, 2020

the capnproto RPC schema has an AnyPointer field for message payloads, so that peers can define their own schema for message contents. We need a way to switch from the "outer" readers/writers to the "inner" ones for the structures referenced via AnyPointer.

@MostAwesomeDude
Copy link
Contributor Author

An AnyPointer (upstream docs) is a dynamically-typed pointer. Recall that, in Capn's encoding framework, trees and structs are passed by pointer; this is a way to reinterpret which schema is being used to decode a particular pointer.

For decoding, it's not hard to imagine that we might want to take some pointer and cast it:

def pointer := struct.getPointer()
def casted := MySchema.cast(pointer)

For encoding, things are trickier due to the current structure of objects. We will probably want to create writers as we do now, but allow for a writer to take a secondary schema and spawn a new structure; this allows for the structure to be foreign but still occupy the same buffer cleanly. Something like:

def writer := makeMainWriter()
def payload := writer.withSchema(MySchema).makeMyStruct(…)
def top := writer.makeTopStruct(=> payload)

In this hypothetical design, the payload is known to the writer to be an AnyPointer; it's opaque but fits into this typed hole, just like how Ints and Strs are adapted to Capn's typing already.

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

3 participants