private static void TestSerialization(TimelineCoordinates coordinates)
        {
            var writer = new BinaryBufferWriter(1)
            {
                Endianness = Endianness.Big
            };

            TimelineCoordinatesWriter.Write(coordinates, writer);

            var reader = new BinaryBufferReader(writer.Buffer, 0)
            {
                Endianness = Endianness.Big
            };

            var deserialized = TimelineCoordinatesReader.Read(reader);

            deserialized.Positions.Length.Should().Be(coordinates.Positions.Length);

            for (var i = 0; i < deserialized.Positions.Length; i++)
            {
                deserialized.Positions[i].Slice.Should().Be(coordinates.Positions[i].Slice);
                deserialized.Positions[i].Offset.Should().Be(coordinates.Positions[i].Offset);
                deserialized.Positions[i].EventId.Should().Equal(coordinates.Positions[i].EventId);
            }
        }
Пример #2
0
        private static SeekToEndStreamPayload ParseSeekToEndResponseBody([NotNull] Response response)
        {
            var reader = new BinaryBufferReader(response.Content.Buffer, response.Content.Offset)
            {
                Endianness = Endianness.Big
            };

            var coordinates = StreamCoordinatesReader.Read(reader);

            return(new SeekToEndStreamPayload(coordinates));
        }
Пример #3
0
        public BinaryStreamReader(Stream stream)
        {
            this.stream = stream ?? throw new ArgumentNullException(nameof(stream));

            if (!stream.CanRead)
            {
                throw new AggregateException($"Input stream of type '{stream.GetType().Name}' was not readable.");
            }

            buffer = new BinaryBufferReader(new byte[BufferSize], 0);
        }
        private ReadTimelinePayload <T> ParseResponseBody([NotNull] Response response)
        {
            var reader = new BinaryBufferReader(response.Content.Buffer, response.Content.Offset)
            {
                Endianness = Endianness.Big
            };

            var coordinates = TimelineCoordinatesReader.Read(reader);

            var events = EventsBinaryReader.Read(response.Content.Buffer, reader.Position, eventBuilderProvider, log);

            return(new ReadTimelinePayload <T>(events, coordinates));
        }
Пример #5
0
        private static void TestSerialization(StreamCoordinates coordinates)
        {
            var writer = new BinaryBufferWriter(1)
            {
                Endianness = Endianness.Big
            };

            StreamCoordinatesWriter.Write(coordinates, writer);

            var reader = new BinaryBufferReader(writer.Buffer, 0)
            {
                Endianness = Endianness.Big
            };

            StreamCoordinatesReader.Read(reader).Should().BeEquivalentTo(coordinates);
        }
Пример #6
0
        private RawReadStreamPayload ParseReadResponseBody([NotNull] Response response)
        {
            try
            {
                var reader = new BinaryBufferReader(response.Content.Buffer, response.Content.Offset)
                {
                    Endianness = Endianness.Big
                };

                var coordinates = StreamCoordinatesReader.Read(reader);

                var content = new ValueDisposable <ArraySegment <byte> >(
                    new ArraySegment <byte>(response.Content.Buffer, (int)reader.Position, (int)(response.Content.Length - reader.Position)),
                    new ActionDisposable(() => bufferPool.Return(response.Content.Buffer)));

                return(new RawReadStreamPayload(content, coordinates));
            }
            catch (Exception)
            {
                bufferPool.Return(response.Content.Buffer);
                throw;
            }
        }