confluent-kafka-dotnet
Show / Hide Table of Contents

Class Variant

A read-only view over a Variant (a Spark/Parquet Variant: a metadata key-dictionary plus a self-describing value stream) at a byte position. Navigation (GetFieldByKey(string) / GetElementAtIndex(int)) returns a sub-Variant sharing the same buffers. This is the .NET counterpart of Java's io.confluent.kafka.schemaregistry.type.Variant; it lives in the core package so the Avro and Protobuf serdes can use it without a Rules dependency.

ToJson() renders temporal types as ISO-8601 with the seconds field always present (0/3/6/9-digit fractional grouping) and decimals in fixed-point - the cross-language contract. ParseJson(string) follows Java number handling: a fractional JSON number becomes a DOUBLE, an integer wider than 64 bits a scale-0 decimal.

Inheritance
object
Variant
Inherited Members
object.Equals(object, object)
object.GetType()
object.ReferenceEquals(object, object)
object.ToString()
Namespace: Confluent.SchemaRegistry
Assembly: Confluent.SchemaRegistry.dll
Syntax
public sealed class Variant

Constructors

Variant(byte[], byte[])

Construct from raw value + metadata byte arrays.

Declaration
public Variant(byte[] value, byte[] metadata)
Parameters
Type Name Description
byte[] value
byte[] metadata

Properties

MetadataBytes

The raw metadata bytes (the key dictionary).

Declaration
public byte[] MetadataBytes { get; }
Property Value
Type Description
byte[]

StandaloneValueBytes

The value bytes from this node's start - the form a navigated sub-variant re-encodes as, and what any write-back has to use.

ValueBytes is the whole buffer, shared across sub-variants, so a navigated variant's own value begins at Confluent.SchemaRegistry.Variant.Position. Handing ValueBytes to an encoder therefore writes the *parent root* rather than the selected value - measured, a field navigated out of {"a":1,"secret":"..."} came back as the whole document. The other clients all have this accessor already (Go's StandaloneValueBytes, C++'s standaloneValueBytes, Rust's standalone_value_bytes), and Java's getValueBuffer is a positioned ByteBuffer.

Like all of those, this slices to the end of the buffer rather than to the node's exact extent, so a navigated value still carries its later siblings' bytes. Decoding ignores them - the encoding is self-delimiting - and trimming needs a value-size walk that only the reference currently has.

Declaration
public byte[] StandaloneValueBytes { get; }
Property Value
Type Description
byte[]

ValueBytes

The raw value bytes (the whole buffer, shared across sub-variants).

Declaration
public byte[] ValueBytes { get; }
Property Value
Type Description
byte[]

Methods

Equals(object)

Equality is over the encoding: the metadata bytes and the value bytes from Confluent.SchemaRegistry.Variant.Position. The same comparison a confluent.type.Variant protobuf message already gets, so a variant read from a field and one built by variants.parseJson answer the same way.

Declaration
public override bool Equals(object obj)
Parameters
Type Name Description
object obj
Returns
Type Description
bool
Overrides
object.Equals(object)

GetBinary()

Declaration
public byte[] GetBinary()
Returns
Type Description
byte[]

GetBoolean()

Declaration
public bool GetBoolean()
Returns
Type Description
bool

GetByte()

The signed 8-bit integer of an INT8 value (exact width; no widening).

Declaration
public sbyte GetByte()
Returns
Type Description
sbyte

GetDecimal()

The decimal value (unscaled integer and scale) as a BigDecimal.

Declaration
public BigDecimal GetDecimal()
Returns
Type Description
BigDecimal

GetDecimalParts(out BigInteger, out int)

The unscaled integer and scale of a decimal value (scale preserved).

Declaration
public void GetDecimalParts(out BigInteger unscaled, out int scale)
Parameters
Type Name Description
BigInteger unscaled
int scale

GetDouble()

The 64-bit double of a DOUBLE value (exact; does not widen FLOAT).

Declaration
public double GetDouble()
Returns
Type Description
double

GetElementAtIndex(int)

The array element at index, or null if out of bounds.

Declaration
public Variant GetElementAtIndex(int index)
Parameters
Type Name Description
int index
Returns
Type Description
Variant

GetFieldAtIndex(int)

The (key, value) of the field at idx (key-sorted).

Declaration
public KeyValuePair<string, Variant> GetFieldAtIndex(int idx)
Parameters
Type Name Description
int idx
Returns
Type Description
KeyValuePair<string, Variant>

GetFieldByKey(string)

The object field with the given key, or null if absent.

Declaration
public Variant GetFieldByKey(string key)
Parameters
Type Name Description
string key
Returns
Type Description
Variant

GetFloat()

The 32-bit float of a FLOAT value (exact; does not read DOUBLE).

Declaration
public float GetFloat()
Returns
Type Description
float

GetHashCode()

Serves as the default hash function.

Declaration
public override int GetHashCode()
Returns
Type Description
int

A hash code for the current object.

Overrides
object.GetHashCode()

GetInt()

The signed 32-bit integer of an INT8/INT16/INT32 value (widens within 32 bits).

Declaration
public int GetInt()
Returns
Type Description
int

GetLong()

The raw integer for any integer-backed type (byte/short/int/long, date days, timestamp micros, time micros, timestamp-nanos) - mirrors Java getLong.

Declaration
public long GetLong()
Returns
Type Description
long

GetShort()

The signed 16-bit integer of an INT8/INT16 value (widens within 16 bits).

Declaration
public short GetShort()
Returns
Type Description
short

GetString()

Declaration
public string GetString()
Returns
Type Description
string

GetUuid()

The UUID as its canonical big-endian hex string (e.g. "00112233-...").

Declaration
public string GetUuid()
Returns
Type Description
string

GetVariantType()

Declaration
public VariantType GetVariantType()
Returns
Type Description
VariantType

NumArrayElements()

Declaration
public int NumArrayElements()
Returns
Type Description
int

NumObjectFields()

Declaration
public int NumObjectFields()
Returns
Type Description
int

ParseJson(string)

Parse a JSON string into a Variant (matches Java VariantUtils.fromJsonNode).

Declaration
public static Variant ParseJson(string json)
Parameters
Type Name Description
string json
Returns
Type Description
Variant

ToJson()

Serialize to a JSON string, matching Java's VariantUtils.toJsonString.

Declaration
public string ToJson()
Returns
Type Description
string
In this article