33 return (a.size() == b.size() && std::strncmp(a.data(), b.data(), a.size()) == 0);
38 const std::string &definition)
39 : _global_warnings(&
std::cerr)
40 , _topic_name(topic_name)
41 , _discard_large_array(DISCARD_LARGE_ARRAYS)
42 , _max_array_size(100)
43 , _blob_policy(STORE_BLOB_AS_COPY)
44 , _dummy_root_field( new
ROSField(msg_type, topic_name) )
67 template <
typename Container>
70 if (container.size() <= new_size)
72 const size_t increased_size = std::max(
size_t(32), container.size() * 2);
73 container.resize(increased_size);
81 deserializer->
init(buffer);
83 bool entire_message_parse =
true;
85 size_t value_index = 0;
86 size_t name_index = 0;
87 size_t blob_index = 0;
88 size_t blob_storage_index = 0;
90 std::function<void(const ROSMessage*, FieldLeaf, bool)> deserializeImpl;
99 bool DO_STORE = store;
100 if (
field.isConstant())
107 auto new_tree_leaf = tree_leaf;
108 new_tree_leaf.node = tree_leaf.node->child(index_s);
110 int32_t array_size =
field.arraySize();
111 if (array_size == -1)
117 new_tree_leaf.index_array.push_back(0);
120 bool IS_BLOB =
false;
136 entire_message_parse =
false;
144 if ( array_size > deserializer->
bytesLeft() )
146 throw std::runtime_error(
"Buffer overrun in deserializeIntoFlatContainer (blob)");
151 auto& blob = flat_container->
blob[blob_index].second;
158 auto& storage = flat_container->
blob_storage[blob_storage_index];
159 storage.resize(array_size);
160 std::memcpy(storage.data(), deserializer->
getCurrentPtr(), array_size);
161 blob_storage_index++;
170 deserializer->
jump( array_size );
174 bool DO_STORE_ARRAY = DO_STORE;
175 for (
int i = 0; i < array_size; i++)
179 DO_STORE_ARRAY =
false;
182 if (
field.isArray() && DO_STORE_ARRAY)
184 new_tree_leaf.index_array.back() = i;
197 flat_container->
name[name_index].second = str;
208 flat_container->
value[value_index] = std::make_pair(new_tree_leaf,
std::move(var));
214 auto msg_node =
field.getMessagePtr(
_schema->msg_library );
215 deserializeImpl(msg_node.get(), new_tree_leaf, DO_STORE_ARRAY);
233 auto root_msg =
_schema->field_tree.croot()->value()->getMessagePtr(
_schema->msg_library );
235 deserializeImpl(root_msg.get(), rootnode,
true);
237 flat_container->
name.resize(name_index);
238 flat_container->
value.resize(value_index);
239 flat_container->
blob.resize(blob_index);
240 flat_container->
blob_storage.resize(blob_storage_index);
242 return entire_message_parse;
std::vector< std::pair< FieldsVector, std::string > > name
List of all those parsed fields that can be represented by a "string".
void ExpandVectorIfNecessary(Container &container, size_t new_size)
BuiltinType typeID() const
If type is builtin, returns the id. BuiltinType::OTHER otherwise.
virtual void jump(size_t bytes)=0
virtual void init(Span< const uint8_t > buffer)
virtual void deserializeString(std::string &out)=0
std::vector< std::pair< FieldsVector, Span< const uint8_t > > > blob
std::shared_ptr< MessageSchema > _schema
bool deserialize(Span< const uint8_t > buffer, FlatMessage *flat_output, Deserializer *deserializer) const
deserializeIntoFlatContainer takes a raw buffer of memory and extract information from it...
std::shared_ptr< ROSMessage > Ptr
const std::vector< ROSField > & fields() const
virtual size_t bytesLeft() const
const FieldTreeNode * node
basic_string_view< char > string_view
ROSMessage::Ptr getMessageByType(const ROSType &type) const
virtual const uint8_t * getCurrentPtr() const =0
A ROSMessage will contain one or more ROSField(s). Each field is little more than a name / type pair...
MessageSchema::Ptr BuildMessageSchema(const std::string &topic_name, const std::vector< ROSMessage::Ptr > &parsed_msgs)
virtual uint32_t deserializeUInt32()=0
const std::shared_ptr< MessageSchema > & getSchema() const
getSchema provides some metadata amout a registered ROSMessage.
std::vector< std::pair< std::string, double > > RenamedValues
virtual Variant deserialize(BuiltinType type)=0
MaxArrayPolicy _discard_large_array
static void field(LexState *ls, ConsControl *cc)
bool isBuiltin() const
True if the type is ROS builtin.
const T & move(const T &v)
std::shared_ptr< MessageSchema > schema
std::vector< std::vector< uint8_t > > blob_storage
int builtinSize(const BuiltinType c)
std::vector< ROSMessage::Ptr > ParseMessageDefinitions(const std::string &multi_def, const ROSType &type)
Parser(const std::string &topic_name, const ROSType &msg_type, const std::string &definition)
std::vector< std::pair< FieldsVector, Variant > > value
The FieldTreeLeaf is, as the name suggests, a leaf (terminal node) of a StringTree. It provides the pointer to the node and a list of numbers that represent the index that corresponds to the placeholder "#".
void CreateRenamedValues(const FlatMessage &flat_msg, RenamedValues &renamed)
bool operator==(const std::string &a, const std::string_view &b)