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 { ...@@ -33,6 +33,11 @@ namespace capnproto {
class DynamicStruct; // So that it can be declared a friend. 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 { namespace internal {
template <typename T> template <typename T>
...@@ -118,18 +123,26 @@ struct PointerHelpers<TrustedMessage> { ...@@ -118,18 +123,26 @@ struct PointerHelpers<TrustedMessage> {
#endif #endif
struct RawSchema {
const word* encodedNode;
const RawSchema* dependencies;
};
template <typename T>
inline constexpr const RawSchema& rawSchema();
} // namespace internal } // namespace internal
} // namespace capnproto } // namespace capnproto
#define CAPNPROTO_DECLARE_ENUM(type) \ #define CAPNPROTO_DECLARE_ENUM(type, id) \
template <> struct KindOf<type> { static constexpr Kind kind = Kind::ENUM; } 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 KindOf<type> { static constexpr Kind kind = Kind::STRUCT; }; \
template <> struct StructSizeFor<type> { \ template <> struct StructSizeFor<type> { \
static constexpr StructSize value = StructSize( \ static constexpr StructSize value = StructSize( \
dataWordSize * WORDS, pointerCount * REFERENCES, FieldSize::preferredElementEncoding); \ 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; } template <> struct KindOf<type> { static constexpr Kind kind = Kind::INTERFACE; }
#endif // CAPNPROTO_GENERATED_HEADER_SUPPORT_H_ #endif // CAPNPROTO_GENERATED_HEADER_SUPPORT_H_
...@@ -265,6 +265,7 @@ enumerantContext parent desc = mkStrContext context where ...@@ -265,6 +265,7 @@ enumerantContext parent desc = mkStrContext context where
enumContext parent desc = mkStrContext context where enumContext parent desc = mkStrContext context where
context "enumName" = MuVariable $ enumName desc context "enumName" = MuVariable $ enumName desc
context "enumId" = MuVariable (printf "0x%16x" (enumId desc) ::String)
context "enumerants" = MuList $ map (enumerantContext context) $ enumerants desc context "enumerants" = MuList $ map (enumerantContext context) $ enumerants desc
context s = parent s context s = parent s
...@@ -383,6 +384,7 @@ structContext parent desc = mkStrContext context where ...@@ -383,6 +384,7 @@ structContext parent desc = mkStrContext context where
context "typeFields" = context "structFields" context "typeFields" = context "structFields"
context "structName" = MuVariable $ structName desc context "structName" = MuVariable $ structName desc
context "structId" = MuVariable (printf "0x%16x" (structId desc) ::String)
context "structFullName" = MuVariable $ fullName (DescStruct desc) context "structFullName" = MuVariable $ fullName (DescStruct desc)
context "structFields" = MuList $ map (fieldContext context) $ structFields desc context "structFields" = MuList $ map (fieldContext context) $ structFields desc
context "structUnions" = MuList $ map (unionContext context) $ structUnions desc context "structUnions" = MuList $ map (unionContext context) $ structUnions desc
......
...@@ -105,16 +105,18 @@ namespace internal { ...@@ -105,16 +105,18 @@ namespace internal {
{{#typeStructOrUnion}} {{#typeStructOrUnion}}
{{#typeStruct}} {{#typeStruct}}
CAPNPROTO_DECLARE_STRUCT( CAPNPROTO_DECLARE_STRUCT(
::{{#fileNamespaces}}{{namespaceName}}::{{/fileNamespaces}}{{typeFullName}}, ::{{#fileNamespaces}}{{namespaceName}}::{{/fileNamespaces}}{{typeFullName}}, {{structId}},
{{structDataSize}}, {{structReferenceCount}}, {{structPreferredListEncoding}}); {{structDataSize}}, {{structReferenceCount}}, {{structPreferredListEncoding}});
{{#structNestedEnums}} {{#structNestedEnums}}
CAPNPROTO_DECLARE_ENUM(::{{#fileNamespaces}}{{namespaceName}}::{{/fileNamespaces}}{{typeFullName}}::{{enumName}}); CAPNPROTO_DECLARE_ENUM(
::{{#fileNamespaces}}{{namespaceName}}::{{/fileNamespaces}}{{typeFullName}}::{{enumName}}, {{enumId}});
{{/structNestedEnums}} {{/structNestedEnums}}
{{/typeStruct}} {{/typeStruct}}
{{/typeStructOrUnion}} {{/typeStructOrUnion}}
{{/fileTypes}} {{/fileTypes}}
{{#fileEnums}} {{#fileEnums}}
CAPNPROTO_DECLARE_ENUM(::{{#fileNamespaces}}{{namespaceName}}::{{/fileNamespaces}}{{enumName}}); CAPNPROTO_DECLARE_ENUM(
::{{#fileNamespaces}}{{namespaceName}}::{{/fileNamespaces}}{{enumName}}, {{enumId}});
{{/fileEnums}} {{/fileEnums}}
} // namespace capnproto } // namespace capnproto
} // namespace internal } // 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