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.
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
The raw metadata bytes (the key dictionary).
Declaration
public byte[] MetadataBytes { get; }
Property Value
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
ValueBytes
The raw value bytes (the whole buffer, shared across sub-variants).
Declaration
public byte[] ValueBytes { get; }
Property Value
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
Overrides
GetBinary()
Declaration
public byte[] GetBinary()
Returns
GetBoolean()
Declaration
Returns
GetByte()
The signed 8-bit integer of an INT8 value (exact width; no widening).
Declaration
Returns
GetDecimal()
The decimal value (unscaled integer and scale) as a BigDecimal.
Declaration
public BigDecimal GetDecimal()
Returns
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
GetDouble()
The 64-bit double of a DOUBLE value (exact; does not widen FLOAT).
Declaration
public double GetDouble()
Returns
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
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
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
GetFloat()
The 32-bit float of a FLOAT value (exact; does not read DOUBLE).
Declaration
Returns
GetHashCode()
Serves as the default hash function.
Declaration
public override int GetHashCode()
Returns
| Type |
Description |
| int |
A hash code for the current object.
|
Overrides
GetInt()
The signed 32-bit integer of an INT8/INT16/INT32 value (widens within 32 bits).
Declaration
Returns
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
Returns
GetShort()
The signed 16-bit integer of an INT8/INT16 value (widens within 16 bits).
Declaration
Returns
GetString()
Declaration
public string GetString()
Returns
GetUuid()
The UUID as its canonical big-endian hex string (e.g. "00112233-...").
Declaration
Returns
GetVariantType()
Declaration
public VariantType GetVariantType()
Returns
NumArrayElements()
Declaration
public int NumArrayElements()
Returns
NumObjectFields()
Declaration
public int NumObjectFields()
Returns
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
ToJson()
Serialize to a JSON string, matching Java's VariantUtils.toJsonString.
Declaration
Returns