Changeset 6 in chevmsgr for trunk/msg.cpp
- Timestamp:
- 08/29/15 02:20:50 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/msg.cpp
r5 r6 5 5 makeTemplate(_obj, _type); \ 6 6 7 namespace Message 7 #define DELIMITER "$" 8 9 namespace Protocol 8 10 { 9 11 // parser 10 void Parser::parse(const std::string & message)12 void Message::parse(const std::string & message) 11 13 { 12 14 mObject = json::Deserialize(message); 13 15 } 14 16 15 std::string Parser::type() const17 std::string Message::type() const 16 18 { 17 19 return get<std::string>("type"); … … 31 33 void Request::makeTemplate(json::Object & obj, const std::string & type) const 32 34 { 33 obj["id"] = mID; 34 obj["type"] = type; 35 } 36 37 std::string Request::command(const std::string & cmd) const 38 { 39 DECLARE_TEMPLATE_OBJECT(obj, "command"); 40 41 obj["command"] = cmd; 42 43 return json::Serialize(obj); 35 obj[ProtocolType::ID ] = mID; 36 obj[ProtocolType::TYPE] = type; 44 37 } 45 38 46 39 std::string Request::sms(const std::string & phone) const 47 40 { 48 DECLARE_TEMPLATE_OBJECT(obj, "sms");41 DECLARE_TEMPLATE_OBJECT(obj, ProtocolType::SMS); 49 42 50 obj[ "phone"] = phone;43 obj[ProtocolType::PHONE] = phone; 51 44 52 45 return json::Serialize(obj); … … 55 48 std::string Request::join(const std::string & id, const std::string & pw, const std::string & sms) 56 49 { 57 DECLARE_TEMPLATE_OBJECT(obj, "join");50 DECLARE_TEMPLATE_OBJECT(obj, ProtocolType::JOIN); 58 51 59 obj[ "id"] = id;60 obj[ "pw"] = pw;61 obj[ "sms"] = sms;52 obj[ProtocolType::ID ] = id; 53 obj[ProtocolType::PW ] = pw; 54 obj[ProtocolType::SMS] = sms; 62 55 63 56 return json::Serialize(obj); … … 66 59 std::string Request::login(const std::string & pw) const 67 60 { 68 DECLARE_TEMPLATE_OBJECT(obj, "login");61 DECLARE_TEMPLATE_OBJECT(obj, ProtocolType::LOGIN); 69 62 70 obj[ "pw"] = mID + "$"+ pw;63 obj[ProtocolType::PW] = mID + DELIMITER + pw; 71 64 72 65 return json::Serialize(obj); 73 66 } 74 67 75 std::string Request:: chat(const std::string & to, const std::string & sessid, const std::string & message) const68 std::string Request::addFriend(const std::string & id) const 76 69 { 77 DECLARE_TEMPLATE_OBJECT(obj, "chat");70 DECLARE_TEMPLATE_OBJECT(obj, ProtocolType::ADD_FRIEND); 78 71 79 obj["from" ] = mID; 80 obj["to" ] = to; 81 obj["sess-id"] = sessid; 82 obj["message"] = message; 72 obj[ProtocolType::ID] = id; 83 73 84 74 return json::Serialize(obj); 85 75 } 86 76 87 std::string Request:: friendList() const77 std::string Request::openSession(const std::string & to) const 88 78 { 89 DECLARE_TEMPLATE_OBJECT(obj, "friend-list"); 79 DECLARE_TEMPLATE_OBJECT(obj, ProtocolType::OPEN_SESSION); 80 81 obj[ProtocolType::TO] = to; 82 83 return json::Serialize(obj); 84 } 85 86 std::string Request::chat(const std::string & sessid, const std::string & message, const int sensitive) const 87 { 88 DECLARE_TEMPLATE_OBJECT(obj, ProtocolType::CHAT); 89 90 obj[ProtocolType::FROM ] = mID; 91 obj[ProtocolType::SESSION_ID] = sessid; 92 obj[ProtocolType::MESSAGE ] = message; 93 obj[ProtocolType::SENSITIVE ] = sensitive; 94 95 return json::Serialize(obj); 96 } 97 98 std::string Request::getFriendList() const 99 { 100 DECLARE_TEMPLATE_OBJECT(obj, ProtocolType::GET_FRIEND_LIST); 90 101 91 102 return json::Serialize(obj); … … 95 106 void Response::makeTemplate(json::Object & obj, const std::string & type) const 96 107 { 97 obj[ "type"] = type;108 obj[ProtocolType::TYPE] = type; 98 109 } 99 110 100 std::string Response::result(const bool status) const111 std::string Response::result(const std::string & requestType, const bool status) const 101 112 { 102 DECLARE_TEMPLATE_OBJECT(obj, "result");113 DECLARE_TEMPLATE_OBJECT(obj, ProtocolType::RESULT); 103 114 104 obj[ "result"] = status;115 obj[ProtocolType::RESULT] = status; 105 116 106 117 return json::Serialize(obj);
Note:
See TracChangeset
for help on using the changeset viewer.