9 #ifndef CUBBYFLOW_FLATBUFFERS_HELPER_H 10 #define CUBBYFLOW_FLATBUFFERS_HELPER_H 17 #include <Flatbuffers/generated/BasicTypes_generated.h> 43 return Size2({ vec.x(), vec.y() });
48 return Size3({ vec.x(), vec.y(), vec.z() });
58 return Vector3D(vec.x(), vec.y(), vec.z());
61 template <
typename Gr
idType,
typename FbsFactoryFunc,
typename FbsGr
idType>
62 void SerializeGrid(flatbuffers::FlatBufferBuilder* builder,
const std::vector<GridType>& gridList, FbsFactoryFunc func, std::vector<flatbuffers::Offset<FbsGridType>>* fbsGridList)
64 for (
const auto& grid : gridList)
66 auto type = builder->CreateString(grid->TypeName());
68 std::vector<uint8_t> gridSerialized;
69 grid->Serialize(&gridSerialized);
71 auto fbsGrid = func(*builder, type, builder->CreateVector(gridSerialized.data(), gridSerialized.size()));
72 fbsGridList->push_back(fbsGrid);
76 template <
typename FbsGr
idList,
typename Gr
idType,
typename FactoryFunc>
77 void DeserializeGrid(FbsGridList* fbsGridList, FactoryFunc factoryFunc, std::vector<GridType>* gridList)
79 for (
const auto& grid : (*fbsGridList))
81 auto type = grid->type()->c_str();
83 std::vector<uint8_t> gridSerialized(grid->data()->begin(), grid->data()->end());
85 auto newGrid = factoryFunc(type);
86 newGrid->Deserialize(gridSerialized);
88 gridList->push_back(newGrid);
3-D vector class.
Definition: Vector3.h:26
T x
X (or the first) component of the vector.
Definition: Vector2.h:29
T z
Z (or the third) component of the vector.
Definition: Vector3.h:38
void DeserializeGrid(FbsGridList *fbsGridList, FactoryFunc factoryFunc, std::vector< GridType > *gridList)
Definition: FlatbuffersHelper.h:77
T x
X (or the first) component of the point.
Definition: Point2.h:28
fbs::Size2 CubbyFlowToFlatbuffers(const Size2 &vec)
Definition: FlatbuffersHelper.h:21
2-D point class.
Definition: Point2.h:25
3-D point class.
Definition: Point3.h:26
void SerializeGrid(flatbuffers::FlatBufferBuilder *builder, const std::vector< GridType > &gridList, FbsFactoryFunc func, std::vector< flatbuffers::Offset< FbsGridType >> *fbsGridList)
Definition: FlatbuffersHelper.h:62
Point2< size_t > Size2
Definition: Size2.h:16
T y
Y (or the second) component of the point.
Definition: Point2.h:34
T x
X (or the first) component of the vector.
Definition: Vector3.h:29
Definition: pybind11Utils.h:24
Vector2< double > Vector2D
Double-type 2D vector.
Definition: Vector2.h:341
T z
Z (or the third) component of the point.
Definition: Point3.h:38
T y
Y (or the second) component of the point.
Definition: Point3.h:35
T y
Y (or the second) component of the vector.
Definition: Vector2.h:35
T x
X (or the first) component of the point.
Definition: Point3.h:29
2-D vector class.
Definition: Vector2.h:26
Size2 FlatbuffersToCubbyFlow(const fbs::Size2 &vec)
Definition: FlatbuffersHelper.h:41
T y
Y (or the second) component of the vector.
Definition: Vector3.h:35
Point3< size_t > Size3
Definition: Size3.h:16
Vector3< double > Vector3D
Double-type 3D vector.
Definition: Vector3.h:353