3 #ifndef GRAIL_ENTITY_STATE_H
4 #define GRAIL_ENTITY_STATE_H
6 #include "BehaviorData.h"
7 #include "Flatbuffers/EntityState_generated.h"
21 std::map<std::string, std::string> privateBlackboardData{};
22 std::vector<std::string> entityTags{};
26 inline flatbuffers::Offset<generated::EntityState> Pack(flatbuffers::FlatBufferBuilder& builder,
29 std::vector<flatbuffers::Offset<generated::StringStringMap>> packedPrivateBlackboards{};
30 packedPrivateBlackboards.reserve(entityState.privateBlackboardData.size());
31 std::vector<flatbuffers::Offset<flatbuffers::String>> packedTags{};
32 packedTags.reserve(entityState.entityTags.size());
34 std::for_each(entityState.privateBlackboardData.begin(), entityState.privateBlackboardData.end(),
35 [&packedPrivateBlackboards, &builder](
const auto& blackboardData)
37 packedPrivateBlackboards.push_back(generated::CreateStringStringMap(builder,
38 builder.CreateString(blackboardData.first),
39 builder.CreateString(blackboardData.second)));
41 std::for_each(entityState.entityTags.begin(), entityState.entityTags.end(),
42 [&packedTags, &builder](
const auto& entityTag)
44 packedTags.push_back(builder.CreateString(entityTag));
46 return generated::CreateEntityState(builder,
47 builder.CreateString(entityState.name),
49 builder.CreateVector(packedPrivateBlackboards),
50 builder.CreateVector(packedTags),
51 Pack(builder, entityState.currentBehaviorData));
54 inline EntityState Unpack(
const generated::EntityState& entityState)
56 EntityState deserializedState{entityState.name()->str(), entityState.id()};
57 for(
const auto& blackboardData : *entityState.privateBlackboardData())
59 deserializedState.privateBlackboardData.insert({blackboardData->key()->str(), blackboardData->value()->str()});
61 deserializedState.entityTags.reserve(entityState.entityTags()->size());
62 for(
const auto& entityTag : *entityState.entityTags())
64 deserializedState.entityTags.emplace_back(entityTag->str());
66 deserializedState.currentBehaviorData = Unpack(*entityState.currentBehaviorData());
67 return deserializedState;