11 #ifndef CUBBYFLOW_FLATBUFFERS_HELPER_HPP 12 #define CUBBYFLOW_FLATBUFFERS_HELPER_HPP 16 #include <Flatbuffers/generated/BasicTypes_generated.h> 47 return Vector3UZ{ { vec.x(), vec.y(), vec.z() } };
57 return Vector3D{ vec.x(), vec.y(), vec.z() };
60 template <
typename Gr
idType,
typename FbsFactoryFunc,
typename FbsGr
idType>
62 const std::vector<GridType>& gridList, FbsFactoryFunc func,
63 std::vector<flatbuffers::Offset<FbsGridType>>* fbsGridList)
65 for (
const auto& grid : gridList)
67 auto type = builder->CreateString(grid->TypeName());
69 std::vector<uint8_t> gridSerialized;
70 grid->Serialize(&gridSerialized);
72 auto fbsGrid = func(*builder, type,
73 builder->CreateVector(gridSerialized.data(),
74 gridSerialized.size()));
75 fbsGridList->push_back(fbsGrid);
79 template <
typename FbsGr
idList,
typename Gr
idType,
typename FactoryFunc>
81 std::vector<GridType>* gridList)
83 for (
const auto grid : *fbsGridList)
85 auto type = grid->type()->c_str();
87 std::vector<uint8_t> gridSerialized(grid->data()->begin(),
90 auto newGrid = factoryFunc(type);
91 newGrid->Deserialize(gridSerialized);
93 gridList->push_back(newGrid);
void DeserializeGrid(FbsGridList *fbsGridList, FactoryFunc factoryFunc, std::vector< GridType > *gridList)
Definition: FlatbuffersHelper.hpp:80
Vector2< size_t > Vector2UZ
Definition: Matrix.hpp:776
Vector2UZ FlatbuffersToCubbyFlow(const fbs::Vector2UZ &vec)
Definition: FlatbuffersHelper.hpp:40
void SerializeGrid(flatbuffers::FlatBufferBuilder *builder, const std::vector< GridType > &gridList, FbsFactoryFunc func, std::vector< flatbuffers::Offset< FbsGridType >> *fbsGridList)
Definition: FlatbuffersHelper.hpp:61
Definition: Matrix.hpp:27
Definition: pybind11Utils.hpp:20
Vector2< double > Vector2D
Definition: Matrix.hpp:774
Vector3< size_t > Vector3UZ
Definition: Matrix.hpp:789
fbs::Vector2UZ CubbyFlowToFlatbuffers(const Vector2UZ &vec)
Definition: FlatbuffersHelper.hpp:20
Vector3< double > Vector3D
Definition: Matrix.hpp:787