Dynamic reflection - clarify question...

82 views
Skip to first unread message

jacek.m...@gmail.com

unread,
Feb 6, 2017, 7:47:52 AM2/6/17
to Cap'n Proto
Hi
I have important questions about dynamic reflection:
Is that true that dynamic reflection works only with compiled *.capnp files (and statically linked to exe/dll)?
And it is not possible just to have *.capnp file and compile them "on the fly" and use in dynamic reflection?

Please answer both this questions because we are looking for dynamic solution of the process (on different machines) data interchange. And we can't recompile our programs and libraries each time new table will appear in our system...

thank you and best regards
Jacek

Kenton Varda

unread,
Feb 6, 2017, 2:04:16 PM2/6/17
to jacek.m...@gmail.com, Cap'n Proto
On Mon, Feb 6, 2017 at 4:47 AM, <jacek.m...@gmail.com> wrote:
Hi
I have important questions about dynamic reflection:
Is that true that dynamic reflection works only with compiled *.capnp files (and statically linked to exe/dll)?

No. You can load schemas dynamically using `capnp::SchemaLoader` (if you already have them in binary format as defined in `schema.capnp`) or `capnp::SchemaParser` (to parse text schemas at runtime).
 
And it is not possible just to have *.capnp file and compile them "on the fly" and use in dynamic reflection?

You can use `capnp::SchemaParser`. You will need to link against the library `libcapnpc.so` in addition to `libcapnp.so`.

However, it's more secure and robust to exchange schemas in binary format if possible, and that does not require `libcapnpc.so`.

For example, say you want to design a server that sits in front of a database, receives Cap'n Proto messages, and inserts them into the database, converting each field into a row. The server needs to know the message schema in order to extract field values to turn them into rows. But, it is intended to work with many different clients with different schemas and can't be recompiled every time a client changes schema.

In this example, the client should send capnp::schema::Node structures (defined in `schema.capnp`) to the server, defining the types in question. These schema nodes are compiled into the client (the capnp generated code includes embedded binary schemas). You can obtain the schema node for a type using `capnp::Schema::from<Type>().getProto()`.

-Kenton

Harris Hancock

unread,
Feb 6, 2017, 6:26:13 PM2/6/17
to Kenton Varda, jacek.m...@gmail.com, Cap'n Proto
On Mon, Feb 6, 2017 at 11:03 AM, Kenton Varda <ken...@sandstorm.io> wrote:
On Mon, Feb 6, 2017 at 4:47 AM, <jacek.m...@gmail.com> wrote:
Hi
I have important questions about dynamic reflection:
Is that true that dynamic reflection works only with compiled *.capnp files (and statically linked to exe/dll)?

No. You can load schemas dynamically using `capnp::SchemaLoader` (if you already have them in binary format as defined in `schema.capnp`) or `capnp::SchemaParser` (to parse text schemas at runtime).
 
And it is not possible just to have *.capnp file and compile them "on the fly" and use in dynamic reflection?

You can use `capnp::SchemaParser`. You will need to link against the library `libcapnpc.so` in addition to `libcapnp.so`.

However, it's more secure and robust to exchange schemas in binary format if possible, and that does not require `libcapnpc.so`.
 
Also, libcapnpc (for `capnp::SchemaParser`) isn't available under MSVC, which it sounds like you'd like to target, Jacek. It should build with VS2017 eventually, but in the meantime, `capnp::SchemaLoader` is the only option under MSVC.
Reply all
Reply to author
Forward
0 new messages