public override byte[] Encode() { byte[] frames = EncodeFrames(); List <byte> result = new List <byte>(); result.Add((byte)(Type | (PacketNumber.Size - 1))); result.AddRange(ByteUtilities.GetBytes(Version)); result.Add(DCID); if (DCID > 0) { result.Add(DestinationConnectionId); } result.Add(SCID); if (SCID > 0) { result.Add(SourceConnectionId); } byte[] tokenLength = new VariableInteger(0); byte[] length = new VariableInteger(PacketNumber.Size + (UInt64)frames.Length); result.AddRange(tokenLength); result.AddRange(length); byte[] packetNumber = PacketNumber; result.AddRange(packetNumber); result.AddRange(frames); return(result.ToArray()); }
public override void Decode(ByteArray array) { byte type = array.ReadByte(); byte OFF_BIT = (byte)(type & 0x04); byte LEN_BIT = (byte)(type & 0x02); byte FIN_BIT = (byte)(type & 0x01); StreamId = array.ReadVariableInteger(); if (OFF_BIT > 0) { Offset = array.ReadVariableInteger(); } if (LEN_BIT > 0) { Length = array.ReadVariableInteger(); } if (FIN_BIT > 0) { EndOfStream = true; } StreamData = array.ReadBytes((int)Length.Value); ConvertedStreamId = QuickNet.Utilities.StreamId.Decode(ByteUtilities.GetBytes(Length.Value)); }
public override byte[] Encode() { byte[] frames = EncodeFrames(); List <byte> result = new List <byte>(); result.Add(EncodeTypeField()); result.AddRange(ByteUtilities.GetBytes(Version)); result.Add(DestinationConnectionId.Size); if (DestinationConnectionId.Size > 0) { result.AddRange(DestinationConnectionId.ToByteArray()); } result.Add(SourceConnectionId.Size); if (SourceConnectionId.Size > 0) { result.AddRange(SourceConnectionId.ToByteArray()); } result.AddRange(frames); return(result.ToArray()); }
public override void Decode(ByteArray array) { var type = array.ReadByte(); var offBit = (byte)(type & 0x04); var lenBit = (byte)(type & 0x02); var finBit = (byte)(type & 0x01); StreamId = array.ReadVariableInteger(); if (offBit > 0) { Offset = array.ReadVariableInteger(); } if (lenBit > 0) { Length = array.ReadVariableInteger(); } if (finBit > 0) { EndOfStream = true; } StreamData = array.ReadBytes((int)Length.Value); ConvertedStreamId = QuickNet.Utilities.StreamId.Decode(ByteUtilities.GetBytes(StreamId.Value)); }
public void ByteUtilitiesTest_GetBytes() { var utilities = new ByteUtilities(); var bytes = new byte[] { 97, 32, 90, 32, 51 }; var newBytes = utilities.GetBytes("a Z 3"); Assert.AreEqual(bytes[0], newBytes[0]); Assert.AreEqual(bytes[1], newBytes[1]); Assert.AreEqual(bytes[2], newBytes[2]); Assert.AreEqual(bytes[3], newBytes[3]); Assert.AreEqual(bytes[4], newBytes[4]); newBytes = utilities.GetBytes(""); Assert.AreEqual(0, newBytes.Length); }
public override byte[] Encode() { var frames = EncodeFrames(); var result = new List <byte>(); result.Add(Type); result.Add(DestinationConnectionId); result.AddRange(ByteUtilities.GetBytes(PacketNumber)); result.AddRange(frames); return(result.ToArray()); }
public override byte[] Encode() { List <byte> result = new List <byte>(); result.Add(Type); byte[] streamId = StreamId; result.AddRange(streamId); result.AddRange(ByteUtilities.GetBytes(ApplicationErrorCode)); byte[] offset = FinalOffset; result.AddRange(offset); return(result.ToArray()); }
public override byte[] Encode() { List <byte> result = new List <byte>(); result.Add(Type); byte[] errorCode = ByteUtilities.GetBytes(ErrorCode); result.AddRange(errorCode); if (string.IsNullOrWhiteSpace(ReasonPhrase) == false) { byte[] reasonPhrase = ByteUtilities.GetBytes(ReasonPhrase); byte[] rpl = new VariableInteger((UInt64)ReasonPhrase.Length); result.AddRange(rpl); result.AddRange(reasonPhrase); } return(result.ToArray()); }
public override byte[] Encode() { var frames = EncodeFrames(); var result = new List <byte> { EncodeTypeField() }; result.AddRange(ByteUtilities.GetBytes(Version)); if (DestinationConnectionId > 0) { DcilScil = (byte)(DcilScil | 0x50); } if (SourceConnectionId > 0) { DcilScil = (byte)(DcilScil | 0x05); } result.Add(DcilScil); if (DestinationConnectionId > 0) { result.Add(DestinationConnectionId); } if (SourceConnectionId > 0) { result.Add(SourceConnectionId); } byte[] tokenLength = new VariableInteger(0); byte[] length = new VariableInteger(4 + (ulong)frames.Length); result.AddRange(tokenLength); result.AddRange(length); result.AddRange(ByteUtilities.GetBytes(PacketNumber)); result.AddRange(frames); return(result.ToArray()); }
public override byte[] Encode() { byte[] frames = EncodeFrames(); List <byte> result = new List <byte>(); result.Add(Type); result.AddRange(ByteUtilities.GetBytes(Version)); if (DestinationConnectionId > 0) { DCIL_SCIL = (byte)(DCIL_SCIL | 0x50); } if (SourceConnectionId > 0) { DCIL_SCIL = (byte)(DCIL_SCIL | 0x05); } result.Add(DCIL_SCIL); if (DestinationConnectionId > 0) { result.Add(DestinationConnectionId); } if (SourceConnectionId > 0) { result.Add(SourceConnectionId); } byte[] tokenLength = new VariableInteger(0); byte[] length = new VariableInteger(4 + (UInt64)frames.Length); result.AddRange(tokenLength); result.AddRange(length); result.AddRange(ByteUtilities.GetBytes(PacketNumber)); result.AddRange(frames); return(result.ToArray()); }
public static byte[] Encode(ulong id, StreamType type) { var identifier = (id << 2) | (ulong)type; return(ByteUtilities.GetBytes(identifier)); }