예제 #1
0
        MqttCommand ICommandReader.Read(NetworkConnection connection)
        {
            var header = FixedHeader.Load(connection);

            byte[] data = connection.ReadBytesOrFailAsync(header.RemainingLength).Await().Result;

            return MqttCommand.Create(header, data);
        }
예제 #2
0
파일: FixedHeader.cs 프로젝트: 4058665/MQTT
        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;
        }
예제 #3
0
파일: FixedHeader.cs 프로젝트: hezlog/MQTT
        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);
        }
예제 #4
0
        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);
        }