1 #ifndef BT_FLATBUFFER_HELPER_H 2 #define BT_FLATBUFFER_HELPER_H 64 std::vector<flatbuffers::Offset<Serialization::TreeNode>> fb_nodes;
67 std::vector<uint16_t> children_uid;
68 if (
auto control = dynamic_cast<BT::ControlNode*>(node))
70 children_uid.reserve(control->children().size());
71 for (
const auto& child : control->children())
73 children_uid.push_back(child->UID());
76 else if (
auto decorator = dynamic_cast<BT::DecoratorNode*>(node))
78 const auto& child = decorator->child();
79 children_uid.push_back(child->UID());
82 std::vector<flatbuffers::Offset<Serialization::PortConfig>> ports;
83 for (
const auto& it : node->config().input_ports)
88 for (
const auto& it : node->config().output_ports)
95 builder, node->UID(), builder.
CreateVector(children_uid),
100 fb_nodes.push_back(tn);
103 std::vector<flatbuffers::Offset<Serialization::NodeModel>> node_models;
105 for (
const auto& node_it : tree.
manifests)
107 const auto&
manifest = node_it.second;
108 std::vector<flatbuffers::Offset<Serialization::PortModel>> port_models;
110 for (
const auto& port_it :
manifest.ports)
112 const auto& port_name = port_it.first;
113 const auto& port = port_it.second;
119 port_models.push_back(port_model);
126 node_models.push_back(node_model);
133 builder.
Finish(behavior_tree);
143 SerializedTransition
buffer;
144 int64_t usec = duration_cast<microseconds>(timestamp).
count();
145 int64_t t_sec = usec / 1000000;
146 int64_t t_usec = usec % 1000000;
148 flatbuffers::WriteScalar(&buffer[0], t_sec);
149 flatbuffers::WriteScalar(&buffer[4], t_usec);
150 flatbuffers::WriteScalar(&buffer[8], UID);
152 flatbuffers::WriteScalar(&buffer[10],
154 flatbuffers::WriteScalar(&buffer[11],
162 #endif // BT_FLATBUFFER_HELPER_H
flatbuffers::Offset< PortModel > CreatePortModel(flatbuffers::FlatBufferBuilder &_fbb, flatbuffers::Offset< flatbuffers::String > port_name=0, Serialization::PortDirection direction=Serialization::PortDirection::INPUT, flatbuffers::Offset< flatbuffers::String > type_info=0, flatbuffers::Offset< flatbuffers::String > description=0)
static raw_event_t * buffer
void Finish(Offset< T > root, const char *file_identifier=nullptr)
Finish serializing a buffer by writing the root offset.
Offset< String > CreateString(const char *str, size_t len)
Store a string in the buffer, which can contain any binary data.
void CreateFlatbuffersBehaviorTree(flatbuffers::FlatBufferBuilder &builder, const BT::Tree &tree)
std::array< uint8_t, 12 > SerializedTransition
TreeNode * rootNode() const
Helper class to hold data needed in creation of a FlatBuffer. To serialize data, you typically call o...
Serialization::NodeType convertToFlatbuffers(BT::NodeType type)
std::string demangle(char const *name)
flatbuffers::Offset< TreeNode > CreateTreeNode(flatbuffers::FlatBufferBuilder &_fbb, uint16_t uid=0, flatbuffers::Offset< flatbuffers::Vector< uint16_t >> children_uid=0, Serialization::NodeStatus status=Serialization::NodeStatus::IDLE, flatbuffers::Offset< flatbuffers::String > instance_name=0, flatbuffers::Offset< flatbuffers::String > registration_name=0, flatbuffers::Offset< flatbuffers::Vector< flatbuffers::Offset< Serialization::PortConfig >>> port_remaps=0)
flatbuffers::Offset< BehaviorTree > CreateBehaviorTree(flatbuffers::FlatBufferBuilder &_fbb, uint16_t root_uid=0, flatbuffers::Offset< flatbuffers::Vector< flatbuffers::Offset< Serialization::TreeNode >>> nodes=0, flatbuffers::Offset< flatbuffers::Vector< flatbuffers::Offset< Serialization::NodeModel >>> node_models=0)
Struct used to store a tree. If this object goes out of scope, the tree is destroyed.
Abstract base class for Behavior Tree Nodes.
Offset< Vector< T > > CreateVector(const T *v, size_t len)
Serialize an array into a FlatBuffer vector.
static volatile int count
std::unordered_map< std::string, TreeNodeManifest > manifests
flatbuffers::Offset< NodeModel > CreateNodeModel(flatbuffers::FlatBufferBuilder &_fbb, flatbuffers::Offset< flatbuffers::String > registration_name=0, Serialization::NodeType type=Serialization::NodeType::UNDEFINED, flatbuffers::Offset< flatbuffers::Vector< flatbuffers::Offset< Serialization::PortModel >>> ports=0)
NodeType
Enumerates the possible types of nodes.
std::chrono::high_resolution_clock::duration Duration
void applyRecursiveVisitor(const TreeNode *root_node, const std::function< void(const TreeNode *)> &visitor)
flatbuffers::Offset< PortConfig > CreatePortConfigDirect(flatbuffers::FlatBufferBuilder &_fbb, const char *port_name=nullptr, const char *remap=nullptr)
SerializedTransition SerializeTransition(uint16_t UID, Duration timestamp, NodeStatus prev_status, NodeStatus status)