Class AvroStreamReader<T>
Reads objects written one after another in the binary encoding, with no container, framing or lengths, until the stream ends: data from a socket or a pipe, or a file of concatenated objects. The objects' schema is not in the stream; the caller supplies it. See AvroStreamWriter<T> for writing such a stream.
public sealed class AvroStreamReader<T> : IDisposable, IAsyncDisposable
Type Parameters
TThe type of the objects.
- Inheritance
-
AvroStreamReader<T>
- Implements
- Inherited Members
Remarks
Nothing in the encoding marks where an object ends, so each is decoded to find its end. When the buffered data
ends inside an object, more is read and the object is decoded again from its start, once the bytes of a string,
bytes or fixed value it was cut off in have arrived. A stream that returns a few bytes per read still costs one
decode per read for objects of many small values; a lower MaxDatumLength bounds that
for untrusted peers. Only when the stream has ended, or MaxDatumLength bytes are
buffered, is a failure reported: truncated and corrupt data look alike until then. Objects that encode to no bytes
(a null schema, an empty record) cannot be delimited, and reading one is an error.
The asynchronous members do no synchronous I/O; each object is decoded synchronously once it is in memory. Instances are not thread-safe.
Properties
- Position
Gets the number of bytes of the stream that the objects read so far took.
Methods
- Dispose()
Releases the buffer and, unless the options say otherwise, disposes the stream.
- DisposeAsync()
Releases the buffer and, unless the options say otherwise, disposes the stream asynchronously.
- ReadAll()
Reads the objects to the end of the stream.
- ReadAllAsync(CancellationToken)
Reads the objects to the end of the stream asynchronously.
- TryRead(out T)
Reads the next object.