confluent-kafka-dotnet
Show / Hide Table of Contents

Class VariantBuilder

A flat, streaming writer that builds a Variant programmatically. A single builder maintains an internal nesting stack (the arrow-dotnet flat streaming-writer shape): each Append* targets the current slot - the root, the next array element, or the current object field value (after AppendKey(string)). Object fields are sorted by key on EndObject() (canonical order) and their keys accumulate into the metadata dictionary. Build() finalizes and returns a Variant.

Output is byte-identical to ParseJson(string) for the equivalent document: ParseJson(string) is itself implemented on top of this builder. Integer widths are the caller's choice here (AppendByte(sbyte) .. AppendLong(long)), whereas the JSON path selects the smallest width that fits; pick the matching method to reproduce a parsed document exactly.

Misuse (an unbalanced Start*/End*, AppendKey(string) outside an object, a value append without a preceding AppendKey(string) inside an object, or Build() with an open container) raises VariantException.

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

Methods

AppendBinary(byte[])

Append an opaque binary blob.

Declaration
public void AppendBinary(byte[] bytes)
Parameters
Type Name Description
byte[] bytes

AppendBoolean(bool)

Append a boolean value.

Declaration
public void AppendBoolean(bool b)
Parameters
Type Name Description
bool b

AppendByte(sbyte)

Append a signed 8-bit integer (INT8).

Declaration
public void AppendByte(sbyte v)
Parameters
Type Name Description
sbyte v

AppendDate(int)

Append a DATE (days since the Unix epoch).

Declaration
public void AppendDate(int daysSinceEpoch)
Parameters
Type Name Description
int daysSinceEpoch

AppendDecimal(BigDecimal)

Append a decimal from a BigDecimal.

Declaration
public void AppendDecimal(BigDecimal d)
Parameters
Type Name Description
BigDecimal d

AppendDecimal(byte[], int)

Append a decimal from its unscaled value (two's-complement big-endian bytes) and scale. The narrowest of DECIMAL4/8/16 that holds the precision is chosen, matching the JSON path.

Declaration
public void AppendDecimal(byte[] unscaledBigEndian, int scale)
Parameters
Type Name Description
byte[] unscaledBigEndian
int scale

AppendDecimal(BigInteger, int)

Append a decimal from a BigInteger unscaled value and scale.

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

AppendDouble(double)

Append a 64-bit double (DOUBLE).

Declaration
public void AppendDouble(double d)
Parameters
Type Name Description
double d

AppendFloat(float)

Append a 32-bit float (FLOAT).

Declaration
public void AppendFloat(float f)
Parameters
Type Name Description
float f

AppendInt(int)

Append a signed 32-bit integer (INT32).

Declaration
public void AppendInt(int v)
Parameters
Type Name Description
int v

AppendKey(string)

Set the key for the next appended value within the current object.

Declaration
public void AppendKey(string key)
Parameters
Type Name Description
string key

AppendLong(long)

Append a signed 64-bit integer (INT64).

Declaration
public void AppendLong(long v)
Parameters
Type Name Description
long v

AppendNull()

Append a null value into the current slot.

Declaration
public void AppendNull()

AppendShort(short)

Append a signed 16-bit integer (INT16).

Declaration
public void AppendShort(short v)
Parameters
Type Name Description
short v

AppendString(string)

Append a string (auto short-string when <= 63 UTF-8 bytes, else long-string).

Declaration
public void AppendString(string s)
Parameters
Type Name Description
string s

AppendTime(long)

Append a TIME_NTZ (microseconds since midnight).

Declaration
public void AppendTime(long microsSinceMidnight)
Parameters
Type Name Description
long microsSinceMidnight

AppendTimestampNanosNtz(long)

Append a nanosecond TIMESTAMP without time zone (nanoseconds since the Unix epoch).

Declaration
public void AppendTimestampNanosNtz(long nanos)
Parameters
Type Name Description
long nanos

AppendTimestampNanosTz(long)

Append a nanosecond TIMESTAMP with time zone (nanoseconds since the Unix epoch).

Declaration
public void AppendTimestampNanosTz(long nanos)
Parameters
Type Name Description
long nanos

AppendTimestampNtz(long)

Append a TIMESTAMP without time zone (microseconds since the Unix epoch).

Declaration
public void AppendTimestampNtz(long micros)
Parameters
Type Name Description
long micros

AppendTimestampTz(long)

Append a TIMESTAMP with time zone (microseconds since the Unix epoch).

Declaration
public void AppendTimestampTz(long micros)
Parameters
Type Name Description
long micros

AppendUuid(byte[])

Append a UUID from its 16 canonical big-endian bytes.

Declaration
public void AppendUuid(byte[] uuid16)
Parameters
Type Name Description
byte[] uuid16

Build()

Finalize and return the built Variant.

Declaration
public Variant Build()
Returns
Type Description
Variant

EndArray()

End the current array.

Declaration
public void EndArray()

EndObject()

End the current object (its fields are sorted by key).

Declaration
public void EndObject()

StartArray()

Begin an array; subsequent appends are its elements in order.

Declaration
public void StartArray()

StartObject()

Begin an object; subsequent field values are preceded by AppendKey(string).

Declaration
public void StartObject()
In this article