bool SFAvroProtocol::Encode(BasePacket* pPacket, char** ppBuffer, int& bufferSize) { SFAvroPacketImpl* pAvroPacket = (SFAvroPacketImpl*)pPacket; ////////////////////////////////////////////////// //header copy ////////////////////////////////////////////////// memcpy(m_pBuffer, pAvroPacket->GetHeader(), sizeof(SFPacketHeader)); /*std::auto_ptr<avro::OutputStream> out = avro::memoryOutputStream(); avro::EncoderPtr e = avro::binaryEncoder(); e->init(*out); bool bResult = pAvroPacket->Encode(e);*/ unsigned int writtenSize = pAvroPacket->GetBufferSize(); memcpy(m_pBuffer + sizeof(SFPacketHeader), pAvroPacket->GetBuffer(), writtenSize); //데이터 사이즈를 헤더에 쓴다. //12바이트 헤더의 마지막 2바이트에 기록 *((unsigned short*)m_pBuffer + 5) = writtenSize; *ppBuffer = m_pBuffer; bufferSize = sizeof(SFPacketHeader)+writtenSize; return true; }
bool SFAvroProtocol::SendRequest(BasePacket* pPacket) { SFAvroPacketImpl* pAvroPacket = (SFAvroPacketImpl*)pPacket; const int bufferSize = 8192; char buffer[bufferSize] = { 0, }; ////////////////////////////////////////////////// //header copy ////////////////////////////////////////////////// memcpy(buffer, pAvroPacket->GetHeader(), sizeof(SFPacketHeader)); /*std::auto_ptr<avro::OutputStream> out = avro::memoryOutputStream(); avro::EncoderPtr e = avro::binaryEncoder(); e->init(*out); bool bResult = pAvroPacket->Encode(e);*/ unsigned int writtenSize = pAvroPacket->GetBufferSize(); memcpy(buffer + sizeof(SFPacketHeader), pAvroPacket->GetBuffer(), writtenSize); //데이터 사이즈를 헤더에 쓴다. //12바이트 헤더의 마지막 2바이트에 기록 *((unsigned short*)buffer + 5) = writtenSize; SFEngine::GetInstance()->SendInternal(pAvroPacket->GetOwnerSerial(), buffer, sizeof(SFPacketHeader)+writtenSize); return true; }