template<typename T> T GetFieldI(const Table *table,
const reflection::Field *field) {
assert(sizeof(T) == GetTypeSize(field->type()->base_type()));
- return table->GetField<T>(field->offset(), field->default_integer());
+ return table->GetField<T>(field->offset(),
+ static_cast<T>(field->default_integer()));
}
// Get a field, if you know it's floating point and its exact type.
template<typename T> T GetFieldF(const Table *table,
const reflection::Field *field) {
assert(sizeof(T) == GetTypeSize(field->type()->base_type()));
- return table->GetField<T>(field->offset(), field->default_real());
+ return table->GetField<T>(field->offset(),
+ static_cast<T>(field->default_real()));
}
// Get a field, if you know it's a string.
case reflection::Double: return GetFieldF<double>(table, field);
case reflection::String: return strtod(GetFieldS(table, field)->c_str(),
nullptr);
- default: return GetAnyFieldI(table, field);
+ default: return static_cast<double>(GetAnyFieldI(table, field));
}
}
const T *operator->() const {
return operator*();
}
+ void operator=(const pointer_inside_vector &piv);
private:
size_t offset_;
const std::vector<U> &vec_;
if (!delta_) return; // We can't shrink by less than largest_scalar_t.
// Now change all the offsets by delta_.
auto root = GetAnyRoot(buf_.data());
- Straddle<uoffset_t>(buf_.data(), root, buf_.data());
+ Straddle<uoffset_t, 1>(buf_.data(), root, buf_.data());
ResizeTable(schema.root_table(), root);
// We can now add or remove bytes at start.
if (delta_ > 0) buf_.insert(buf_.begin() + start, delta_, 0);
// Check if the range between first (lower address) and second straddles
// the insertion point. If it does, change the offset at offsetloc (of
// type T, with direction D).
- template<typename T, int D = 1> void Straddle(void *first, void *second,
- void *offsetloc) {
+ template<typename T, int D> void Straddle(void *first, void *second,
+ void *offsetloc) {
if (first <= startptr_ && second >= startptr_) {
WriteScalar<T>(offsetloc, ReadScalar<T>(offsetloc) + delta_ * D);
DagCheck(offsetloc) = true;
if (DagCheck(offsetloc))
continue; // This offset already visited.
auto ref = offsetloc + ReadScalar<uoffset_t>(offsetloc);
- Straddle<uoffset_t>(offsetloc, ref, offsetloc);
+ Straddle<uoffset_t, 1>(offsetloc, ref, offsetloc);
// Recurse.
switch (base_type) {
case reflection::Obj: {
if (DagCheck(loc))
continue; // This offset already visited.
auto dest = loc + vec->Get(i);
- Straddle<uoffset_t>(loc, dest ,loc);
+ Straddle<uoffset_t, 1>(loc, dest ,loc);
ResizeTable(elemobjectdef, reinterpret_cast<Table *>(dest));
}
break;
}
}
+ void operator=(const ResizeContext &rc);
+
private:
const reflection::Schema &schema_;
uint8_t *startptr_;
uoffset_t newsize, T val,
const Vector<T> *vec,
std::vector<uint8_t> *flatbuf) {
- auto delta_elem = newsize - static_cast<int>(vec->size());
+ auto delta_elem = static_cast<int>(newsize) - static_cast<int>(vec->size());
auto delta_bytes = delta_elem * static_cast<int>(sizeof(T));
auto vec_start = reinterpret_cast<const uint8_t *>(vec) - flatbuf->data();
auto start = static_cast<uoffset_t>(vec_start + sizeof(uoffset_t) +
// Set new elements to "val".
for (int i = 0; i < delta_elem; i++) {
auto loc = flatbuf->data() + start + i * sizeof(T);
- if (std::is_scalar<T>::value) {
+ auto is_scalar = std::is_scalar<T>::value;
+ if (is_scalar) {
WriteScalar(loc, val);
} else { // struct
*reinterpret_cast<T *>(loc) = val;
// The enums in the reflection schema should match the ones we use internally.
// Compare the last element to check if these go out of sync.
static_assert(BASE_TYPE_UNION ==
- static_cast<BaseType>(reflection::BaseType::Union),
+ static_cast<BaseType>(reflection::Union),
"enums don't match");
static void Error(const std::string &msg) {
const {
std::vector<Offset<reflection::Field>> field_offsets;
for (auto it = fields.vec.begin(); it != fields.vec.end(); ++it) {
- field_offsets.push_back((*it)->Serialize(builder, it - fields.vec.begin()));
+ field_offsets.push_back(
+ (*it)->Serialize(builder,
+ static_cast<uint16_t>(it - fields.vec.begin())));
}
return reflection::CreateObject(*builder,
builder->CreateString(name),
* limitations under the License.
*/
+#define FLATBUFFERS_DEBUG_VERIFICATION_FAILURE 1
+
#include "flatbuffers/flatbuffers.h"
#include "flatbuffers/idl.h"
#include "flatbuffers/util.h"
// Load a binary schema.
std::string bfbsfile;
TEST_EQ(flatbuffers::LoadFile(
- "tests/monster_test.bfbs", false, &bfbsfile), true);
+ "tests/monster_test.bfbs", true, &bfbsfile), true);
+
+ // Verify it, just in case:
+ flatbuffers::Verifier verifier(
+ reinterpret_cast<const uint8_t *>(bfbsfile.c_str()), bfbsfile.length());
+ TEST_EQ(reflection::VerifySchemaBuffer(verifier), true);
// Make sure the schema is what we expect it to be.
auto schema = reflection::GetSchema(bfbsfile.c_str());