diff --git a/f8/protoutils.cc b/f8/protoutils.cc index 24397fd..66f447e 100644 --- a/f8/protoutils.cc +++ b/f8/protoutils.cc @@ -92,6 +92,24 @@ namespace f8 return sizeof(PackHead) + packlen; } + int Net_SendMsg(a8::AsioTcpClient* tcp_client, unsigned seqid, unsigned short msgid, + const ::google::protobuf::Message& msg) + { + int packlen = msg.ByteSize(); + + char* buff = (char*)malloc(sizeof(PackHead) + packlen); + PackHead* head = (PackHead*)buff; + head->packlen = packlen; + head->msgid = msgid; + head->seqid = seqid; + head->magic_code = MAGIC_CODE; + head->ext_len = packlen >> 16; + msg.SerializeToArray(buff + sizeof(PackHead), packlen); + tcp_client->SendBuff(buff, sizeof(PackHead) + packlen); + free(buff); + return sizeof(PackHead) + packlen; + } + int Net_SendBigMsg(a8::TcpClient* tcp_client, unsigned seqid, unsigned short msgid, ::google::protobuf::Message& msg) { diff --git a/f8/protoutils.h b/f8/protoutils.h index 19664ea..ff51951 100644 --- a/f8/protoutils.h +++ b/f8/protoutils.h @@ -89,6 +89,8 @@ namespace f8 void Net_PackMsg(unsigned short msgid, ::google::protobuf::Message& msg, std::string& out); int Net_SendMsg(a8::TcpClient* tcp_client, unsigned int seqid, unsigned short msgid, const ::google::protobuf::Message& msg); + int Net_SendMsg(a8::AsioTcpClient* tcp_client, unsigned int seqid, + unsigned short msgid, const ::google::protobuf::Message& msg); int Net_SendBigMsg(a8::TcpClient* tcp_client, unsigned int seqid, unsigned short msgid, ::google::protobuf::Message& msg); int Net_SendMsg(a8::TcpClient* tcp_client, unsigned int seqid, unsigned short msgid,