Commit 18cfa132 authored by Kenton Varda's avatar Kenton Varda

Dynamic API WIP.

parent 1a515be7
This diff is collapsed.
This diff is collapsed.
......@@ -33,6 +33,11 @@ namespace capnproto {
class DynamicStruct; // So that it can be declared a friend.
template <typename T>
inline constexpr uint64_t typeId();
// typeId<MyType>() returns the type ID as defined in the schema. Works with structs, enums, and
// interfaces.
namespace internal {
template <typename T>
......@@ -118,18 +123,26 @@ struct PointerHelpers<TrustedMessage> {
#endif
struct RawSchema {
const word* encodedNode;
const RawSchema* dependencies;
};
template <typename T>
inline constexpr const RawSchema& rawSchema();
} // namespace internal
} // namespace capnproto
#define CAPNPROTO_DECLARE_ENUM(type) \
#define CAPNPROTO_DECLARE_ENUM(type, id) \
template <> struct KindOf<type> { static constexpr Kind kind = Kind::ENUM; }
#define CAPNPROTO_DECLARE_STRUCT(type, dataWordSize, pointerCount, preferredElementEncoding) \
#define CAPNPROTO_DECLARE_STRUCT(type, id, dataWordSize, pointerCount, preferredElementEncoding) \
template <> struct KindOf<type> { static constexpr Kind kind = Kind::STRUCT; }; \
template <> struct StructSizeFor<type> { \
static constexpr StructSize value = StructSize( \
dataWordSize * WORDS, pointerCount * REFERENCES, FieldSize::preferredElementEncoding); \
}
#define CAPNPROTO_DECLARE_INTERFACE(type) \
#define CAPNPROTO_DECLARE_INTERFACE(type, id) \
template <> struct KindOf<type> { static constexpr Kind kind = Kind::INTERFACE; }
#endif // CAPNPROTO_GENERATED_HEADER_SUPPORT_H_
......@@ -265,6 +265,7 @@ enumerantContext parent desc = mkStrContext context where
enumContext parent desc = mkStrContext context where
context "enumName" = MuVariable $ enumName desc
context "enumId" = MuVariable (printf "0x%16x" (enumId desc) ::String)
context "enumerants" = MuList $ map (enumerantContext context) $ enumerants desc
context s = parent s
......@@ -383,6 +384,7 @@ structContext parent desc = mkStrContext context where
context "typeFields" = context "structFields"
context "structName" = MuVariable $ structName desc
context "structId" = MuVariable (printf "0x%16x" (structId desc) ::String)
context "structFullName" = MuVariable $ fullName (DescStruct desc)
context "structFields" = MuList $ map (fieldContext context) $ structFields desc
context "structUnions" = MuList $ map (unionContext context) $ structUnions desc
......
......@@ -105,16 +105,18 @@ namespace internal {
{{#typeStructOrUnion}}
{{#typeStruct}}
CAPNPROTO_DECLARE_STRUCT(
::{{#fileNamespaces}}{{namespaceName}}::{{/fileNamespaces}}{{typeFullName}},
::{{#fileNamespaces}}{{namespaceName}}::{{/fileNamespaces}}{{typeFullName}}, {{structId}},
{{structDataSize}}, {{structReferenceCount}}, {{structPreferredListEncoding}});
{{#structNestedEnums}}
CAPNPROTO_DECLARE_ENUM(::{{#fileNamespaces}}{{namespaceName}}::{{/fileNamespaces}}{{typeFullName}}::{{enumName}});
CAPNPROTO_DECLARE_ENUM(
::{{#fileNamespaces}}{{namespaceName}}::{{/fileNamespaces}}{{typeFullName}}::{{enumName}}, {{enumId}});
{{/structNestedEnums}}
{{/typeStruct}}
{{/typeStructOrUnion}}
{{/fileTypes}}
{{#fileEnums}}
CAPNPROTO_DECLARE_ENUM(::{{#fileNamespaces}}{{namespaceName}}::{{/fileNamespaces}}{{enumName}});
CAPNPROTO_DECLARE_ENUM(
::{{#fileNamespaces}}{{namespaceName}}::{{/fileNamespaces}}{{enumName}}, {{enumId}});
{{/fileEnums}}
} // namespace capnproto
} // namespace internal
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment