Commit 07b979a3 authored by Kenton Varda's avatar Kenton Varda

Test Dynamic API.

parent 08d73bef
......@@ -49,6 +49,8 @@ includecapnp_HEADERS = \
src/capnproto/layout.h \
src/capnproto/list.h \
src/capnproto/message.h \
src/capnproto/schema.h \
src/capnproto/dynamic.h \
src/capnproto/io.h \
src/capnproto/serialize.h \
src/capnproto/serialize-packed.h \
......@@ -73,6 +75,8 @@ libcapnproto_a_SOURCES= \
src/capnproto/layout.c++ \
src/capnproto/list.c++ \
src/capnproto/message.c++ \
src/capnproto/schema.c++ \
src/capnproto/dynamic.c++ \
src/capnproto/io.c++ \
src/capnproto/serialize.c++ \
src/capnproto/serialize-packed.c++
......@@ -117,6 +121,8 @@ capnproto_test_SOURCES = \
src/capnproto/logging-test.c++ \
src/capnproto/layout-test.c++ \
src/capnproto/message-test.c++ \
src/capnproto/schema-test.c++ \
src/capnproto/dynamic-test.c++ \
src/capnproto/encoding-test.c++ \
src/capnproto/serialize-test.c++ \
src/capnproto/serialize-packed-test.c++ \
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -427,7 +427,8 @@ struct WireHelpers {
word* ptr;
if (ref->isNull()) {
if (defaultValue == nullptr) {
if (defaultValue == nullptr ||
reinterpret_cast<const WireReference*>(defaultValue)->isNull()) {
ptr = allocate(ref, segment, size.total(), WireReference::STRUCT);
ref->structRef.set(size);
} else {
......@@ -508,7 +509,8 @@ struct WireHelpers {
word* ptr;
if (ref->isNull()) {
if (defaultValue == nullptr) {
if (defaultValue == nullptr ||
reinterpret_cast<const WireReference*>(defaultValue)->isNull()) {
return ListBuilder();
}
ptr = copyMessage(segment, ref, defaultRef);
......@@ -619,7 +621,8 @@ struct WireHelpers {
word* ptr;
if (ref->isNull()) {
if (defaultValue == nullptr) {
if (defaultValue == nullptr ||
reinterpret_cast<const WireReference*>(defaultValue)->isNull()) {
return ObjectBuilder();
} else {
ptr = copyMessage(segment, ref, reinterpret_cast<const WireReference*>(defaultValue));
......@@ -668,7 +671,8 @@ struct WireHelpers {
if (ref == nullptr || ref->isNull()) {
useDefault:
if (defaultValue == nullptr) {
if (defaultValue == nullptr ||
reinterpret_cast<const WireReference*>(defaultValue)->isNull()) {
return StructReader(nullptr, nullptr, nullptr, 0 * BITS, 0 * REFERENCES, 0 * BITS,
std::numeric_limits<int>::max());
}
......@@ -714,7 +718,8 @@ struct WireHelpers {
const word* ptr;
if (ref == nullptr || ref->isNull()) {
useDefault:
if (defaultValue == nullptr) {
if (defaultValue == nullptr ||
reinterpret_cast<const WireReference*>(defaultValue)->isNull()) {
return ListReader();
}
segment = nullptr;
......@@ -874,7 +879,8 @@ struct WireHelpers {
const void* defaultValue, ByteCount defaultSize)) {
if (ref == nullptr || ref->isNull()) {
useDefault:
if (defaultValue == nullptr) {
if (defaultValue == nullptr ||
reinterpret_cast<const WireReference*>(defaultValue)->isNull()) {
defaultValue = "";
}
return Text::Reader(reinterpret_cast<const char*>(defaultValue), defaultSize / BYTES);
......@@ -973,7 +979,8 @@ struct WireHelpers {
const word* ptr;
if (ref == nullptr || ref->isNull()) {
useDefault:
if (defaultValue == nullptr) {
if (defaultValue == nullptr ||
reinterpret_cast<const WireReference*>(defaultValue)->isNull()) {
return ObjectReader();
}
segment = nullptr;
......
......@@ -647,7 +647,7 @@ struct ObjectBuilder {
ObjectBuilder(): kind(ObjectKind::NULL_POINTER), structBuilder() {}
ObjectBuilder(StructBuilder structBuilder)
: kind(ObjectKind::STRUCT), structBuilder(structBuilder) {}
ObjectBuilder(ListBuilder listBuilderBuilder)
ObjectBuilder(ListBuilder listBuilder)
: kind(ObjectKind::LIST), listBuilder(listBuilder) {}
};
......
......@@ -122,6 +122,12 @@ Maybe<StructSchema::Member> StructSchema::findMemberByName(Text::Reader name) co
return findSchemaMemberByName(raw, name, 0, getMembers());
}
StructSchema::Member StructSchema::getMemberByName(Text::Reader name) const {
Maybe<StructSchema::Member> member = findMemberByName(name);
PRECOND(member != nullptr, "struct has no such member", name);
return *member;
}
Maybe<StructSchema::Union> StructSchema::Member::getContainingUnion() const {
if (unionIndex == 0) return nullptr;
return parent.getMembers()[unionIndex - 1].asUnion();
......@@ -142,6 +148,12 @@ Maybe<StructSchema::Member> StructSchema::Union::findMemberByName(Text::Reader n
return findSchemaMemberByName(parent.raw, name, index + 1, getMembers());
}
StructSchema::Member StructSchema::Union::getMemberByName(Text::Reader name) const {
Maybe<StructSchema::Member> member = findMemberByName(name);
PRECOND(member != nullptr, "struct has no such member", name);
return *member;
}
// -------------------------------------------------------------------
EnumSchema::EnumerantList EnumSchema::getEnumerants() const {
......@@ -152,6 +164,12 @@ Maybe<EnumSchema::Enumerant> EnumSchema::findEnumerantByName(Text::Reader name)
return findSchemaMemberByName(raw, name, 0, getEnumerants());
}
EnumSchema::Enumerant EnumSchema::getEnumerantByName(Text::Reader name) const {
Maybe<EnumSchema::Enumerant> enumerant = findEnumerantByName(name);
PRECOND(enumerant != nullptr, "enum has no such enumerant", name);
return *enumerant;
}
// -------------------------------------------------------------------
InterfaceSchema::MethodList InterfaceSchema::getMethods() const {
......@@ -162,6 +180,12 @@ Maybe<InterfaceSchema::Method> InterfaceSchema::findMethodByName(Text::Reader na
return findSchemaMemberByName(raw, name, 0, getMethods());
}
InterfaceSchema::Method InterfaceSchema::getMethodByName(Text::Reader name) const {
Maybe<InterfaceSchema::Method> method = findMethodByName(name);
PRECOND(method != nullptr, "interface has no such method", name);
return *method;
}
// =======================================================================================
ListSchema ListSchema::of(schema::Type::Body::Which primitiveType) {
......
......@@ -100,8 +100,12 @@ public:
class MemberList;
MemberList getMembers() const;
Maybe<Member> findMemberByName(Text::Reader name) const;
Member getMemberByName(Text::Reader name) const;
// Like findMemberByName() but throws an exception on failure.
private:
StructSchema(const internal::RawSchema* raw): Schema(raw) {}
template <typename T> static inline StructSchema fromImpl() {
......@@ -148,8 +152,12 @@ public:
Union() = default;
MemberList getMembers() const;
Maybe<Member> findMemberByName(Text::Reader name) const;
Member getMemberByName(Text::Reader name) const;
// Like findMemberByName() but throws an exception on failure.
private:
inline Union(const Member& base): Member(base) {}
......@@ -187,8 +195,12 @@ public:
class EnumerantList;
EnumerantList getEnumerants() const;
Maybe<Enumerant> findEnumerantByName(Text::Reader name) const;
Enumerant getEnumerantByName(Text::Reader name) const;
// Like findEnumerantByName() but throws an exception on failure.
private:
EnumSchema(const internal::RawSchema* raw): Schema(raw) {}
template <typename T> static inline EnumSchema fromImpl() {
......@@ -250,8 +262,12 @@ public:
class MethodList;
MethodList getMethods() const;
Maybe<Method> findMethodByName(Text::Reader name) const;
Method getMethodByName(Text::Reader name) const;
// Like findMethodByName() but throws an exception on failure.
private:
InterfaceSchema(const internal::RawSchema* raw): Schema(raw) {}
template <typename T> static inline InterfaceSchema fromImpl() {
......
......@@ -498,7 +498,7 @@ outerFileContext schemaNodes = fileContext where
DescEnum d -> muJust $ enumContext context d
_ -> muNull
context "typeSchema" = case desc of
DescUnion u -> muNull
DescUnion _ -> muNull
_ -> muJust $ schemaContext context desc
context s = parent s
......
......@@ -523,7 +523,7 @@ encodeSchema requestedFiles allFiles = (encRoot, nodesForEmbedding) where
BuiltinType BuiltinFloat64 -> 11
BuiltinType BuiltinText -> 12
BuiltinType BuiltinData -> 13
BuiltinType BuiltinObject -> 19
BuiltinType BuiltinObject -> 18
ListType _ -> 14
EnumType _ -> 15
StructType _ -> 16
......
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