本文整理汇总了C++中OutStream::Skip方法的典型用法代码示例。如果您正苦于以下问题:C++ OutStream::Skip方法的具体用法?C++ OutStream::Skip怎么用?C++ OutStream::Skip使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OutStream
的用法示例。
在下文中一共展示了OutStream::Skip方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Execute
void SendMsg::Execute(Session *s) {
InStream jis(s->GetRequestPack()->buf, s->GetRequestPack()->head.len);
uint16 cmd = s->GetCmd();
// 登录id
string from;
string to;
string text;
string uuid;
jis>>from;
jis>>to;
jis>>text;
jis>>uuid;
int16 error_code = kErrCode00;
char error_msg[ERR_MSG_LENGTH+1] = {0};
DataService dao;
IMMsg msg;
int ret = kErrCode00;
int msgId;
ret = dao.SendMsg(from, to, text, msgId);
if (ret == kErrCode00) {
LOG(INFO)<<"发送记录插入 userId: "<<from;
} else {
error_code = ret;
assert(error_code < kErrCodeMax);
strcpy(error_msg, gErrMsg[error_code].c_str());
LOG(ERROR)<<"发送记录插入出错: "<<error_msg<<" userId: "<<from;
}
OutStream jos;
// 包头命令
jos<<cmd;
size_t lengthPos = jos.Length();
jos.Skip(2);///留出2个字节空间用来后面存储包体长度+包尾(8)的长度
// 包头cnt、seq、error_code、error_msg
uint16 cnt = 0;
uint16 seq = 0;
jos<<cnt<<seq<<error_code;
jos.WriteBytes(error_msg, ERR_MSG_LENGTH);
// 包体
if (ret == kErrCode00) {
jos<<msgId;
jos<<uuid;
}
FillOutPackage(jos, lengthPos, cmd);
s->Send(jos.Data(), jos.Length());
if (ret == kErrCode00) {
PushService push;
push.PushSendMsg(from, to, dao);
}
}
示例2: Execute
void RequestAddBuddy::Execute(Session *s) {
InStream jis(s->GetRequestPack()->buf, s->GetRequestPack()->head.len);
uint16 cmd = s->GetCmd();
// 好友请求
string fromName;
string toName;
jis>>fromName;
jis>>toName;
int16 error_code = kErrCode00;
char error_msg[ERR_MSG_LENGTH+1] = {0};
// 实际的添加操作
DataService dao;
int ret;
string toId;
string reqId;
ret = dao.RequestAddBuddy(fromName, toName, toId, reqId);
if (ret == kErrCode00) {
strcpy(error_msg, "请求发送成功");
LOG(INFO)<<"添加好友请求成功 from: "<<fromName<<" to: "<<toName;
} else {
error_code = ret;
assert(error_code < kErrCodeMax);
strcpy(error_msg, gErrMsg[error_code].c_str());
LOG(INFO)<<"添加好友请求失败 from: "<<fromName<<" to: "<<toName<<" "<<error_msg;
}
OutStream jos;
// 包头命令
jos<<cmd;
size_t lengthPos = jos.Length();
jos.Skip(2);///留出2个字节空间用来后面存储包体长度+包尾(8)的长度
// 包头cnt、seq、error_code、error_msg
uint16 cnt = 0;
uint16 seq = 0;
jos<<cnt<<seq<<error_code;
jos.WriteBytes(error_msg, ERR_MSG_LENGTH);
// 空包体
FillOutPackage(jos, lengthPos, cmd);
s->Send(jos.Data(), jos.Length());
if (ret == kErrCode00) {
PushService push;
//通知在线请求方同意结果
push.PushRequestAddBuddy(s->GetIMUser(), toId, reqId, dao);
}
}
示例3: Execute
void HeartBeat::Execute(Session *s) {
InStream jis(s->GetRequestPack()->buf, s->GetRequestPack()->head.len);
uint16 cmd = s->GetCmd();
// 登录id
string userId;
jis>>userId;
int16 error_code = kErrCode00;
char error_msg[ERR_MSG_LENGTH+1] = {0};
int ret = kErrCode00;
if (ret == kErrCode00) {
LOG(INFO)<<"用户心跳包 userId: "<<userId;
timeval now;
gettimeofday(&now, NULL);
s->SetLastTime(now);
} else {
error_code = ret;
assert(error_code < kErrCodeMax);
strcpy(error_msg, gErrMsg[error_code].c_str());
//LOG_ERROR<<"发送记录插入出错: "<<error_msg<<" userId: "<<from;
}
OutStream jos;
// 包头命令
jos<<cmd;
size_t lengthPos = jos.Length();
jos.Skip(2);///留出2个字节空间用来后面存储包体长度+包尾(8)的长度
// 包头cnt、seq、error_code、error_msg
uint16 cnt = 0;
uint16 seq = 0;
jos<<cnt<<seq<<error_code;
jos.WriteBytes(error_msg, ERR_MSG_LENGTH);
// 空包体
FillOutPackage(jos, lengthPos, cmd);
s->Send(jos.Data(), jos.Length());
}