diff options
Diffstat (limited to 'src/messageparser.cc')
-rw-r--r-- | src/messageparser.cc | 39 |
1 files changed, 33 insertions, 6 deletions
diff --git a/src/messageparser.cc b/src/messageparser.cc index 1b5fd7f..0f1844e 100644 --- a/src/messageparser.cc +++ b/src/messageparser.cc @@ -332,8 +332,9 @@ MessageList parse_msg_client(std::string data) return msgList; } -std::string msg_tostring(message_t m) +std::vector<std::string> msg_tostring(message_t m) { + std::vector<std::string> msgs; std::string msg; switch(m.cmd) @@ -342,27 +343,45 @@ std::string msg_tostring(message_t m) msg = "create " + std::to_string(m.create.id) + " " + std::to_string(m.create.parentid) + " " + - std::to_string(m.create.insertbeforeid); + std::to_string(m.create.insertbeforeid) + ";"; + msgs.push_back(msg); + break; + case cmd::create_with_attributes: + msg = "create " + + std::to_string(m.create.id) + " " + + std::to_string(m.create.parentid) + " " + + std::to_string(m.create.insertbeforeid) + ";"; + msgs.push_back(msg); + for(const auto& attribute : m.attributes) + { + msg = "update " + + std::to_string(m.create.id) + " \"" + + attribute.first + "\" \"" + attribute.second + "\";"; + msgs.push_back(msg); + } break; case cmd::remove: - msg = "remove " + std::to_string(m.remove.id); + msg = "remove " + std::to_string(m.remove.id) + ";"; + msgs.push_back(msg); break; case cmd::move: msg = "move " + std::to_string(m.move.id) + " " + std::to_string(m.move.parentid) + " " + - std::to_string(m.move.insertbeforeid); + std::to_string(m.move.insertbeforeid) + ";"; + msgs.push_back(msg); break; case cmd::update: msg = "update " + std::to_string(m.update.id) + " \"" + - m.update.attribute + "\" \"" + m.update.value + "\""; + m.update.attribute + "\" \"" + m.update.value + "\";"; + msgs.push_back(msg); break; default: break; } - return msg + ";"; + return msgs; } message_t create_msg_create(node_t t, nodeid_t insertbeforeid) @@ -375,6 +394,14 @@ message_t create_msg_create(node_t t, nodeid_t insertbeforeid) return m; } +message_t create_msg_create_with_attributes(node_t node, + nodeid_t insertbeforeid) +{ + auto msg = create_msg_create(node, insertbeforeid); + msg.cmd = cmd::create_with_attributes; + return msg; +} + message_t create_msg_update(node_t t, const std::string &attr) { message_t m; |