|
#include "StdAfx.h"
#include "ProtobufPacket.h"
ProtobufPacketImpl::ProtobufPacketImpl( int serviceId, google::protobuf::Message* message )
{
this->serviceId = serviceId;
this->message = message;
pEncodedStream = NULL;
}
ProtobufPacketImpl::~ProtobufPacketImpl( void )
{
delete pEncodedStream;
}
bool ProtobufPacketImpl::Decode( char* pBuf, unsigned int nSize )
{
if(nSize == 0)
return true;
return getStructuredData().ParseFromArray(pBuf, nSize);
}
bool ProtobufPacketImpl::Encode()
{
if(pEncodedStream)
return true;
pEncodedStream = new std::string();
if(!getStructuredData().SerializeToString(pEncodedStream))
{
delete pEncodedStream;
pEncodedStream = NULL;
return false;
}
getStructuredData().ByteSize();
return true;
}
int ProtobufPacketImpl::getEncodedStreamSize()
{
return getStructuredData().GetCachedSize();
}
google::protobuf::Message& ProtobufPacketImpl::getStructuredData()
{
return (*message);
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.