Struct AvroReader
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
PipeReaderread.
- 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
booleanarray items intodestination. Contiguous input is checked and copied as one span, since each item is one byte.
- ReadBytes()
Reads
bytesinto a new array.
- ReadBytesSpan()
Reads
bytesand 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
doublefrom 8 little-endian bytes.
- ReadDoubles(scoped Span<double>)
Reads
doublearray items intodestination. 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
fixedvalue intodestination, whose length is the schema's size.
- ReadFixedSpan(int)
Reads a
fixedvalue ofsizebytes, without copying when contiguous.
- ReadFloat()
Reads a
floatfrom 4 little-endian bytes.
- ReadFloats(scoped Span<float>)
Reads
floatarray items intodestination. On little-endian hardware, contiguous input is a single copy.
- ReadInt()
Reads a zig-zag variable-length
int.
- ReadInts(scoped Span<int>)
Reads
destination.Lengthintvalues, 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.Lengthlongvalues, such as the items of an array block.
- ReadNull()
Reads
null, which is encoded as zero bytes.
- ReadString()
Reads a
stringand decodes it from UTF-8. Invalid UTF-8 is replaced with U+FFFD.
- ReadStringUtf8()
Reads a
stringas UTF-8 bytes, without decoding and, when contiguous, without copying.
- ReadUnionIndex()
Reads the zero-based index of a union branch.
- SkipBytes()
Skips a
bytesorstringvalue.
- SkipRaw(long)
Skips
countraw bytes, for example afixedvalue or a sized array block. To skip an Avrobytesvalue, with its length, use SkipBytes().
- SkipVarint()
Skips a variable-length
intorlong.