From 7f6c831d8dbef97267f3a87053249d7beb0bf615 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Mon, 3 Jun 2019 16:53:06 +0800 Subject: [PATCH] 1 --- cpp/protoutils.cc | 20 ++++++++++++++++++++ cpp/protoutils.h | 3 +++ 2 files changed, 23 insertions(+) diff --git a/cpp/protoutils.cc b/cpp/protoutils.cc index 0b363c5..bc7c800 100644 --- a/cpp/protoutils.cc +++ b/cpp/protoutils.cc @@ -3,6 +3,7 @@ #include "framework/cpp/protoutils.h" #include +#include #include #include @@ -95,6 +96,25 @@ namespace f8 return sizeof(PackHead) + packlen; } + int Net_SendMsg(a8::TcpClient2* tcp_client, unsigned seqid, unsigned short msgid, + ::google::protobuf::Message& msg) + { + int packlen = msg.ByteSize(); + assert(packlen < 1024 * 60); + + 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->rpc_error_code = 0; + 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/cpp/protoutils.h b/cpp/protoutils.h index 3cf8459..92e3be2 100644 --- a/cpp/protoutils.h +++ b/cpp/protoutils.h @@ -12,6 +12,7 @@ namespace google namespace a8 { class TcpClient; + class TcpClient2; class TcpListener; } @@ -94,6 +95,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, ::google::protobuf::Message& msg); + int Net_SendMsg(a8::TcpClient2* tcp_client, unsigned int seqid, + unsigned short msgid, ::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,