This commit is contained in:
aozhiwei 2019-06-03 16:53:06 +08:00
parent ca38a14dc4
commit 7f6c831d8d
2 changed files with 23 additions and 0 deletions

View File

@ -3,6 +3,7 @@
#include "framework/cpp/protoutils.h"
#include <a8/tcpclient.h>
#include <a8/tcpclient2.h>
#include <a8/tcplistener.h>
#include <google/protobuf/message.h>
@ -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)
{

View File

@ -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,