3 #ifndef GRAIL_BEHAVIOR_DATA_H
4 #define GRAIL_BEHAVIOR_DATA_H
9 #include "Flatbuffers/BehaviorData_generated.h"
10 #include "Flatbuffers/StringStringMap_generated.h"
19 std::map<std::string, std::string> behaviorInstanceData{};
22 inline flatbuffers::Offset<generated::BehaviorData> Pack(flatbuffers::FlatBufferBuilder& builder,
25 std::vector<flatbuffers::Offset<generated::StringStringMap>> packedInstanceData{};
26 packedInstanceData.reserve(behaviorData.behaviorInstanceData.size());
27 std::for_each(behaviorData.behaviorInstanceData.begin(), behaviorData.behaviorInstanceData.end(),
28 [&packedInstanceData, &builder](
const auto& instanceData)
30 packedInstanceData.push_back(generated::CreateStringStringMap(builder,
31 builder.CreateString(instanceData.first), builder.CreateString(instanceData.second)));
33 return generated::CreateBehaviorData(builder, builder.CreateString(behaviorData.name),
34 builder.CreateVector(packedInstanceData));
37 inline BehaviorData Unpack(
const generated::BehaviorData& behaviorData)
39 BehaviorData deserializedData{behaviorData.name()->str()};
40 for(
const auto& instanceData : *behaviorData.behaviorInstanceData())
42 deserializedData.behaviorInstanceData.insert({instanceData->key()->str(), instanceData->value()->str()});
44 return deserializedData;