retrieving the ID of a struct

30 views
Skip to first unread message

vlo...@gmail.com

unread,
Apr 22, 2020, 6:35:40 PM4/22/20
to Cap'n Proto
What's the proper way to get the ID associated with a struct at runtime? Will accessing this pull in the entire dynamic schema? I'm hoping I can just get the ID with minimal overhead.

Thanks!

Kenton Varda

unread,
Apr 22, 2020, 6:55:24 PM4/22/20
to Vitali Lovich, Cap'n Proto
Hi Vitali,

Hmm, what do you mean by "at runtime"? Type IDs are not sent on the wire, so if all you have are some bytes, there's no way to get the type ID.

If you know the type at compile time, you can use `capnp::typeId<MyStructType>()` in code to get the type ID of a struct as a constexpr... but that's compile time, not runtime.

-Kenton

On Wed, Apr 22, 2020 at 5:35 PM <vlo...@gmail.com> wrote:
What's the proper way to get the ID associated with a struct at runtime? Will accessing this pull in the entire dynamic schema? I'm hoping I can just get the ID with minimal overhead.

Thanks!

--
You received this message because you are subscribed to the Google Groups "Cap'n Proto" group.
To unsubscribe from this group and stop receiving emails from it, send an email to capnproto+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/capnproto/ed804680-408b-45a4-acaf-a195c560deb1%40googlegroups.com.

Vitali Lovich

unread,
Apr 22, 2020, 7:36:22 PM4/22/20
to Kenton Varda, Cap'n Proto
Sorry. I did mean `capnp::typeId<MyStructType>` rather than looking it up dynamically for a type. Does capnp::typeId cause the entire schema to be pulled in? It looks like it just pulls in EnumInfo<T>::typeId so I'm hoping function/data sections will cause the encoded schema itself to be stripped out.

Kenton Varda

unread,
Apr 22, 2020, 7:43:43 PM4/22/20
to Vitali Lovich, Cap'n Proto
Since it's a constexpr, the compiler will evaluate it to an integer at compile-time, so it shouldn't pull in any symbols at all.

-Kenton
Reply all
Reply to author
Forward
0 new messages