capnproto-rust icon indicating copy to clipboard operation
capnproto-rust copied to clipboard

Reading messages dynamically without capnpc generation

Open anlumo opened this issue 1 year ago • 3 comments

I'm trying to read Cap'n Proto messages where the schema is only known at runtime. capnproto-c++ does support runtime schema loading, but capnproto-rust does not.

The examples always start with a type from capnpc-generated code and then downcast to dynamic_value, dynamic_struct, etc., but there is no way to get there from a capnp::message::Reader.

Same goes for creating messages based on dynamic_value etc..

It would be great to have this feature added.

anlumo avatar Jan 29 '25 16:01 anlumo

No, capnproto-rust currently does not support that. The dynamic reflection API requires any schemas that are used to be known at compile time.

If you are willing to use C++, capnproto-c++ does support runtime schema loading: https://github.com/capnproto/capnproto/blob/v2/c%2B%2B/src/capnp/schema-loader.h

dwrensha avatar Jan 30 '25 02:01 dwrensha

Unfortunately, using C++ is not an option (I have to support wasm, where mixing Rust and C++ is hard to impossible). Is there any chance that this will be added?

anlumo avatar Jan 30 '25 07:01 anlumo

I've updated the ticket to represent a feature request rather than a question.

anlumo avatar Jan 30 '25 11:01 anlumo