From 8a49aa65c8576cabe1672be55fc903a6b17e2c37 Mon Sep 17 00:00:00 2001 From: azw Date: Sat, 6 May 2023 14:30:44 +0000 Subject: [PATCH] 1 --- f8/protoutils.cc | 18 ++++++++++++++++++ f8/protoutils.h | 2 ++ 2 files changed, 20 insertions(+) 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,