Esempio n. 1
0
        public void Framelet_Getters_ReturnConstructorValues()
        {
            var framelet = new Framelet(FrameletType.PayloadData, AnyContents);

            Assert.AreEqual(FrameletType.PayloadData, framelet.Type);
            Assert.AreEqual(AnyContents, framelet.Contents);
        }
Esempio n. 2
0
File: Frame.cs Progetto: ikvm/bond
        public static async Task <Frame> ReadAsync(Stream stream, CancellationToken ct)
        {
            try
            {
                var frameletCount = await ReadUInt16Async(stream, ct);

                if (frameletCount == 0)
                {
                    throw new EpoxyProtocolErrorException("Zero framelets");
                }

                var frame = new Frame(frameletCount);

                while (frameletCount > 0)
                {
                    if (ct.IsCancellationRequested)
                    {
                        return(null);
                    }

                    var frameletType = await ReadUInt16Async(stream, ct);

                    if (!Framelet.IsKnownType(frameletType))
                    {
                        throw new EpoxyProtocolErrorException("Unknown framelet type: " + frameletType);
                    }

                    var frameletLength = await ReadUInt32Async(stream, ct);

                    if (frameletLength > int.MaxValue)
                    {
                        throw new EpoxyProtocolErrorException("Framelet too big: " + frameletLength);
                    }

                    byte[] frameletContents = await ReadBufferAsync(stream, unchecked ((int)frameletLength), ct);

                    frame.Add(new Framelet((FrameletType)frameletType, new ArraySegment <byte>(frameletContents)));

                    --frameletCount;
                }

                return(frame);
            }
            catch (Exception ex) when(ex is OperationCanceledException || ex is EndOfStreamException || ex is ObjectDisposedException)
            {
                return(null);
            }
        }
Esempio n. 3
0
        public void Add(Framelet framelet)
        {
            if (framelets.Count == UInt16.MaxValue)
            {
                var message = logger.Site().ErrorAndReturnFormatted("Exceeded maximum allowed count of framelets.");
                throw new InvalidOperationException(message);
            }

            try
            {
                // add space for framelet type, length of payload, and actual payload content
                TotalSize = checked (TotalSize + sizeof(UInt16) + sizeof(UInt32) + framelet.Contents.Count);
                framelets.Add(framelet);
            }
            catch (OverflowException oex)
            {
                var message = logger.Site().ErrorAndReturnFormatted("Exceeded maximum size of frame.");
                throw new InvalidOperationException(message, oex);
            }
        }
Esempio n. 4
0
        public void Add(Framelet framelet)
        {
            if (framelets.Count == UInt16.MaxValue)
            {
                var message = logger.Site().ErrorAndReturnFormatted("Exceeded maximum allowed count of framelets.");
                throw new InvalidOperationException(message);
            }

            try
            {
                // add space for framelet type, length of payload, and actual payload content
                TotalSize = checked(TotalSize + sizeof(UInt16) + sizeof(UInt32) + framelet.Contents.Count);
                framelets.Add(framelet);
            }
            catch (OverflowException oex)
            {
                var message = logger.Site().ErrorAndReturnFormatted("Exceeded maximum size of frame.");
                throw new InvalidOperationException(message, oex);
            }
        }