Table of Contents

Struct AvroValue

Namespace
AvroSharp.Generic
Assembly
AvroSharp.dll

Any Avro value in the generic data model, without boxing: primitives are stored inline, and strings, bytes, records, enums, arrays, maps and fixed values by reference.

public readonly struct AvroValue : IEquatable<AvroValue>
Implements
Inherited Members

Remarks

The struct is 16 bytes. Primitive values are kept in a 64-bit field and identified by a shared marker object; for every other kind, the reference itself identifies the kind. An enum stores its schema and ordinal, so enum values do not allocate.

Logical types are represented by their underlying Avro type: a date is an Int, a timestamp-micros a Long, a decimal its Bytes.

Arrays are held as IReadOnlyList<T> and maps as IReadOnlyDictionary<TKey, TValue>; the reader creates List<T> and Dictionary<TKey, TValue> instances.

Arrays of boolean, int, long, float and double items are held as the primitive values themselves: the reader creates them this way, and FromInt64Array(ReadOnlyMemory<long>) and the other typed factories wrap existing memory. AsArray() still returns their items as values, and TryGetInt64Array(out ReadOnlyMemory<long>) and the other typed accessors return the memory without a copy.

Factories and accessors pair by name: From… creates what As… returns. Primitives are named after their .NET type (FromInt32(int) and AsInt32(), Int64, Single, Double, Boolean, String), and the other kinds after their Avro type (FromBytes(byte[]?), Record, Fixed, Array, Map, Enum).

Properties

EnumSchema

Gets the enum schema when this is an enum value; otherwise null.

IsNull

Gets a value indicating whether this is the Avro null value.

Kind

Gets the kind of value.

Null

Gets the Avro null value (the default value of this struct).

Methods

AsArray()

Gets the array items.

AsBoolean()

Gets the boolean.

AsBytes()

Gets the bytes (not a copy).

AsDouble()

Gets the value as a double; a float is widened.

AsEnumOrdinal()

Gets the enum ordinal.

AsEnumSymbol()

Gets the enum symbol.

AsFixed()

Gets the fixed value.

AsInt32()

Gets the int.

AsInt64()

Gets the value as a long; an int is widened.

AsMap()

Gets the map entries.

AsRecord()

Gets the record.

AsSingle()

Gets the float.

AsString()

Gets the string.

Equals(AvroValue)

Compares structurally: same kind and equal contents. Floating-point values compare by bit pattern (so NaN equals NaN), byte arrays and fixed values by content, arrays in order, maps by key, records by schema name and field values, enums by schema name and ordinal.

Equals(object?)

Indicates whether this instance and a specified object are equal.

FromArray(IReadOnlyList<AvroValue>)

Creates an array value from a list (for example a List<T> or an array). The list is not copied.

FromBoolean(bool)

Creates a boolean value.

FromBooleanArray(ReadOnlyMemory<bool>)

Creates an array of boolean items, stored as they are. The memory is not copied.

FromBytes(byte[]?)

Creates a bytes value, or null. The array is not copied.

FromDouble(double)

Creates a double value.

FromDoubleArray(ReadOnlyMemory<double>)

Creates an array of double items, stored as they are. The memory is not copied.

FromEnum(EnumSchema, int)

Creates an enum value from its ordinal.

FromEnum(EnumSchema, string)

Creates an enum value from its symbol.

FromFixed(GenericFixed?)

Creates a fixed value, or null.

FromInt32(int)

Creates an int value.

FromInt32Array(ReadOnlyMemory<int>)

Creates an array of int items, stored as they are. The memory is not copied.

FromInt64(long)

Creates a long value.

FromInt64Array(ReadOnlyMemory<long>)

Creates an array of long items, stored as they are. The memory is not copied.

FromMap(IReadOnlyDictionary<string, AvroValue>)

Creates a map value from a dictionary (for example a Dictionary<TKey, TValue>). The dictionary is not copied.

FromRecord(GenericRecord?)

Creates a record value, or null.

FromSingle(float)

Creates a float value.

FromSingleArray(ReadOnlyMemory<float>)

Creates an array of float items, stored as they are. The memory is not copied.

FromString(string?)

Creates a string value, or null.

GetHashCode()

Returns the hash code for this instance.

ToObject()

Returns the value boxed as a CLR object: null, a primitive, or the referenced object.

ToString()

Returns the fully qualified type name of this instance.

TryGetBooleanArray(out ReadOnlyMemory<bool>)

Gets the items of an array stored as boolean values, without a copy.

TryGetDoubleArray(out ReadOnlyMemory<double>)

Gets the items of an array stored as double values, without a copy.

TryGetInt32Array(out ReadOnlyMemory<int>)

Gets the items of an array stored as int values, without a copy.

TryGetInt64Array(out ReadOnlyMemory<long>)

Gets the items of an array stored as long values, without a copy.

TryGetSingleArray(out ReadOnlyMemory<float>)

Gets the items of an array stored as float values, without a copy.

Operators

operator ==(AvroValue, AvroValue)

Compares two values structurally (see Equals(AvroValue)).

implicit operator AvroValue(GenericFixed?)

Creates a fixed value, or null.

implicit operator AvroValue(GenericRecord?)

Creates a record value, or null.

implicit operator AvroValue(bool)

Creates a boolean value.

implicit operator AvroValue(byte[]?)

Creates a bytes value, or null for a null array. The array is not copied.

implicit operator AvroValue(double)

Creates a double value.

implicit operator AvroValue(int)

Creates an int value.

implicit operator AvroValue(long)

Creates a long value.

implicit operator AvroValue(float)

Creates a float value.

implicit operator AvroValue(string?)

Creates a string value, or null for a null string.

operator !=(AvroValue, AvroValue)

Compares two values structurally.

See Also