本文整理汇总了C++中Packet::GetData方法的典型用法代码示例。如果您正苦于以下问题:C++ Packet::GetData方法的具体用法?C++ Packet::GetData怎么用?C++ Packet::GetData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Packet
的用法示例。
在下文中一共展示了Packet::GetData方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: lock
void Room::RoomImpl::BroadcastRoomInformation() {
Packet packet;
packet << static_cast<u8>(IdRoomInformation);
packet << room_information.name;
packet << room_information.member_slots;
packet << room_information.uid;
packet << room_information.port;
packet << room_information.preferred_game;
packet << static_cast<u32>(members.size());
{
std::lock_guard<std::mutex> lock(member_mutex);
for (const auto& member : members) {
packet << member.nickname;
packet << member.mac_address;
packet << member.game_info.name;
packet << member.game_info.id;
}
}
ENetPacket* enet_packet =
enet_packet_create(packet.GetData(), packet.GetDataSize(), ENET_PACKET_FLAG_RELIABLE);
enet_host_broadcast(server, 0, enet_packet);
enet_host_flush(server);
}
示例2: main
int main()
{
// Security header
byte* header = new byte[4];
header = "HEAD";
// Protocol ID
CS_Protocol protocol = CS_Protocol::JOIN_GAME;
// Data
byte* data = "My_serialized_packet_data";
// Create a new Packet
Packet* packet = new Packet(header, protocol, data);
std::cout << "Packet Protocol: " << std::endl;
std::cout << packet->GetProtocolID() << std::endl;
std::cout << "Packet Data Length: " << std::endl;
std::cout << packet->GetDataLength() << std::endl;
std::cout << "Packet Data: " << std::endl;
std::cout << packet->GetData() << std::endl << std::endl;
std::cout << "Packet Payload: " << std::endl;
std::cout << packet->GetPayload() << std::endl << std::endl;
std::cout << "Changed Packet Data: " << std::endl;
byte* newData = "This data was changed by packet->SetData();";
packet->SetData(newData);
// Use GetPayload() to return serialized data ready for the networking stream.
std::cout << packet->GetPayload();
for (;;){}
}
示例3: Add
void CPacketQueue::Add(CAutoPtr<Packet> p)
{
CAutoLock cAutoLock(this);
if(p)
{
m_size += p->GetDataSize();
if(p->bAppendable && !p->bDiscontinuity && !p->pmt
&& p->rtStart == Packet::INVALID_TIME
&& !IsEmpty() && GetTail()->rtStart != Packet::INVALID_TIME)
{
Packet* tail = GetTail();
int oldsize = tail->GetCount();
int newsize = tail->GetCount() + p->GetCount();
tail->SetCount(newsize, max(1024, newsize)); // doubles the reserved buffer size
memcpy(tail->GetData() + oldsize, p->GetData(), p->GetCount());
/*
GetTail()->Append(*p); // too slow
*/
return;
}
}
AddTail(p);
}
示例4:
void Room::RoomImpl::SendWrongPassword(ENetPeer* client) {
Packet packet;
packet << static_cast<u8>(IdWrongPassword);
ENetPacket* enet_packet =
enet_packet_create(packet.GetData(), packet.GetDataSize(), ENET_PACKET_FLAG_RELIABLE);
enet_peer_send(client, 0, enet_packet);
enet_host_flush(server);
}
示例5: GetHeight
unsigned int Miner::GetHeight(int nTimeout)
{
Packet* packet = new Packet();
packet->SetHeader((unsigned char)GET_HEIGHT);
this->WritePacket(packet);
delete(packet);
Packet RESPONSE = ReadNextPacket(nTimeout);
if(RESPONSE.IsNull())
return 0;
if(RESPONSE.GetData().size() == 0)
{
return 0;
}
unsigned int nHeight = bytes2uint(RESPONSE.GetData());
ResetPacket();
return nHeight;
}
示例6: lock
void Room::RoomImpl::SendModBanListResponse(ENetPeer* client) {
Packet packet;
packet << static_cast<u8>(IdModBanListResponse);
{
std::lock_guard lock(ban_list_mutex);
packet << username_ban_list;
packet << ip_ban_list;
}
ENetPacket* enet_packet =
enet_packet_create(packet.GetData(), packet.GetDataSize(), ENET_PACKET_FLAG_RELIABLE);
enet_peer_send(client, 0, enet_packet);
enet_host_flush(server);
}
示例7: HandlePacket
void HTTP::HandlePacket(Packet& p)
{
String got;
got.assign(p.GetData(), p.GetSize());
LOG(got);
//handle request, close connection after handling
String response = HandleRequest(got);
auto foundIt = m_connections.find(p.GetAddress());
if(foundIt != m_connections.end())
foundIt->second.sock->Send(response.c_str(), response.size());
else
ERR("where did the connection go!?!?");
}
示例8: GetBlock
Core::CBlock* Miner::GetBlock(int nTimeout)
{
Packet* packet = new Packet();
packet->SetHeader(GET_BLOCK);
this->WritePacket(packet);
delete(packet);
Packet RESPONSE = ReadNextPacket(nTimeout);
if(RESPONSE.IsNull())
return NULL;
Core::CBlock* BLOCK = DeserializeBlock(RESPONSE.GetData());
ResetPacket();
return BLOCK;
}
示例9: JoinAudioBuffers
void CAudioPin::JoinAudioBuffers(Packet* pBuffer, CDeMultiplexer* pDemuxer)
{
if (pBuffer->pmt)
{
// Currently only uncompressed PCM audio is supported
if (pBuffer->pmt->subtype == MEDIASUBTYPE_PCM)
{
//LogDebug("aud: Joinig Audio Buffers");
WAVEFORMATEXTENSIBLE* wfe = (WAVEFORMATEXTENSIBLE*)pBuffer->pmt->pbFormat;
WAVEFORMATEX* wf = (WAVEFORMATEX*)wfe;
// Assuming all packets in the stream are the same size
int packetSize = pBuffer->GetDataSize();
int maxDurationInBytes = wf->nAvgBytesPerSec / 10; // max 100 ms buffer
while (true)
{
if ((MAX_BUFFER_SIZE - pBuffer->GetDataSize() >= packetSize ) &&
(maxDurationInBytes >= pBuffer->GetDataSize() + packetSize))
{
Packet* buf = pDemuxer->GetAudio(pBuffer->nPlaylist,pBuffer->nClipNumber);
if (buf)
{
byte* data = buf->GetData();
// Skip LPCM header when copying the next buffer
pBuffer->SetCount(pBuffer->GetDataSize() + buf->GetDataSize() - LPCM_HEADER_SIZE);
memcpy(pBuffer->GetData()+pBuffer->GetDataSize() - (buf->GetDataSize() - LPCM_HEADER_SIZE), &data[LPCM_HEADER_SIZE], buf->GetDataSize() - LPCM_HEADER_SIZE);
delete buf;
}
else
{
// No new buffer was available in the demuxer
break;
}
}
else
{
// buffer limit reached
break;
}
}
}
}
}
示例10: Send
////////////////////////////////////////////////////////////
/// Send a packet of data to the host (must be connected first)
////////////////////////////////////////////////////////////
Socket::Status SocketTCP::Send(Packet& PacketToSend)
{
// Let the packet do custom stuff before sending it
PacketToSend.OnSend();
// First send the packet size
Uint32 PacketSize = htonl(PacketToSend.GetDataSize());
Send(reinterpret_cast<const char*>(&PacketSize), sizeof(PacketSize));
// Send the packet data
if (PacketSize > 0)
{
return Send(PacketToSend.GetData(), PacketToSend.GetDataSize());
}
else
{
return Socket::Done;
}
}
示例11: SendResponseFrame
bool CProtocolComm::SendResponseFrame(DWORD dwRequestPacketID, Packet &packet)
{
Packet packet_remain;
if (WaitPopLast(0, packet_remain))
{
WARNING("sendResponseFrame queue get test");
// 如果是之前请求包的重发,则立即返回结果,否则丢弃结果包
if (packet_remain.GetPacketID() != dwRequestPacketID)
{
// 丢弃返回包
WARNING("sendResponseFrame queue find diff id packet");
// 重新放入队列,等待处理
m_queue.Push(packet_remain);
return false;
}
}
return SendFrame(packet.GetSrcAddr(), packet.GetDestAddr(),
packet.GetType(), packet.GetFunction(),
packet.GetData(), packet.GetDataLen(), false);
}
示例12: SubmitBlock
unsigned char Miner::SubmitBlock(uint512 hashMerkleRoot, unsigned long long nNonce, int nTimeout)
{
Packet* PACKET = new Packet();
PACKET->SetHeader(SUBMIT_BLOCK);
PACKET->SetData(hashMerkleRoot.GetBytes());
std::vector<unsigned char> NONCE = uint2bytes64(nNonce);
std::vector<unsigned char> pckt = PACKET->GetData();
pckt.insert(pckt.end(), NONCE.begin(), NONCE.end());
PACKET->SetData(pckt);
PACKET->SetLength(72);
this->WritePacket(PACKET);
delete(PACKET);
Packet RESPONSE = ReadNextPacket(nTimeout);
if(RESPONSE.IsNull())
return 0;
ResetPacket();
return RESPONSE.GetHeader();
}
示例13: getResponse
Packet* cRPCCommandHandler::getResponse(const Packet* pck)
{
Packet resp;
if(!m_sock)
{
error_log("Socket error for Cluster %s:%u",m_addr,m_port);
return NULL;
}
if(m_sock->Connect(m_port,m_addr) != 0)
{
error_log("Connect to Cluster %s:%u failed for RPC",m_addr,m_port);
return NULL;
}
m_sock->SetBlocking(true);
if(m_sock->Send((Packet&)*pck) != 0)
{
error_log("Sending Packet to Cluster %s:%u failed for RPC",m_addr,m_port);
return NULL;
}
if(m_sock->Receive(resp) != 0)
{
error_log("Receiving Packet forum Cluster %s:%u fail on RPC",m_addr,m_port);
return NULL;
}
Packet* resp_ = new Packet();
for(uint32 i=0;i<pck->GetDataSize();i++)
*resp_ << uint8(resp.GetData()[i]);
m_sock->Close();
return resp_;
}
示例14: PacketVaild
bool PacketBuffer::PacketVaild()
{
if (size() > 0)
{
//DEBUG("recv: %d", size());
//DEBUG_HEX(raw(), size());
Packet *pPacket = (Packet *)raw();
// check length
if (size() >= Packet::PACKET_MINLEN &&
size() >= pPacket->GetPacketLen())
{
// check checksum and packet end
WORD wCRC = __le16_to_cpu(*(WORD *)&(pPacket->GetData()[pPacket->GetDataLen()]));
WORD wCalCRC = pPacket->CheckSUM(&pPacket->m_btAddr, pPacket->GetPacketLen()-2);
if (wCRC == wCalCRC)
{
DEBUG("recv: %d", size());
DEBUG_HEX(raw(), size());
return true;
}
ERROR("serialport packet checksum wrong calc:%04x recv:%04X", wCalCRC, wCRC);
DEBUG_HEX(raw(), size());
}
else
{
return false;
}
// throw exception
throw(Packet::EXCEPTION_PACKET);
}
else
{
return false;
}
}
示例15: FillBuffer
//.........这里部分代码省略.........
return ERROR_NO_DATA;
}
} // comparemediatypes
}
} // lock ends
m_rtTitleDuration = buffer->rtTitleDuration;
if (checkPlaybackState)
{
buffer->nNewSegment = 0;
m_pCachedBuffer = buffer;
CheckPlaybackState();
LogDebug("vid: cached push %6.3f clip: %d playlist: %d", m_pCachedBuffer->rtStart / 10000000.0, m_pCachedBuffer->nClipNumber, m_pCachedBuffer->nPlaylist);
return ERROR_NO_DATA;
}
bool hasTimestamp = buffer->rtStart != Packet::INVALID_TIME;
REFERENCE_TIME rtCorrectedStartTime = 0;
REFERENCE_TIME rtCorrectedStopTime = 0;
if (hasTimestamp)
{
if (m_bZeroTimeStream)
{
m_rtStreamTimeOffset = buffer->rtStart - buffer->rtClipStartTime;
m_bZeroTimeStream = false;
}
if (m_bDiscontinuity || buffer->bDiscontinuity)
{
LogDebug("vid: set discontinuity");
pSample->SetDiscontinuity(true);
pSample->SetMediaType(buffer->pmt);
m_bDiscontinuity = false;
}
rtCorrectedStartTime = buffer->rtStart - m_rtStreamTimeOffset;
rtCorrectedStopTime = buffer->rtStop - m_rtStreamTimeOffset;
pSample->SetTime(&rtCorrectedStartTime, &rtCorrectedStopTime);
if (m_bInitDuration)
{
m_pFilter->SetTitleDuration(m_rtTitleDuration);
m_pFilter->ResetPlaybackOffset(buffer->rtPlaylistTime - rtCorrectedStartTime);
m_bInitDuration = false;
}
m_pFilter->OnPlaybackPositionChange();
}
else // Buffer has no timestamp
pSample->SetTime(NULL, NULL);
pSample->SetSyncPoint(buffer->bSyncPoint);
{
CAutoLock lock(&m_csDeliver);
if (!m_bFlushing)
{
BYTE* pSampleBuffer;
pSample->SetActualDataLength(buffer->GetDataSize());
pSample->GetPointer(&pSampleBuffer);
memcpy(pSampleBuffer, buffer->GetData(), buffer->GetDataSize());
m_bFirstSample = false;
#ifdef LOG_VIDEO_PIN_SAMPLES
LogDebug("vid: %6.3f corr %6.3f playlist time %6.3f clip: %d playlist: %d size: %d", buffer->rtStart / 10000000.0, rtCorrectedStartTime / 10000000.0,
buffer->rtPlaylistTime / 10000000.0, buffer->nClipNumber, buffer->nPlaylist, buffer->GetCount());
#endif
}
else
{
LogDebug("vid: dropped sample as flush is active!");
return ERROR_NO_DATA;
}
}
//static int iFrameNumber = 0;
//LogMediaSample(pSample, iFrameNumber++);
delete buffer;
}
} while (!buffer);
return NOERROR;
}
catch(...)
{
LogDebug("vid: FillBuffer exception");
}
return S_OK;
}