IM/MP/IMDataPacket.cpp

60 lines
1.5 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// Created by dongl on 23-6-20.
//
#include "IMDataPacket.h"
IMDataPacket::IMDataPacket(mp::MP_TYPE type, mp::im::msg_data* data) :
Mph(type),
MsgData(data) {
}
IMDataPacket::IMDataPacket(mp::MP_TYPE type, mp::MP_SUB_TYPE subType,
mp::MP_SUB_TYPE sessionType, uint64_t messageId,
time_t time, uint64_t account, std::string &imMsgData) :
Mph(type),
MsgData(subType, sessionType,messageId, time, account,imMsgData) {
}
IMDataPacket::IMDataPacket(mp::MP_TYPE type, mp::MP_SUB_TYPE subType,
uint64_t messageId, time_t time) :
Mph(type),
MsgData(subType, messageId, time) {
}
std::string IMDataPacket::packet() {
// 包体长度
mph->set_mpb_size(data->ByteSizeLong());
// im_data_packet 的 L 为 16bit
std::string temp;
// 判断是否超过数据包限制大小 一个包 大概0.06MB
if (mph->ByteSizeLong() + data->ByteSizeLong() > 65535) {
return "超过数据包限制大小无法构造长度请低于65535 或者分包";
}
// L
// temp.push_back(mph->ByteSizeLong());
if (mph->ByteSizeLong() + data->ByteSizeLong() <= 255) {
temp.push_back(0);
temp.push_back(mph->ByteSizeLong());
} else {
short len = mph->ByteSizeLong() + data->ByteSizeLong();
char LTV_L[2];
memcpy(LTV_L, &len, sizeof(LTV_L));
temp.append(LTV_L);
}
// T
mph->AppendToString(&temp);
// V
data->AppendToString(&temp);
return temp;
}