mirror of https://github.com/SeanOMik/libki.git
Add auto_sort parameter for adding message templates, improve error msg
This commit is contained in:
parent
77b1e05b0a
commit
e8d25eeb67
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue