本文整理汇总了C++中CImPdu::GetBodyLength方法的典型用法代码示例。如果您正苦于以下问题:C++ CImPdu::GetBodyLength方法的具体用法?C++ CImPdu::GetBodyLength怎么用?C++ CImPdu::GetBodyLength使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CImPdu
的用法示例。
在下文中一共展示了CImPdu::GetBodyLength方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: HandleGroupInfoResponse
void CGroupChat::HandleGroupInfoResponse(CImPdu* pPdu)
{
IM::Group::IMGroupInfoListRsp msg;
CHECK_PB_PARSE_MSG(msg.ParseFromArray(pPdu->GetBodyData(), pPdu->GetBodyLength()));
uint32_t user_id = msg.user_id();
uint32_t group_cnt = msg.group_info_list_size();
CPduAttachData pduAttachData((uchar_t*)msg.attach_data().c_str(), msg.attach_data().length());
log("HandleGroupInfoResponse, user_id=%u, group_cnt=%u. ", user_id, group_cnt);
//此处是查询成员时使用,主要用于群消息从数据库获得msg_id后进行发送,一般此时group_cnt = 1
if (pduAttachData.GetPduLength() > 0 && group_cnt > 0)
{
IM::BaseDefine::GroupInfo group_info = msg.group_info_list(0);
uint32_t group_id = group_info.group_id();
log("GroupInfoRequest is send by server, group_id=%u ", group_id);
std::set<uint32_t> group_member_set;
for (uint32_t i = 0; i < group_info.group_member_list_size(); i++)
{
uint32_t member_user_id = group_info.group_member_list(i);
group_member_set.insert(member_user_id);
}
if (group_member_set.find(user_id) == group_member_set.end())
{
log("user_id=%u is not in group, group_id=%u. ", user_id, group_id);
return;
}
IM::Message::IMMsgData msg2;
CHECK_PB_PARSE_MSG(msg2.ParseFromArray(pduAttachData.GetPdu(), pduAttachData.GetPduLength()));
CImPdu pdu;
pdu.SetPBMsg(&msg2);
pdu.SetServiceId(SID_MSG);
pdu.SetCommandId(CID_MSG_DATA);
//Push相关
IM::Server::IMGroupGetShieldReq msg3;
msg3.set_group_id(group_id);
msg3.set_attach_data(pdu.GetBodyData(), pdu.GetBodyLength());
for (uint32_t i = 0; i < group_info.group_member_list_size(); i++)
{
uint32_t member_user_id = group_info.group_member_list(i);
msg3.add_user_id(member_user_id);
CImUser* pToImUser = CImUserManager::GetInstance()->GetImUserById(member_user_id);
if (pToImUser)
{
CMsgConn* pFromConn = NULL;
if( member_user_id == user_id )
{
uint32_t reqHandle = pduAttachData.GetHandle();
if(reqHandle != 0)
pFromConn = CImUserManager::GetInstance()->GetMsgConnByHandle(user_id, reqHandle);
}
pToImUser->BroadcastData(pdu.GetBuffer(), pdu.GetLength(), pFromConn);
}
}
CImPdu pdu2;
pdu2.SetPBMsg(&msg3);
pdu2.SetServiceId(SID_OTHER);
pdu2.SetCommandId(CID_OTHER_GET_SHIELD_REQ);
CDBServConn* pDbConn = get_db_serv_conn();
if (pDbConn)
{
pDbConn->SendPdu(&pdu2);
}
}
else if (pduAttachData.GetPduLength() == 0)
{
//正常获取群信息的返回
CMsgConn* pConn = CImUserManager::GetInstance()->GetMsgConnByHandle(user_id, pduAttachData.GetHandle());
if (pConn)
{
msg.clear_attach_data();
pPdu->SetPBMsg(&msg);
pConn->SendPdu(pPdu);
}
}
}
示例2: _HandleGetDeviceTokenResponse
void CDBServConn::_HandleGetDeviceTokenResponse(CImPdu *pPdu)
{
IM::Server::IMGetDeviceTokenRsp msg;
CHECK_PB_PARSE_MSG(msg.ParseFromArray(pPdu->GetBodyData(), pPdu->GetBodyLength()));
IM::Message::IMMsgData msg2;
CHECK_PB_PARSE_MSG(msg2.ParseFromArray(msg.attach_data().c_str(), msg.attach_data().length()));
string msg_data = msg2.msg_data();
uint32_t msg_type = msg2.msg_type();
uint32_t from_id = msg2.from_user_id();
uint32_t to_id = msg2.to_session_id();
if (msg_type == IM::BaseDefine::MSG_TYPE_SINGLE_TEXT || msg_type == IM::BaseDefine::MSG_TYPE_GROUP_TEXT)
{
//msg_data =
char* msg_out = NULL;
uint32_t msg_out_len = 0;
if (pAes->Decrypt(msg_data.c_str(), msg_data.length(), &msg_out, msg_out_len) == 0)
{
msg_data = string(msg_out, msg_out_len);
}
else
{
log("HandleGetDeviceTokenResponse, decrypt msg failed, from_id: %u, to_id: %u, msg_type: %u.", from_id, to_id, msg_type);
return;
}
pAes->Free(msg_out);
}
build_ios_push_flash(msg_data, msg2.msg_type(), from_id);
//{
// "msg_type": 1,
// "from_id": "1345232",
// "group_type": "12353",
//}
jsonxx::Object json_obj;
json_obj << "msg_type" << (uint32_t)msg2.msg_type();
json_obj << "from_id" << from_id;
if (CHECK_MSG_TYPE_GROUP(msg2.msg_type())) {
json_obj << "group_id" << to_id;
}
uint32_t user_token_cnt = msg.user_token_info_size();
log("HandleGetDeviceTokenResponse, user_token_cnt = %u.", user_token_cnt);
IM::Server::IMPushToUserReq msg3;
for (uint32_t i = 0; i < user_token_cnt; i++)
{
IM::BaseDefine::UserTokenInfo user_token = msg.user_token_info(i);
uint32_t user_id = user_token.user_id();
string device_token = user_token.token();
uint32_t push_cnt = user_token.push_count();
uint32_t client_type = user_token.user_type();
//自己发得消息不给自己发推送
if (from_id == user_id) {
continue;
}
log("HandleGetDeviceTokenResponse, user_id = %u, device_token = %s, push_cnt = %u, client_type = %u.",
user_id, device_token.c_str(), push_cnt, client_type);
CImUser* pUser = CImUserManager::GetInstance()->GetImUserById(user_id);
if (pUser)
{
msg3.set_flash(msg_data);
msg3.set_data(json_obj.json());
IM::BaseDefine::UserTokenInfo* user_token_tmp = msg3.add_user_token_list();
user_token_tmp->set_user_id(user_id);
user_token_tmp->set_user_type((IM::BaseDefine::ClientType)client_type);
user_token_tmp->set_token(device_token);
user_token_tmp->set_push_count(push_cnt);
//pc client登录,则为勿打扰式推送
if (pUser->GetPCLoginStatus() == IM_PC_LOGIN_STATUS_ON)
{
user_token_tmp->set_push_type(IM_PUSH_TYPE_SILENT);
log("HandleGetDeviceTokenResponse, user id: %d, push type: silent.", user_id);
}
else
{
user_token_tmp->set_push_type(IM_PUSH_TYPE_NORMAL);
log("HandleGetDeviceTokenResponse, user id: %d, push type: normal.", user_id);
}
}
else
{
IM::Server::IMPushToUserReq msg4;
msg4.set_flash(msg_data);
msg4.set_data(json_obj.json());
IM::BaseDefine::UserTokenInfo* user_token_tmp = msg4.add_user_token_list();
user_token_tmp->set_user_id(user_id);
user_token_tmp->set_user_type((IM::BaseDefine::ClientType)client_type);
user_token_tmp->set_token(device_token);
user_token_tmp->set_push_count(push_cnt);
user_token_tmp->set_push_type(IM_PUSH_TYPE_NORMAL);
CImPdu pdu;
pdu.SetPBMsg(&msg4);
pdu.SetServiceId(SID_OTHER);
pdu.SetCommandId(CID_OTHER_PUSH_TO_USER_REQ);
CPduAttachData attach_data(ATTACH_TYPE_PDU_FOR_PUSH, 0, pdu.GetBodyLength(), pdu.GetBodyData());
IM::Buddy::IMUsersStatReq msg5;
//.........这里部分代码省略.........