本文整理汇总了C++中PacketReader::available方法的典型用法代码示例。如果您正苦于以下问题:C++ PacketReader::available方法的具体用法?C++ PacketReader::available怎么用?C++ PacketReader::available使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PacketReader
的用法示例。
在下文中一共展示了PacketReader::available方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: add
void add(PacketReader& fragment) {
string::size_type old = _pBuffer->size();
_pBuffer->resize(old + fragment.available(),true);
if(_pBuffer->size()>old)
memcpy(_pBuffer->data()+old,fragment.current(),fragment.available());
++(UInt16&)fragments;
}
示例2: add
void add(PacketReader& fragment) {
string::size_type old = _buffer.size();
_buffer.resize(old + (string::size_type)fragment.available());
if(_buffer.size()>old)
memcpy(&_buffer[old],fragment.current(),(size_t)fragment.available());
++(UInt16&)fragments;
}
示例3: buildPacket
bool WSSession::buildPacket(PacketReader& packet) {
if (packet.available()<2)
return false;
UInt8 type = packet.read8() & 0x0F;
UInt8 lengthByte = packet.read8();
UInt32 size=lengthByte&0x7f;
if (size==127) {
if (packet.available()<8)
return false;
size = (UInt32)packet.read64();
} else if (size==126) {
if (packet.available()<2)
return false;
size = packet.read16();
}
if(lengthByte&0x80)
size += 4;
if (packet.available()<size)
return false;
packet.shrink(size);
if (lengthByte & 0x80) {
shared_ptr<WSUnmasking> pWSUnmasking(new WSUnmasking(invoker, packet.current(),packet.available(), type));
decode<WSUnmasking>(pWSUnmasking);
} else {
packet.reset(packet.position()-1);
*(UInt8*)packet.current() = type;
}
return true;
}
示例4: packetHandler
void ServerConnection::packetHandler(PacketReader& packet) {
UInt8 marker = packet.read8();
if(marker!=0x0b) {
ERROR("ServerConnection with an unknown %u marker, it should be 0x0b",marker);
return;
}
packet.next(2);
UInt8 id = packet.read8();
switch(id) {
case 0x71: {
packet.next(2);
string tag;
packet.readString8(tag);
map<string,P2PHandshakerAddress>::iterator it = _p2pHandshakers.find(tag);
if(it==_p2pHandshakers.end()) {
ERROR("Unknown ServerConnection tag %s on P2P handshake",tag.c_str());
break;
}
(SocketAddress&)_handshake.peer.address = it->second;
packet.reset(0);
PacketWriter writer(packet.current(),packet.available()+16); // +16 for futur 0xFFFF padding
writer.clear(packet.available());
_handshake.send(writer);
_p2pHandshakers.erase(it);
break;
}
case 0x40: {
if(!_connected) {
// Edge hello response
_connected=true;
return;
}
// Edge keepalive
PacketWriter& packet(writer());
packet.write8(0x41);
packet.write16(0);
flush();
INFO("Keepalive RTMFP server");
break;
}
case 0x45: {
// Server is death!
(bool&)died=true;
break;
}
default:
ERROR("Unkown ServerConnection packet id %u",id);
}
}
示例5: unpack
Message::Type Flow::unpack(PacketReader& reader) {
if(reader.available()==0)
return Message::EMPTY;
Message::Type type = (Message::Type)reader.read8();
switch(type) {
// amf content
case 0x11:
reader.next(1);
case Message::AMF_WITH_HANDLER:
reader.next(4);
return Message::AMF_WITH_HANDLER;
case Message::AMF:
reader.next(5);
case Message::AUDIO:
case Message::VIDEO:
break;
// raw data
case 0x04:
reader.next(4);
case 0x01:
break;
default:
ERROR("Unpacking type '%02x' unknown",type);
break;
}
return type;
}
示例6: unpack
AMF::ContentType RTMFPFlow::unpack(PacketReader& packet,UInt32& time) {
if(packet.available()==0)
return AMF::EMPTY;
AMF::ContentType type = (AMF::ContentType)packet.read8();
switch(type) {
// amf content
case AMF::INVOCATION_AMF3:
packet.next(1);
case AMF::INVOCATION:
packet.next(4);
return AMF::INVOCATION;
case AMF::AUDIO:
case AMF::VIDEO:
time = packet.read32();
break;
case AMF::DATA:
packet.next(1);
case AMF::RAW:
packet.next(4);
case AMF::CHUNKSIZE:
break;
default:
ERROR("Unpacking type '",Format<UInt8>("%02x",(UInt8)type),"' unknown");
break;
}
return type;
}
示例7: Decode
bool RTMFP::Decode(Exception& ex,RTMFPEngine& aesDecrypt,PacketReader& packet) {
// Decrypt
aesDecrypt.process(packet.current(),(UInt8*)packet.current(),packet.available());
bool result = ReadCRC(packet);
if (!result)
ex.set(Exception::CRYPTO, "Bad RTMFP CRC sum computing");
return result;
}
示例8: Decode
bool RTMFP::Decode(AESEngine& aesDecrypt,PacketReader& packet) {
// Decrypt
aesDecrypt.process(packet.current(),packet.current(),packet.available());
// Check the first 2 CRC bytes
packet.reset(4);
UInt16 sum = packet.read16();
return (sum == CheckSum(packet));
}
示例9: pushDataPacket
void Listener::pushDataPacket(const string& name,PacketReader& packet) {
// TODO create _dataWriter ??
if(_unbuffered) {
UInt16 offset = name.size()+9;
if(packet.position()>=offset) {
packet.reset(packet.position()-offset);
_writer.writeUnbufferedMessage(packet.current(),packet.available());
return;
}
WARN("Written unbuffered impossible, it requires %u head bytes available on PacketReader given",offset);
}
StreamCopier::copyStream(packet.stream(),_writer.writeAMFPacket(name).writer.stream());
}
示例10: writeMedia
bool WSWriter::writeMedia(MediaType type,UInt32 time,PacketReader& packet,Parameters& properties) {
if(state()==CLOSED)
return true;
switch(type) {
case START:
writeInvocation("__publishing").writeString(string((const char*)packet.current(),packet.available()));
break;
case STOP:
writeInvocation("__unpublishing").writeString(string((const char*)packet.current(),packet.available()));
break;
case DATA: {
JSONWriter& writer = newDataWriter();
writer.packet.write8('[');
writer.packet.writeRaw(packet.current(),packet.available());
writer.packet.write8(']');
break;
}
case INIT:
break;
default:
return Writer::writeMedia(type,time,packet,properties);
}
return true;
}
示例11: write
void write(UInt32 time,PacketReader& data,bool unbuffered) {
// if(_type==0x08)
// time=0;
/* if(_type==0x09)
TRACE("Video timestamp : %u",_time)
else
TRACE("Audio timestamp : %u",_time);*/
if(unbuffered) {
if(data.position()>=5) {
data.reset(data.position()-5);
PacketWriter writer(data.current(),5);
writer.write8(_type);
writer.write32(time);
writeUnbufferedMessage(data.current(),data.available(),data.current(),5);
return;
}
WARN("Written unbuffered impossible, it requires 5 head bytes available on PacketReader given");
}
BinaryWriter& out = writeRawMessage(true);
out.write8(_type);
out.write32(time);
StreamCopier::copyStream(data.stream(),out.stream());
}
示例12: targetPacketHandler
void Middle::targetPacketHandler(PacketReader& packet) {
if(_firstResponse)
((Timestamp&)peer.lastReceptionTime).update(); // To emulate a long ping corresponding, otherwise client send multiple times each packet
_firstResponse = false;
UInt8 marker = packet.read8();
_timeSent = packet.read16(); // time
UInt16 timeEcho(0);
if((marker|0xF0) == 0xFE)
timeEcho = packet.read16(); // time echo
PacketWriter& packetOut = writer();
int pos = packetOut.position();
UInt8 type = packet.available()>0 ? packet.read8() : 0xFF;
UInt64 idFlow,stage;
UInt8 nbPeerSent = 0;
while(type!=0xFF) {
int posType = packetOut.position();
packetOut.write8(type);
UInt16 size = packet.read16();
PacketReader content(packet.current(),size);packetOut.write16(size);
if(type==0x10 || type==0x11) {
UInt8 flag = content.read8();packetOut.write8(flag);
if(type==0x10) {
idFlow = content.read7BitLongValue();packetOut.write7BitLongValue(idFlow);
stage = content.read7BitLongValue();packetOut.write7BitLongValue(stage);
packetOut.write7BitLongValue(content.read7BitLongValue());
} else
++stage;
if(!(flag&MESSAGE_WITH_BEFOREPART)) {
if(flag&MESSAGE_HEADER) {
UInt8 len = content.read8(); packetOut.write8(len);
while(len!=0) {
packetOut.writeRaw(content.current(),len);
content.next(len);
len = content.read8(); packetOut.write8(len);
}
}
UInt8 flagType = content.read8(); packetOut.write8(flagType);
if(flagType==0x09) {
UInt32 time = content.read32(); packetOut.write32(time);
TRACE("Timestamp/Flag video : %u/%2x",time,*content.current());
} else if(flagType==0x08) {
UInt32 time = content.read32(); packetOut.write32(time);
TRACE("Timestamp/Flag audio : %u/%2x",time,*content.current());
} else if(flagType==0x04) {
packetOut.write32(content.read32());
UInt16 a = content.read16();packetOut.write16(a);
UInt32 b = content.read32(); packetOut.write32(b);
if(content.available()>0) {
UInt32 c = content.read32(); packetOut.write32(c);
if(a!=0x22) {
DEBUG("Raw %llu : %.2x %u %u",idFlow,a,b,c)
} else {
TRACE("Bound %llu : %.2x %u %u",idFlow,a,b,c);
}
} else
DEBUG("Raw %llu : %.2x %u",idFlow,a,b)
/* if(a==0x1F) {
packetOut.reset(posType);
content.next(content.available());
}*/
}
示例13: packetHandler
void Middle::packetHandler(PacketReader& packet) {
if(!_pMiddleAesEncrypt)
manage(); // to wait the target handshake response
// Middle to target
PacketWriter& request = requester();
UInt8 marker = packet.read8();
request << marker;
request << packet.read16();
if((marker|0xF0) == 0xFD)
request.write16(packet.read16()); // time echo
int pos = request.position();
UInt8 type = packet.available()>0 ? packet.read8() : 0xFF;
while(type!=0xFF) {
UInt16 size = packet.read16();
PacketReader content(packet.current(),size);
PacketWriter out(request.begin()+request.position(),request.available()); // 3 for future type and size
out.clear(3);
if(type==0x10) {
out.write8(content.read8());
UInt64 idFlow = content.read7BitLongValue();out.write7BitLongValue(idFlow);
UInt64 stage = content.read7BitLongValue();out.write7BitLongValue(stage);
if(idFlow==0x02 && stage==0x01) {
if(!_isPeer) {
/// Replace NetConnection infos
out.writeRaw(content.current(),14);content.next(14);
// first string
string tmp;
content.readString16(tmp);out.writeString16(tmp);
AMFWriter writer(out);
writer.amf0Preference=true;
AMFReader reader(content);
writer.writeNumber(reader.readNumber()); // double
AMFSimpleObject obj;
reader.readSimpleObject(obj);
/// Replace tcUrl
if(obj.has("tcUrl"))
obj.setString("tcUrl",_queryUrl);
writer.writeSimpleObject(obj);
} else {
out.writeRaw(content.current(),3);content.next(3);
UInt16 netGroupHeader = content.read16();out.write16(netGroupHeader);
if(netGroupHeader==0x4752) {
map<string,string>::const_iterator it = peer.properties.find("groupspec");
if(it!=peer.properties.end()) {
out.writeRaw(content.current(),71);content.next(71);
UInt8 result1[AES_KEY_SIZE];
UInt8 result2[AES_KEY_SIZE];
HMAC(EVP_sha256(),&_sharedSecret[0],_sharedSecret.size(),&_targetNonce[0],_targetNonce.size(),result1,NULL);
HMAC(EVP_sha256(),it->second.c_str(),it->second.size(),result1,AES_KEY_SIZE,result2,NULL);
out.writeRaw(result2,AES_KEY_SIZE);content.next(AES_KEY_SIZE);
out.writeRaw(content.current(),4);content.next(4);
out.writeRaw(_target.peerId,ID_SIZE);content.next(ID_SIZE);
} else
WARN("No groupspec client property indicated to make working the 'man-in-the-middle' mode between peers in a NetGroup case");
}
}
}
} else if(type == 0x4C) {
kill();
return;
} else if(type == 0x51) {
//printf("%s\n",Util::FormatHex(content.current(),content.available()).c_str());
}
out.writeRaw(content.current(),content.available());
packet.next(size);
if(out.length()>=3) {
request<<type;
size = out.length()-3;
request.write16(size);request.next(size);
}
type = packet.available()>0 ? packet.read8() : 0xFF;
}
if(request.length()>pos)
//.........这里部分代码省略.........
示例14: flags
Fragment(PacketReader& data,UInt8 flags) : flags(flags),Buffer<UInt8>(data.available()) {
data.readRaw(begin(),size());
}
示例15: Decode
bool RTMFP::Decode(AESEngine& aesDecrypt,PacketReader& packet) {
// Decrypt
aesDecrypt.process(packet.current(),packet.current(),packet.available());
return ReadCRC(packet);
}