Struct AvroValue
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
nullvalue.
- Kind
Gets the kind of value.
- Null
Gets the Avro
nullvalue (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; afloatis 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; anintis 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
booleanitems, stored as they are. The memory is not copied.
- FromBytes(byte[]?)
Creates a
bytesvalue, ornull. The array is not copied.
- FromDouble(double)
Creates a
doublevalue.
- FromDoubleArray(ReadOnlyMemory<double>)
Creates an array of
doubleitems, 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
intvalue.
- FromInt32Array(ReadOnlyMemory<int>)
Creates an array of
intitems, stored as they are. The memory is not copied.
- FromInt64(long)
Creates a
longvalue.
- FromInt64Array(ReadOnlyMemory<long>)
Creates an array of
longitems, 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
floatvalue.
- FromSingleArray(ReadOnlyMemory<float>)
Creates an array of
floatitems, stored as they are. The memory is not copied.
- FromString(string?)
Creates a
stringvalue, ornull.
- 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
booleanvalues, without a copy.
- TryGetDoubleArray(out ReadOnlyMemory<double>)
Gets the items of an array stored as
doublevalues, without a copy.
- TryGetInt32Array(out ReadOnlyMemory<int>)
Gets the items of an array stored as
intvalues, without a copy.
- TryGetInt64Array(out ReadOnlyMemory<long>)
Gets the items of an array stored as
longvalues, without a copy.
- TryGetSingleArray(out ReadOnlyMemory<float>)
Gets the items of an array stored as
floatvalues, 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
bytesvalue, ornullfor a null array. The array is not copied.
- implicit operator AvroValue(double)
Creates a
doublevalue.
- implicit operator AvroValue(int)
Creates an
intvalue.
- implicit operator AvroValue(long)
Creates a
longvalue.
- implicit operator AvroValue(float)
Creates a
floatvalue.
- implicit operator AvroValue(string?)
Creates a
stringvalue, ornullfor a null string.
- operator !=(AvroValue, AvroValue)
Compares two values structurally.