public static Info Deserialize(IInOctetStream stream) { var packetSequenceId = stream.ReadUint8(); var receivedByRemoteSequenceId = stream.ReadUint8(); var receiveMask = stream.ReadUint32(); var header = new Header(new SequenceId(receivedByRemoteSequenceId), new ReceiveMask(receiveMask)); var info = new Info { PacketId = new SequenceId(packetSequenceId), Header = header }; return(info); }
public static string Deserialize(IInOctetStream stream) { var myNonce = stream.ReadUint8(); var characters = stream.ReadOctets(myNonce); return(Encoding.UTF8.GetString(characters)); }
void ReadOOB(IInOctetStream stream, long packetTime) { var cmd = stream.ReadUint8(); switch (cmd) { case CommandValues.ChallengeResponse: OnChallengeResponse(stream); break; case CommandValues.ConnectResponse: OnConnectResponse(stream); break; case CommandValues.TimeSyncResponse: OnTimeSyncResponse(stream); break; case CommandValues.PongResponse: OnPongResponse(stream, packetTime); break; default: throw new Exception($"Unknown command {cmd}"); } }
public static CustomConnectPayload Deserialize(IInOctetStream stream) { var octetCount = stream.ReadUint8(); var octets = stream.ReadOctets(octetCount); return(new CustomConnectPayload { Payload = octets }); }
void ReadHeader(IInOctetStream stream, byte mode, int packetOctetCount, long nowMs) { var sequence = stream.ReadUint8(); var assignedConnectionId = stream.ReadUint16(); if (assignedConnectionId == 0) { ReadOOB(stream, nowMs); } else { if (assignedConnectionId == connectionId) { var headerSequenceId = new SequenceId(sequence); if (lastIncomingSequence.IsValidSuccessor(headerSequenceId)) { var diff = lastIncomingSequence.Distance(headerSequenceId); var timeStamp = DateTime.UtcNow; if (diff > 1) { inStatsCollector.PacketsDropped(timeStamp, diff - 1); } inStatsCollector.PacketReceived(timeStamp, packetOctetCount); simpleIn.AddPacket(packetOctetCount); lastIncomingSequence = headerSequenceId; if (mode == OobMode) { ReadOOB(stream, nowMs); } else { ReadConnectionPacket(stream, nowMs); } } } } lastValidHeader = monotonicClock.NowMilliseconds(); }