Beispiel #1
0
        private async ValueTask ReadFrameAsync(CancellationToken cancellationToken)
        {
            UpdateKnownMessageSize(-1);
            await InnerTransport.ReadAllAsync(HeaderBuf, 0, HeaderSize, cancellationToken);

            int size = BinaryPrimitives.ReadInt32BigEndian(HeaderBuf);

            if ((0 > size) || (size > Configuration.MaxFrameSize))  // size must be in the range 0 to allowed max
            {
                throw new TTransportException(TTransportException.ExceptionType.Unknown, $"Maximum frame size exceeded ({size} bytes)");
            }
            UpdateKnownMessageSize(size + HeaderSize);

            ReadBuffer.SetLength(size);
            ReadBuffer.Seek(0, SeekOrigin.Begin);

            ReadBuffer.TryGetBuffer(out ArraySegment <byte> bufSegment);
            await InnerTransport.ReadAllAsync(bufSegment.Array, 0, size, cancellationToken);
        }