Table of Contents

Struct AvroReader

Namespace
AvroSharp.IO
Assembly
AvroSharp.dll

Reads Avro binary encoding from a ReadOnlySpan<T> or a (possibly multi-segment) ReadOnlySequence<T>.

public ref struct AvroReader
Inherited Members

Remarks

Reads from contiguous data never copy or allocate: ReadBytesSpan() and ReadFixedSpan(int) return slices of the input. Only a value that straddles two segments of a sequence is copied.

Every length prefix is checked against the remaining input before anything is allocated, so malformed or hostile input cannot trigger large allocations. Errors are reported as AvroDataException.

This type is a ref struct: pass it by ref to methods that read values.

Constructors

AvroReader(in ReadOnlySequence<byte>)

Initializes a reader over a sequence of buffers, such as the result of a PipeReader read.

AvroReader(ReadOnlySpan<byte>)

Initializes a reader over contiguous data.

Properties

BytesConsumed

Gets the number of bytes read so far.

BytesRemaining

Gets the number of bytes left to read.

IsAtEnd

Gets a value indicating whether all input has been read.

Methods

ReadBlockCount(out long)

Reads the header of an array or map block: the number of items, or 0 at the end of the array or map.

ReadBoolean()

Reads a boolean encoded as one byte, 0 or 1.

ReadBooleans(scoped Span<bool>)

Reads boolean array items into destination. Contiguous input is checked and copied as one span, since each item is one byte.

ReadBytes()

Reads bytes into a new array.

ReadBytesSpan()

Reads bytes and returns them without copying when they are contiguous in the input (always, for span input). A value that straddles sequence segments is copied into a new array.

ReadDouble()

Reads a double from 8 little-endian bytes.

ReadDoubles(scoped Span<double>)

Reads double array items into destination. On little-endian hardware, contiguous input is a single copy.

ReadEnum()

Reads an enum symbol's zero-based ordinal.

ReadFixed(scoped Span<byte>)

Reads a fixed value into destination, whose length is the schema's size.

ReadFixedSpan(int)

Reads a fixed value of size bytes, without copying when contiguous.

ReadFloat()

Reads a float from 4 little-endian bytes.

ReadFloats(scoped Span<float>)

Reads float array items into destination. On little-endian hardware, contiguous input is a single copy.

ReadInt()

Reads a zig-zag variable-length int.

ReadInts(scoped Span<int>)

Reads destination.Length int values, such as the items of an array block. Uses the same vector check for one-byte values as ReadLongs(scoped Span<long>).

ReadLong()

Reads a zig-zag variable-length long.

ReadLongs(scoped Span<long>)

Reads destination.Length long values, such as the items of an array block.

ReadNull()

Reads null, which is encoded as zero bytes.

ReadString()

Reads a string and decodes it from UTF-8. Invalid UTF-8 is replaced with U+FFFD.

ReadStringUtf8()

Reads a string as UTF-8 bytes, without decoding and, when contiguous, without copying.

ReadUnionIndex()

Reads the zero-based index of a union branch.

SkipBytes()

Skips a bytes or string value.

SkipRaw(long)

Skips count raw bytes, for example a fixed value or a sized array block. To skip an Avro bytes value, with its length, use SkipBytes().

SkipVarint()

Skips a variable-length int or long.

See Also