Inheritance: AbstractFrameBase
Esempio n. 1
0
        public void Stream1ClientInchoateGoogleCachedServerParametersClientMessage()
        {
            var tags = Messages.ClientHandshakeMessageTest.ClientInchoateGoogleCachedServerParametersClientMessageFactory.Value;
            var message2 = new ClientHandshakeMessage(tags);
            var messageBytes2 = message2.ToByteArray();

            var stream = new StreamFrame(1, 0);
            stream.SetData(messageBytes2, false);

            var streamBytes = stream.ToByteArray();
            Assert.IsNotNull(streamBytes);
            Debug.WriteLine(streamBytes.GenerateHexDumpWithASCII());

            //Assert.AreEqual(streamBytes.Length, FrameLibrary.ClientInchoateGoogleCachedServerParametersStream1Subset.Length);

            // Soft warn
            for (var i = 0; i < streamBytes.Length; i++)
            {
                if (streamBytes[i] != FrameLibrary.ClientInchoateGoogleCachedServerParametersStream1Subset[i])
                    Debug.WriteLine($"Byte difference at position {i}: generated byte is {streamBytes[i]:x2} but reference byte was {FrameLibrary.ClientInchoateGoogleCachedServerParametersStream1Subset[i]:x2}");
            }

            // Hard test fail
            for (var i = 0; i < streamBytes.Length; i++)
            {
                Assert.AreEqual(streamBytes[i], FrameLibrary.ClientInchoateGoogleCachedServerParametersStream1Subset[i], $"Byte difference at position {i}: generated byte is {streamBytes[i]:x2} but reference byte was {FrameLibrary.ClientInchoateGoogleCachedServerParametersStream1Subset[i]:x2}");
            }
        }
Esempio n. 2
0
        public static Tuple <StreamFrame, int> FromByteArray(byte[] bytes, int index)
        {
            var finFlag        = (bytes[index] & (1 << 6)) != 0;
            var dataLengthFlag = (bytes[index] & (1 << 5)) != 0;
            var olenIndex      = (bytes[index] >> 2) & 7;

            var frame = new StreamFrame
            {
                Fin   = finFlag,
                _olen = (byte)(olenIndex == 0 ? 0 : olenIndex + 1),
                _slen = (byte)(bytes[index] & 3)
            };

            switch (frame._slen)
            {
            case 0:
                frame._streamId = bytes[index + 1];
                break;

            case 1:
                frame._streamId = BitConverter.ToUInt16(bytes, index + 1);
                break;

            case 2:
                var buf = new byte[4];
                Array.Copy(bytes, index + 1, buf, 1, 3);
                frame._streamId = BitConverter.ToUInt32(buf, 0);
                break;

            case 3:
                frame._streamId = BitConverter.ToUInt32(bytes, index + 1);
                break;
            }

            // ReSharper disable PossibleInvalidOperationException
            frame._metadataLength = 1 + (frame._slen.Value + 1) + (frame._olen.Value == 0 ? 0 : frame._olen.Value + 1) + (dataLengthFlag ? 2 : 0);
            // ReSharper restore PossibleInvalidOperationException

            index += frame._metadataLength.Value;
            var dataLength = dataLengthFlag ? BitConverter.ToUInt16(bytes, index - 2) : bytes.Length - index - 1;

            frame._data = new byte[dataLength];
            Array.Copy(bytes, index, frame._data, 0, dataLength);
            index += dataLength;

            return(new Tuple <StreamFrame, int>(frame, index));
        }
Esempio n. 3
0
        public static Tuple<StreamFrame, int> FromByteArray(byte[] bytes, int index)
        {
            var finFlag = (bytes[index] & (1 << 6)) != 0;
            var dataLengthFlag = (bytes[index] & (1 << 5)) != 0;
            var olenIndex = (bytes[index] >> 2) & 7;

            var frame = new StreamFrame
                        {
                            Fin = finFlag,
                            _olen = (byte)(olenIndex == 0 ? 0 : olenIndex + 1),
                            _slen = (byte)(bytes[index] & 3)
                        };

            switch (frame._slen)
            {
                case 0:
                    frame._streamId = bytes[index + 1];
                    break;
                case 1:
                    frame._streamId = BitConverter.ToUInt16(bytes, index + 1);
                    break;
                case 2:
                    var buf = new byte[4];
                    Array.Copy(bytes, index + 1, buf, 1, 3);
                    frame._streamId = BitConverter.ToUInt32(buf,0);
                    break;
                case 3:
                    frame._streamId = BitConverter.ToUInt32(bytes, index + 1);
                    break;
            }

            // ReSharper disable PossibleInvalidOperationException
            frame._metadataLength = 1 + (frame._slen.Value + 1) + (frame._olen.Value == 0 ? 0 : frame._olen.Value + 1) + (dataLengthFlag ? 2 : 0);
            // ReSharper restore PossibleInvalidOperationException

            index += frame._metadataLength.Value;
            var dataLength = dataLengthFlag ? BitConverter.ToUInt16(bytes, index - 2) : bytes.Length - index - 1;
            frame._data = new byte[dataLength];
            Array.Copy(bytes, index, frame._data, 0, dataLength);
            index += dataLength;

            return new Tuple<StreamFrame, int>(frame, index);
        }