15 #include "flatbuffers.h" 37 static void writeFlatBufferToStream(std::ostream& out, flatbuffers::FlatBufferBuilder& finishedFlatBufferBuilder) {
38 auto flatbufferPointer = finishedFlatBufferBuilder.GetBufferPointer();
39 size_t flatbufferSize = finishedFlatBufferBuilder.GetSize();
40 out.write(reinterpret_cast<char*>(&flatbufferSize),
sizeof(
size_t));
42 reinterpret_cast<char*>(flatbufferPointer),
47 static void readFlatBufferTableFromStream(
49 std::function<
void(
const T&)> tableReader) {
51 in.read(reinterpret_cast<char*>(&bufferSize),
sizeof(
size_t));
53 std::vector<char> buffer(bufferSize);
54 in.read(buffer.data(), bufferSize);
56 flatbuffers::Verifier verifier(reinterpret_cast<uint8_t*>(buffer.data()), bufferSize);
57 if ( ! verifier.VerifyBuffer<T>()) {
58 throw std::runtime_error(
"Streaming FlatBuffer table failed verification");
61 auto table = flatbuffers::GetRoot<T>(buffer.data());
Copyright (c) 2015-present, Facebook, Inc.
Definition: openbwprocess.h:17