Struct VariantReader
Zero-copy reader for a single variant value. Provides type inspection and typed accessors for primitives, short strings, objects, and arrays.
public ref struct VariantReader
- Inherited Members
Constructors
VariantReader(ReadOnlySpan<byte>, ReadOnlySpan<byte>)
Creates a reader over a variant value.
public VariantReader(ReadOnlySpan<byte> metadata, ReadOnlySpan<byte> value)
Parameters
metadataReadOnlySpan<byte>The variant metadata buffer (shared across all values in a column).
valueReadOnlySpan<byte>The variant value buffer for this specific value.
Properties
BasicType
Gets the basic type of this value.
public VariantBasicType BasicType { get; }
Property Value
Header
Gets the header byte of this value.
public byte Header { get; }
Property Value
IsArray
Returns true if this value is an array.
public bool IsArray { get; }
Property Value
IsBoolean
Returns true if this value is a boolean (true or false).
public bool IsBoolean { get; }
Property Value
IsNull
Returns true if this value is null.
public bool IsNull { get; }
Property Value
IsNumeric
Returns true if this value is a numeric type (any integer, float, double, or decimal).
public bool IsNumeric { get; }
Property Value
IsObject
Returns true if this value is an object.
public bool IsObject { get; }
Property Value
IsString
Returns true if this value is a string (either short string or long string primitive).
public bool IsString { get; }
Property Value
Metadata
Gets the full metadata span.
public ReadOnlySpan<byte> Metadata { get; }
Property Value
PrimitiveType
public VariantPrimitiveType? PrimitiveType { get; }
Property Value
Value
Gets the full value span.
public ReadOnlySpan<byte> Value { get; }
Property Value
Methods
GetBinary()
Gets the binary value as a byte span.
public ReadOnlySpan<byte> GetBinary()
Returns
GetBoolean()
Gets the boolean value.
public bool GetBoolean()
Returns
GetDate()
Gets the date as a DateTime.
public DateTime GetDate()
Returns
GetDateDays()
Gets the date as days since Unix epoch (1970-01-01).
public int GetDateDays()
Returns
GetDecimal16()
Attempts to get a Decimal16 value as a decimal. This may throw OverflowException if the value exceeds 96 bits.
public decimal GetDecimal16()
Returns
GetDecimal16Raw(out byte)
Gets the raw scale and 16-byte unscaled value for a Decimal16. The 16-byte integer may exceed decimal range.
public ReadOnlySpan<byte> GetDecimal16Raw(out byte scale)
Parameters
scalebyteThe scale (number of decimal digits after the point).
Returns
- ReadOnlySpan<byte>
The 16-byte unscaled value in little-endian byte order.
GetDecimal4()
Gets a Decimal4 value (1-byte scale + 4-byte unscaled integer).
public decimal GetDecimal4()
Returns
GetDecimal8()
Gets a Decimal8 value (1-byte scale + 8-byte unscaled integer).
public decimal GetDecimal8()
Returns
GetDouble()
Gets a double value.
public double GetDouble()
Returns
GetFloat()
Gets a float (Float) value.
public float GetFloat()
Returns
GetInt16()
Gets an Int16 value.
public short GetInt16()
Returns
GetInt32()
Gets an Int32 value.
public int GetInt32()
Returns
GetInt64()
Gets an Int64 value.
public long GetInt64()
Returns
GetInt8()
Gets an Int8 value.
public sbyte GetInt8()
Returns
GetSqlDecimal()
Gets a decimal value as a SqlDecimal. Works for Decimal4, Decimal8, and Decimal16 types. Unlike GetDecimal16(), this method does not throw OverflowException for values exceeding 96 bits.
public SqlDecimal GetSqlDecimal()
Returns
GetString()
Gets the string value decoded from UTF-8. Works for both short strings and long string primitives (type 16).
public string GetString()
Returns
GetStringBytes()
Gets the raw UTF-8 bytes of the string value. Works for both short strings and long string primitives (type 16).
public ReadOnlySpan<byte> GetStringBytes()
Returns
GetTimeNtzMicros()
Gets a TimeNTZ value as microseconds since midnight.
public long GetTimeNtzMicros()
Returns
GetTimestamp()
Gets a Timestamp as a DateTimeOffset (UTC).
public DateTimeOffset GetTimestamp()
Returns
GetTimestampMicros()
Gets a Timestamp value as microseconds since Unix epoch (UTC).
public long GetTimestampMicros()
Returns
GetTimestampNtz()
Gets a TimestampNTZ as a DateTime (Unspecified kind).
public DateTime GetTimestampNtz()
Returns
GetTimestampNtzMicros()
Gets a TimestampNTZ value as microseconds since epoch (no timezone).
public long GetTimestampNtzMicros()
Returns
GetTimestampNtzNanos()
Gets a TimestampNtzNanos value as nanoseconds since epoch (no timezone).
public long GetTimestampNtzNanos()
Returns
GetTimestampTzNanos()
Gets a TimestampTzNanos value as nanoseconds since Unix epoch (UTC).
public long GetTimestampTzNanos()
Returns
GetUuid()
Gets the UUID value. The variant encoding stores UUIDs as 16 bytes in big-endian (RFC 4122) byte order.
public Guid GetUuid()
Returns
GetUuidBytes()
Gets the raw 16 UUID bytes in big-endian (RFC 4122) order.
public ReadOnlySpan<byte> GetUuidBytes()
Returns
ToVariantValue()
Materializes this variant value into a VariantValue object. Recursively materializes objects and arrays.
public VariantValue ToVariantValue()
Returns
TryGetDecimal16(out decimal)
Attempts to get a Decimal16 value as a decimal. Returns false if the value exceeds 96 bits instead of throwing.
public bool TryGetDecimal16(out decimal value)
Parameters
valuedecimal