Commit b731cf8f authored by Kenton Varda's avatar Kenton Varda

Better check that schema matches exactly here.

parent e5e34217
...@@ -281,17 +281,11 @@ void DynamicUnion::Builder::setObjectDiscriminant(StructSchema::Member member) { ...@@ -281,17 +281,11 @@ void DynamicUnion::Builder::setObjectDiscriminant(StructSchema::Member member) {
// ======================================================================================= // =======================================================================================
void DynamicStruct::Reader::verifyTypeId(uint64_t id) { void DynamicStruct::Reader::verifySchema(StructSchema expected) {
VALIDATE_INPUT(id == schema.getProto().getId(), PRECOND(schema == expected, "Type mismatch when using DynamicStruct::Reader::as().");
"Type mismatch when using DynamicStruct::Reader::as().") {
// Go on with bad type ID.
}
} }
void DynamicStruct::Builder::verifyTypeId(uint64_t id) { void DynamicStruct::Builder::verifySchema(StructSchema expected) {
VALIDATE_INPUT(id == schema.getProto().getId(), PRECOND(schema == expected, "Type mismatch when using DynamicStruct::Builder::as().");
"Type mismatch when using DynamicStruct::Builder::as().") {
// Go on with bad type ID.
}
} }
DynamicValue::Reader DynamicStruct::Reader::get(StructSchema::Member member) { DynamicValue::Reader DynamicStruct::Reader::get(StructSchema::Member member) {
......
...@@ -267,7 +267,7 @@ private: ...@@ -267,7 +267,7 @@ private:
inline Reader(StructSchema schema, internal::StructReader reader) inline Reader(StructSchema schema, internal::StructReader reader)
: schema(schema), reader(reader) {} : schema(schema), reader(reader) {}
void verifyTypeId(uint64_t id); void verifySchema(StructSchema expected);
static DynamicValue::Reader getImpl(internal::StructReader reader, StructSchema::Member member); static DynamicValue::Reader getImpl(internal::StructReader reader, StructSchema::Member member);
...@@ -344,7 +344,7 @@ private: ...@@ -344,7 +344,7 @@ private:
inline Builder(StructSchema schema, internal::StructBuilder builder) inline Builder(StructSchema schema, internal::StructBuilder builder)
: schema(schema), builder(builder) {} : schema(schema), builder(builder) {}
void verifyTypeId(uint64_t id); void verifySchema(StructSchema expected);
static DynamicValue::Builder getImpl( static DynamicValue::Builder getImpl(
internal::StructBuilder builder, StructSchema::Member member); internal::StructBuilder builder, StructSchema::Member member);
...@@ -858,14 +858,14 @@ template <typename T> ...@@ -858,14 +858,14 @@ template <typename T>
typename T::Reader DynamicStruct::Reader::as() { typename T::Reader DynamicStruct::Reader::as() {
static_assert(kind<T>() == Kind::STRUCT, static_assert(kind<T>() == Kind::STRUCT,
"DynamicStruct::Reader::as<T>() can only convert to struct types."); "DynamicStruct::Reader::as<T>() can only convert to struct types.");
verifyTypeId(typeId<T>()); verifySchema(Schema::from<T>());
return typename T::Reader(reader); return typename T::Reader(reader);
} }
template <typename T> template <typename T>
typename T::Builder DynamicStruct::Builder::as() { typename T::Builder DynamicStruct::Builder::as() {
static_assert(kind<T>() == Kind::STRUCT, static_assert(kind<T>() == Kind::STRUCT,
"DynamicStruct::Builder::as<T>() can only convert to struct types."); "DynamicStruct::Builder::as<T>() can only convert to struct types.");
verifyTypeId(typeId<T>()); verifySchema(Schema::from<T>());
return typename T::Builder(builder); return typename T::Builder(builder);
} }
......
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