diff --git a/include/ki/protocol/dml/MessageModule.h b/include/ki/protocol/dml/MessageModule.h index 4e0c220..6a802db 100644 --- a/include/ki/protocol/dml/MessageModule.h +++ b/include/ki/protocol/dml/MessageModule.h @@ -27,7 +27,7 @@ namespace dml std::string get_protocol_desription() const; void set_protocol_description(std::string protocol_description); - void add_message_template(MessageTemplate *message_template); + void add_message_template(MessageTemplate *message_template, bool auto_sort = false); const MessageTemplate *add_message_template(std::string name, ki::dml::Record *record, bool auto_sort = true); const MessageTemplate *get_message_template(uint8_t type) const; diff --git a/src/protocol/dml/MessageManager.cpp b/src/protocol/dml/MessageManager.cpp index 7689bb1..53953d9 100644 --- a/src/protocol/dml/MessageManager.cpp +++ b/src/protocol/dml/MessageManager.cpp @@ -234,7 +234,7 @@ namespace dml if (!message_template) { std::ostringstream oss; - oss << "No message exists with type: " << (uint16_t)header.get_service_id(); + oss << "No message exists with type: " << (uint16_t)header.get_type(); oss << "(service=" << message_module->get_protocol_type() << ")"; throw value_error(oss.str(), value_error::DML_INVALID_MESSAGE_TYPE); } @@ -259,7 +259,7 @@ namespace dml catch (ki::dml::parse_error &e) { delete message; - throw parse_error("Failed to read DML message payload.", parse_error::INVALID_MESSAGE_DATA); + throw parse_error("Failed to read DML message payload. (" + std::string(e.what()) + ")", parse_error::INVALID_MESSAGE_DATA); } return message; } diff --git a/src/protocol/dml/MessageModule.cpp b/src/protocol/dml/MessageModule.cpp index aa159ce..017c19c 100644 --- a/src/protocol/dml/MessageModule.cpp +++ b/src/protocol/dml/MessageModule.cpp @@ -55,10 +55,14 @@ namespace dml m_protocol_description = protocol_description; } - void MessageModule::add_message_template(MessageTemplate *message_template) { + void MessageModule::add_message_template(MessageTemplate *message_template, bool auto_sort) { m_templates.push_back(message_template); m_message_name_map.emplace(message_template->get_name(), message_template); m_message_type_map.emplace(message_template->get_type(), message_template); + + if (auto_sort) { + sort_lookup(); + } } const MessageTemplate *MessageModule::add_message_template(std::string name, @@ -128,7 +132,7 @@ namespace dml // First, clear the message type map since we're going to be // moving everything around m_message_type_map.clear(); - + // Iterating over a map with std::string as the key // is guaranteed to be in alphabetical order for (auto it = m_message_name_map.begin();