public static FixedHeader Load(NetworkConnection connection) { byte firstByte = connection.ReadBytesOrFailAsync(1).Await().Result[0]; var header = new FixedHeader { Message = (CommandMessage)((firstByte & 0xF0) >> 4), Duplicate = (firstByte & 0x8) == 0x8, QualityOfService = (QualityOfService)((firstByte & 0x6) >> 1), Retain = (firstByte & 0x1) == 0x1, RemainingLength = VariableLengthInteger.Load(connection) }; return(header); }
public static FixedHeader Load(NetworkConnection connection) { byte firstByte = connection.Stream.ReadBytesOrFailAsync(1).Await <byte[]>().Result[0]; FixedHeader header = new FixedHeader(); header.Message = (CommandMessage)((firstByte & 0xF0) >> 4); header.Duplicate = (firstByte & 0x8) == 0x8; header.QualityOfService = (QualityOfService)((firstByte & 0x6) >> 1); header.Retain = (firstByte & 0x1) == 0x1; header.RemainingLength = VariableLengthInteger.Load(connection); return(header); }
public byte[] ToByteArray() { int firstByte = 0; firstByte |= ((int)Message << 4); if (Duplicate) { firstByte |= 0x8; } firstByte |= ((int)QualityOfService << 1); if (Retain) { firstByte++; } var bytes = new List <byte>(); bytes.Add((byte)firstByte); bytes.AddRange(VariableLengthInteger.ToByteArray(RemainingLength)); return(bytes.ToArray()); }