本文整理汇总了C++中PacketReader::read16方法的典型用法代码示例。如果您正苦于以下问题:C++ PacketReader::read16方法的具体用法?C++ PacketReader::read16怎么用?C++ PacketReader::read16使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PacketReader
的用法示例。
在下文中一共展示了PacketReader::read16方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: packetHandler
void Handshake::packetHandler(PacketReader& packet) {
UInt8 marker = packet.read8();
if(marker!=0x0b) {
ERROR("Marker handshake wronk : must be '0B' and not '%02x'",marker);
return;
}
UInt16 time = packet.read16();
UInt8 id = packet.read8();
packet.shrink(packet.read16()); // length
PacketWriter& packetOut = writer();
UInt8 idResponse=0;
{
PacketWriter response(packetOut,3);
idResponse = handshakeHandler(id,packet,response);
if(idResponse==0)
return;
}
packetOut << (UInt8)idResponse;
packetOut << (UInt16)(packetOut.length()-packetOut.position()-2);
send(true);
// reset farid to 0!
_farId=0;
}
示例2: packetHandler
void Handshake::packetHandler(PacketReader& packet) {
UInt8 marker = packet.read8();
if(marker!=0x0b) {
ERROR("Marker handshake wrong : should be 0b and not %u",marker);
return;
}
UInt16 time = packet.read16();
UInt8 id = packet.read8();
packet.shrink(packet.read16()); // length
PacketWriter& response(writer());
UInt32 pos = response.position();
response.next(3);
UInt8 idResponse = handshakeHandler(id,packet,response);
response.reset(pos);
if(idResponse>0) {
response.write8(idResponse);
response.write16(response.length()-response.position()-2);
flush();
}
// reset farid to 0!
(UInt32&)farId=0;
}
示例3: rawHandler
void FlashStream::rawHandler(UInt8 type, PacketReader& packet, FlashWriter& writer) {
if(packet.read16()==0x22) { // TODO Here we receive RTMFP flow sync signal, useless to support it!
//TRACE("Sync ",id," : ",data.read32(),"/",data.read32());
return;
}
ERROR("Raw message ",Format<UInt8>("%.2x",type),"/",packet.read16()," unknown on stream ",id);
}
示例4: 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;
}
示例5: rawHandler
void FlashStream::rawHandler(UInt8 type, PacketReader& packet, FlashWriter& writer) {
if(packet.read16()==0x22) { // TODO Here we receive publication bounds (id + tracks), useless? maybe to record a file and sync tracks?
//TRACE("Bound ",id," : ",data.read32()," ",data.read32());
return;
}
ERROR("Raw message ",type," unknown on stream ",id);
}
示例6: rawHandler
void FlowStream::rawHandler(UInt8 type,PacketReader& data) {
UInt16 flag = data.read16();
if(flag==0x22) { // TODO Here we receive publication bounds (id + tracks), useless? maybe to record a file and sync tracks?
//TRACE("Bound %u : %u %u",id,data.read32(),data.read32());
return;
}
ERROR("Unknown raw flag %u on FlowStream %llu",flag,id);
Flow::rawHandler(type,data);
}
示例7: 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));
}
示例8: packetHandler
void RTMFPHandshake::packetHandler(PacketReader& packet) {
UInt8 marker = packet.read8();
if(marker!=0x0b) {
ERROR("Marker handshake wrong : should be 0b and not ",Format<UInt8>("%.2x",marker));
return;
}
UInt16 time = packet.read16();
UInt8 id = packet.read8();
packet.shrink(packet.read16()); // length
PacketWriter& response(this->packet());
UInt32 oldSize(response.size());
response.next(3); // type and size
UInt8 idResponse = handshakeHandler(id,packet,response);
if(idResponse>0)
BinaryWriter(response,oldSize).write8(idResponse).write16(response.size()-oldSize-3);
else
response.clear(oldSize);
}
示例9: rawHandler
void FlowConnection::rawHandler(UInt8 type,PacketReader& data) {
UInt16 flag = data.read16();
if(flag!=0x03) {
Flow::rawHandler(type,data);
return;
}
// setBufferTime
UInt32 streamId = data.read32();
if(streamId>0) {
INFO("setBufferTime %u on stream %u",data.read32(),streamId)
BinaryWriter& raw = writer.writeRawMessage();
raw.write16(0);
raw.write32(streamId);
}
}
示例10: packetHandler
void RTMFPSession::packetHandler(PacketReader& packet) {
_recvTimestamp.update();
// Read packet
UInt8 marker = packet.read8()|0xF0;
_timeSent = packet.read16();
// with time echo
if(marker == 0xFD) {
UInt16 time = RTMFP::TimeNow();
UInt16 timeEcho = packet.read16();
if(timeEcho>time) {
if(timeEcho-time<30)
time=0;
else
time += 0xFFFF-timeEcho;
timeEcho = 0;
}
peer.setPing((time-timeEcho)*RTMFP_TIMESTAMP_SCALE);
}
else if(marker != 0xF9)
WARN("RTMFPPacket marker unknown : ", Format<UInt8>("%02x",marker));
// Variables for request (0x10 and 0x11)
UInt8 flags;
RTMFPFlow* pFlow=NULL;
UInt64 stage=0;
UInt64 deltaNAck=0;
UInt8 type = packet.available()>0 ? packet.read8() : 0xFF;
bool answer = false;
// Can have nested queries
while(type!=0xFF) {
UInt16 size = packet.read16();
PacketReader message(packet.current(),size);
switch(type) {
case 0x0c :
fail("failed on client side");
break;
case 0x4c :
/// Session death!
_failed = true; // to avoid the fail signal!!
kill();
return;
/// KeepAlive
case 0x01 :
if(!peer.connected)
fail("Timeout connection client");
else
writeMessage(0x41,0);
case 0x41 :
_timesKeepalive=0;
break;
case 0x5e : {
// RTMFPFlow exception!
UInt64 id = message.read7BitLongValue();
RTMFPWriter* pRTMFPWriter = writer(id);
if(pRTMFPWriter)
pRTMFPWriter->fail("Writer rejected on session ",name());
else
WARN("RTMFPWriter ", id, " unfound for failed signal on session ", name());
break;
}
case 0x18 :
/// This response is sent when we answer with a Acknowledgment negative
// It contains the id flow
// I don't unsertand the usefulness...
//pFlow = &flow(message.read8());
//stage = pFlow->stageSnd();
// For the moment, we considerate it like a exception
fail("ack negative from server"); // send fail message immediatly
break;
case 0x51 : {
/// Acknowledgment
UInt64 id = message.read7BitLongValue();
RTMFPWriter* pRTMFPWriter = writer(id);
if(pRTMFPWriter)
pRTMFPWriter->acknowledgment(message);
else
WARN("RTMFPWriter ",id," unfound for acknowledgment on session ",name());
break;
}
/// Request
// 0x10 normal request
// 0x11 special request, in repeat case (following stage request)
case 0x10 : {
flags = message.read8();
//.........这里部分代码省略.........
示例11: packetHandler
void WSSession::packetHandler(PacketReader& packet) {
UInt8 type = 0;
Exception ex;
if(peer.connected) {
type = packet.read8();
switch(type) {
case WS::TYPE_BINARY: {
RawReader reader(packet);
peer.onMessage(ex, "onMessage",reader,WS::TYPE_BINARY);
break;
}
case WS::TYPE_TEXT: {
if(!JSONReader::IsValid(packet)) {
RawReader reader(packet);
peer.onMessage(ex, "onMessage",reader);
break;
}
JSONReader reader(packet);
if(reader.followingType()!=JSONReader::STRING) {
peer.onMessage(ex, "onMessage",reader);
break;
}
string name;
reader.readString(name);
if(name=="__publish") {
if(reader.followingType()!=JSONReader::STRING) {
ex.set(Exception::PROTOCOL, "__publish method takes a stream name in first parameter",WS::CODE_MALFORMED_PAYLOAD);
break;
}
reader.readString(name);
if(_pPublication)
invoker.unpublish(peer,_pPublication->name());
_pPublication = invoker.publish(ex, peer,name);
} else if(name=="__play") {
if(reader.followingType()!=JSONReader::STRING) {
ex.set(Exception::PROTOCOL, "__play method takes a stream name in first parameter",WS::CODE_MALFORMED_PAYLOAD);
break;
}
reader.readString(name);
closeSusbcription();
} else if(name=="__closePublish") {
closePublication();
} else if(name=="__closePlay") {
closeSusbcription();
} else if (name == "__close") {
closePublication();
closeSusbcription();
} else if(_pPublication) {
reader.reset();
_pPublication->pushData(reader);
} else
peer.onMessage(ex, name,reader);
break;
}
case WS::TYPE_CLOSE:
_writer.close(packet.available() ? packet.read16() : 0);
break;
case WS::TYPE_PING:
_writer.writePong(packet.current(),packet.available());
break;
case WS::TYPE_PONG:
peer.setPing(_writer.ping = (UInt16)(_time.elapsed()/1000));
break;
default:
ex.set(Exception::PROTOCOL, Format<UInt8>("Type %#x unknown", type), WS::CODE_MALFORMED_PAYLOAD);
break;
}
if (ex) {
ERROR(ex.error());
_writer.close((ex.code()==Exception::APPLICATION || ex.code() == Exception::SOFTWARE) ? WS::CODE_PROTOCOL_ERROR : ex.code());
}
}
if(!peer.connected || type==WS::TYPE_CLOSE)
kill();
else
_writer.flush();
}
示例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 Session::packetHandler(PacketReader& packet) {
_recvTimestamp.update();
// Read packet
UInt8 marker = packet.read8()|0xF0;
_timeSent = packet.read16();
// with time echo
if(marker == 0xFD)
_peer.setPing(RTMFP::Time(_recvTimestamp.epochMicroseconds())-packet.read16());
else if(marker != 0xF9)
WARN("Packet marker unknown : %02x",marker);
// Variables for request (0x10 and 0x11)
UInt8 flags;
Flow* pFlow=NULL;
UInt32 stage=0;
UInt32 deltaNAck=0;
UInt8 type = packet.available()>0 ? packet.read8() : 0xFF;
bool answer = false;
// Can have nested queries
while(type!=0xFF) {
UInt16 size = packet.read16();
PacketReader message(packet.current(),size);
switch(type) {
case 0x0c :
fail("Session failed on the client side");
break;
case 0x4c :
/// Session death!
kill();
break;
/// KeepAlive
case 0x01 :
writeMessage(0x41,0);
case 0x41 :
_timesKeepalive=0;
break;
case 0x5e : {
// Flow exception!
UInt32 id = message.read7BitValue();
FlowWriter* pFlowWriter = flowWriter(id);
if(pFlowWriter)
pFlowWriter->fail("receiver has rejected the flow");
else
WARN("FlowWriter %u unfound for failed signal",id);
break;
}
case 0x18 :
/// This response is sent when we answer with a Acknowledgment negative
// It contains the id flow
// I don't unsertand the usefulness...
//pFlow = &flow(message.read8());
//stage = pFlow->stageSnd();
// For the moment, we considerate it like a exception
fail("ack negative from server"); // send fail message immediatly
break;
case 0x51 : {
/// Acknowledgment
UInt32 id = message.read7BitValue();
FlowWriter* pFlowWriter = flowWriter(id);
if(pFlowWriter) {
UInt8 ack = message.read8();
while(ack==0xFF)
ack = message.read8();
if(ack>0)
pFlowWriter->acknowledgment(message.read7BitValue());
else {
// In fact here, we should send a 0x18 message (with id flow),
// but it can create a loop... We prefer the following behavior
pFlowWriter->fail("ack negative from client");
}
} else
WARN("FlowWriter %u unfound for acknowledgment",id);
break;
}
/// Request
// 0x10 normal request
// 0x11 special request, in repeat case (following stage request)
case 0x10 : {
flags = message.read8();
UInt32 idFlow = message.read7BitValue();
stage = message.read7BitValue()-1;
deltaNAck = message.read7BitValue()-1;
//.........这里部分代码省略.........
示例14: targetPacketHandler
void Middle::targetPacketHandler(PacketReader& packet) {
if(_firstResponse)
_recvTimestamp.update(); // To emulate a long ping corresponding, otherwise client send multiple times each packet
_firstResponse = false;
UInt8 marker = packet.read8();
UInt16 timestamp = packet.read16(); // time
if((marker|0xF0) == 0xFE)
_timeSent = packet.read16(); // time echo
PacketWriter& packetOut = writer();
int pos = packetOut.position();
UInt8 type = packet.available()>0 ? packet.read8() : 0xFF;
UInt32 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.read7BitValue();packetOut.write7BitValue(idFlow);
stage = content.read7BitValue();packetOut.write7BitValue(stage);
} else
++stage;
packetOut.write7BitValue(content.read7BitValue());
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);
UInt32 c = content.read32(); packetOut.write32(c);
//TRACE("Bound %u : %u %u %u",idFlow,a,b,c);
}
if(flagType==0x0b && stage==0x01 && ((marker==0x4e && idFlow==0x03) || (marker==0x8e && idFlow==0x05))) {
/// Replace "middleId" by "peerId"
UInt8 middlePeerIdWanted[ID_SIZE];
content.readRaw(middlePeerIdWanted,ID_SIZE);
++nbPeerSent;
Sessions::Iterator it;
for(it=_sessions.begin();it!=_sessions.end();++it) {
Middle* pMiddle = (Middle*)it->second;
if(pMiddle->middlePeer() == middlePeerIdWanted) {
memcpy(middlePeerIdWanted,pMiddle->peer.id,ID_SIZE);
break;
}
}
packetOut.writeRaw(middlePeerIdWanted,ID_SIZE);
} else if(flagType == 0x01) {
packetOut.writeRaw(content.current(),68);content.next(68);
Entities<Group>::Iterator it;
for(it = _invoker.groups.begin();it!=_invoker.groups.end();++it) {
Group& group = *it->second;
Group::Iterator itP;
for(itP=group.begin();itP!=group.end();++itP) {
if((**itP)==_target.id) {
UInt8 result1[AES_KEY_SIZE];
UInt8 result2[AES_KEY_SIZE];
HMAC(EVP_sha256(),_target.sharedSecret,KEY_SIZE,&_target.initiatorNonce[0],_target.initiatorNonce.size(),result1,NULL);
HMAC(EVP_sha256(),group.id,ID_SIZE,result1,AES_KEY_SIZE,result2,NULL);
packetOut.writeRaw(result2,AES_KEY_SIZE);content.next(AES_KEY_SIZE);
//.........这里部分代码省略.........
示例15: packetHandler
void Middle::packetHandler(PacketReader& packet) {
if(!_pMiddleAesEncrypt) {
DEBUG("500ms sleeping to wait target handshaking");
Thread::sleep(500); // to wait the target handshake response
manage();
}
// 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());
UInt32 idFlow = content.read7BitValue();out.write7BitValue(idFlow);
UInt32 stage = content.read7BitValue();out.write7BitValue(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) {
out.writeRaw(content.current(),71);content.next(71);
Entities<Group>::Iterator it;
for(it = _invoker.groups.begin();it!=_invoker.groups.end();++it) {
Group& group = *it->second;
Group::Iterator itP;
for(itP=group.begin();itP!=group.end();++itP) {
if((**itP)==_target.id) {
UInt8 result1[AES_KEY_SIZE];
UInt8 result2[AES_KEY_SIZE];
HMAC(EVP_sha256(),_sharedSecret,KEY_SIZE,&_targetNonce[0],_targetNonce.size(),result1,NULL);
HMAC(EVP_sha256(),group.id,ID_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);
break;
}
}
if(itP!=group.end())
break;
}
if(it==_invoker.groups.end())
ERROR("Handshake NetGroup packet between peers without corresponding Group");
}
}
}
} else if(type == 0x4C) {
kill();
} else if(type == 0x51) {
//printf("%s\n",Util::FormatHex(content.current(),content.available()).c_str());
}
//.........这里部分代码省略.........