/// <inheritdoc /> public async Task <ReadStreamResult <T> > ReadAsync(ReadStreamQuery query, TimeSpan timeout, CancellationToken cancellationToken = default) { var result = await client.ReadAsync(query, settings.ApiKeyProvider(), timeout, cancellationToken).ConfigureAwait(false); if (!result.IsSuccessful) { return(new ReadStreamResult <T>(result.Status, null, result.ErrorDetails)); } var payload = result.Payload; try { var events = EventsBinaryReader.Read(payload.Content, settings.EventBuilderProvider, log); return(new ReadStreamResult <T>(result.Status, new ReadStreamPayload <T>(events, payload.Next))); } catch (Exception error) { log.Warn(error); return(new ReadStreamResult <T>(HerculesStatus.UnknownError, null, error.Message)); } finally { payload.Dispose(); } }
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)); }
private HerculesEvent TestSerialization(Action <IHerculesEventBuilder> build) { var memoryBuilder = new HerculesEventBuilder(); memoryBuilder.SetTimestamp(defaultTimestamp); build(memoryBuilder); var memoryEvent = memoryBuilder.BuildEvent(); var binaryWriter = new BinaryBufferWriter(16) { Endianness = Endianness.Big }; binaryWriter.Write(3); for (var i = 0; i < 3; i++) { using (var binaryBuilder = new BinaryEventBuilder(binaryWriter, () => defaultTimestamp, Constants.EventProtocolVersion)) { build(binaryBuilder); } } var events = EventsBinaryReader.Read(binaryWriter.Buffer, 0, _ => new HerculesEventBuilderGeneric(), new SynchronousConsoleLog()); events.Count.Should().Be(3); events.Should().AllBeEquivalentTo(memoryEvent); var dummyEvents = EventsBinaryReader.Read(binaryWriter.Buffer, 0, b => DummyEventBuilder.Instance, new SynchronousConsoleLog()); dummyEvents.Count.Should().Be(3); return(events.Last()); }