int pyllbc_Service::Send(int sessionId, int opcode, PyObject *data, int status, PyObject *parts) { // Started check. if (UNLIKELY(!this->IsStarted())) { pyllbc_SetError("service not start"); return LLBC_RTN_FAILED; } // Build parts, if exists. LLBC_PacketHeaderParts *cLayerParts = NULL; if (parts && _llbcSvcType != LLBC_IService::Raw) { if (!(cLayerParts = this->BuildCLayerParts(parts))) return LLBC_RTN_FAILED; } // Serialize python layer 'data' object to stream. LLBC_Stream stream; const int ret = this->SerializePyObj2Stream(data, stream); if (UNLIKELY(ret != LLBC_RTN_OK)) { LLBC_XDelete(cLayerParts); return LLBC_RTN_FAILED; } // Build packet & send. LLBC_Packet *packet = LLBC_New(LLBC_Packet); packet->Write(stream.GetBuf(), stream.GetPos()); packet->SetSessionId(sessionId); if (_llbcSvcType != LLBC_IService::Raw) { packet->SetOpcode(opcode); packet->SetStatus(status); if (cLayerParts) { cLayerParts->SetToPacket(*packet); LLBC_Delete(cLayerParts); } } if (UNLIKELY(_llbcSvc->Send(packet) == LLBC_RTN_FAILED)) { pyllbc_TransferLLBCError(__FILE__, __LINE__); return LLBC_RTN_FAILED; } return LLBC_RTN_OK; }