Struct AvroWriter
Writes Avro binary encoding directly into an IBufferWriter<T> or a fixed Span<T>, without intermediate buffers or per-value allocations.
public ref struct AvroWriter
- Inherited Members
Remarks
When writing to an IBufferWriter<T>, bytes are committed to it in chunks; call Flush() once finished to commit the rest. When writing to a span, BytesWritten gives the length used.
This type is a ref struct: pass it by ref to methods that write values.
It writes values only; it does not check them against a schema.
Constructors
- AvroWriter(IBufferWriter<byte>)
Initializes a writer that appends to
output.
- AvroWriter(Span<byte>)
Initializes a writer over a fixed destination. Writing more than it holds throws AvroException.
Properties
- BytesPending
Gets the number of bytes written but not yet committed to the IBufferWriter<T>.
- BytesWritten
Gets the total number of bytes written, including bytes not yet flushed.
Methods
- Flush()
Commits pending bytes to the IBufferWriter<T>. Does nothing for a span destination.
- WriteBlockCount(long)
Writes the item count that starts an array or map block. Follow it with that many items (or key/value pairs), then more blocks, then WriteBlockEnd().
- WriteBlockEnd()
Writes the zero count that ends an array or map.
- WriteBoolean(bool)
Writes a boolean as one byte, 0 or 1.
- WriteBooleans(scoped ReadOnlySpan<bool>)
Writes
booleanarray items as a single copy, since each item is one byte in memory and on the wire.
- WriteBytes(scoped ReadOnlySpan<byte>)
Writes
bytes: the length as along, then the bytes.
- WriteDouble(double)
Writes a
doubleas 8 little-endian bytes of its IEEE 754 bit pattern.
- WriteDoubles(scoped ReadOnlySpan<double>)
Writes
doublearray items. On little-endian hardware this is a single copy, because Avro's encoding matches the in-memory layout.
- WriteEnum(int)
Writes an enum symbol's zero-based ordinal as an
int.
- WriteFixed(scoped ReadOnlySpan<byte>)
Writes a
fixedvalue: exactly its bytes, with no length prefix.
- WriteFloat(float)
Writes a
floatas 4 little-endian bytes of its IEEE 754 bit pattern.
- WriteFloats(scoped ReadOnlySpan<float>)
Writes
floatarray items. On little-endian hardware this is a single copy, because Avro's encoding matches the in-memory layout.
- WriteInt(int)
Writes an
intas a zig-zag variable-length integer (1 to 5 bytes).
- WriteInts(scoped ReadOnlySpan<int>)
Writes
intarray items, each as a zig-zag varint.
- WriteLong(long)
Writes a
longas a zig-zag variable-length integer (1 to 10 bytes).
- WriteLongs(scoped ReadOnlySpan<long>)
Writes
longarray items, each as a zig-zag varint.
- WriteNull()
Writes
null, which is encoded as zero bytes.
- WriteRaw(scoped ReadOnlySpan<byte>)
Writes bytes as they are, with no length prefix.
- WriteString(scoped ReadOnlySpan<char>)
Writes a
string: the UTF-8 length as along, then the UTF-8 bytes, encoded in place.
- WriteString(string)
Writes a
string: the UTF-8 length as along, then the UTF-8 bytes, encoded in place.
- WriteStringUtf8(scoped ReadOnlySpan<byte>)
Writes a
stringthat is already UTF-8 encoded.
- WriteUnionIndex(int)
Writes the zero-based index of a union branch as an
int.