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