Files
IM/MP/Response.cpp
2023-05-04 12:55:59 +08:00

53 lines
1.3 KiB
C++

//
// Created by dongl on 23-4-21.
//
#include "Response.h"
Response::Response(mp::MP_TYPE type, mp::MP_SRI code, const std::string &username, const std::string &msg, const std::string &token) :
Mph(type),
Sri(code, username, msg, token) {
}
Response::~Response() {
delete response;
}
void Response::init() {
memset(temp, 0 , 256);
response = new mp::response();
response->set_allocated_sri(sri);
mph->set_mpb_size( response->ByteSizeLong());
}
std::string Response::operator()() {
init();
std::string temp_mph;
std::string temp_request;
mph->SerializeToString(&temp_mph);
response->SerializeToString(&temp_request);
uint8_t size = mph->ByteSizeLong();
sprintf(temp, "%c", size);
sprintf(temp, "%s%s%s", temp, temp_mph.c_str(), temp_request.c_str());
// time: 0426 19:54 debug return 这里反复执行 然后temp 字符串就乱了 变了 ? 原因不明确
return temp;
}
std::string Response::packet () {
init();
std::string temp_mph;
std::string temp_request;
mph->SerializeToString(&temp_mph);
response->SerializeToString(&temp_request);
uint8_t size = mph->ByteSizeLong();
sprintf(temp, "%c", size);
sprintf(temp, "%s%s%s", temp, temp_mph.c_str(), temp_request.c_str());
return temp;
}