MqttCommand ICommandReader.Read(NetworkConnection connection) { var header = FixedHeader.Load(connection); byte[] data = connection.ReadBytesOrFailAsync(header.RemainingLength).Await().Result; return MqttCommand.Create(header, data); }
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.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); }
internal static int Load(NetworkConnection connection) { int result = 0; int multiplier = 1; int bytesRead = 0; int digit; do { digit = connection.ReadBytesOrFailAsync(1).Await().Result[0]; result += (digit & 127) * multiplier; multiplier *= 128; bytesRead++; } while ((digit & 128) != 0 && (bytesRead < 4)); return(result); }