Add auto_sort parameter for adding message templates, improve error msg

This commit is contained in:
SeanOMik 2020-12-16 00:36:51 -06:00
parent 77b1e05b0a
commit e8d25eeb67
No known key found for this signature in database
GPG Key ID: E5B8A9E070F831BE
3 changed files with 9 additions and 5 deletions

View File

@ -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;

View File

@ -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;
}

View File

@ -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,