Class VariantBuilder
java.lang.Object
io.confluent.kafka.schemaregistry.type.VariantBuilder
- Direct Known Subclasses:
VariantArrayBuilder,VariantObjectBuilder
Builder for creating Variant value and metadata.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected VariantArrayBuilderprotected io.confluent.kafka.schemaregistry.type.MetadataObject and array builders share the same Metadata object as the main builder.protected VariantObjectBuilderThese are used to build nested objects and arrays, via startObject() and startArray().protected byte[]The buffer for building the Variant value.protected int -
Constructor Summary
ConstructorsConstructorDescriptionCreates a VariantBuilder.VariantBuilder(io.confluent.kafka.schemaregistry.type.Metadata metadata) Creates a VariantBuilder with a non-default metadata object. -
Method Summary
Modifier and TypeMethodDescriptionvoidappendBinary(ByteBuffer binary) Appends binary data to the variant builder.voidappendBoolean(boolean b) Appends a boolean value to the Variant builder.voidappendByte(byte b) Appends a byte value to the variant builder.voidappendDate(int daysSinceEpoch) Appends a date value to the variant builder.voidAppends a decimal value to the variant builder.voidappendDouble(double d) Appends a double value to the variant builder.voidappendEncodedValue(ByteBuffer value) Directly append a Variant value.voidappendFloat(float f) Appends a float value to the variant builder.voidappendInt(int i) Appends an int value to the variant builder.voidappendLong(long l) Appends a long value to the variant builder.voidAppends a null value to the Variant builder.voidvoidappendShort(short s) Appends a short value to the variant builder.voidappendString(String str) Appends a string value to the Variant builder.voidappendTime(long microsSinceMidnight) Appends a Time value to the variant builder.voidappendTimestampNanosNtz(long nanosSinceEpoch) Appends a TimestampNanosNtz value to the variant builder.voidappendTimestampNanosTz(long nanosSinceEpoch) Appends a TimestampNanosTz value to the variant builder.voidappendTimestampNtz(long microsSinceEpoch) Appends a TimestampNtz value to the variant builder.voidappendTimestampTz(long microsSinceEpoch) Appends a TimestampTz value to the variant builder.voidappendUUID(UUID uuid) Appends a UUID value to the variant builder.build()protected voidprotected voidcheckMultipleNested(String message) voidendArray()Ends appending an array to this variant builder.voidFinishes appending the object to this builder.voidstatic intgetMinIntegerSize(int value) protected voidonAppend()protected voidStarts appending an array to this variant builder.Starts appending an object to this variant builder.startOrContinuePartialObject(ByteBuffer value, Set<String> suppressedKeys)
-
Field Details
-
writeBuffer
protected byte[] writeBufferThe buffer for building the Variant value. The first `writePos` bytes have been written. -
writePos
protected int writePos -
metadata
protected io.confluent.kafka.schemaregistry.type.Metadata metadataObject and array builders share the same Metadata object as the main builder. -
objectBuilder
These are used to build nested objects and arrays, via startObject() and startArray(). Only one of these can be non-null at a time. If one of these is non-null, then no append() methods can be called on this builder, until endObject() or endArray() is called. -
arrayBuilder
-
-
Constructor Details
-
VariantBuilder
public VariantBuilder()Creates a VariantBuilder. -
VariantBuilder
public VariantBuilder(io.confluent.kafka.schemaregistry.type.Metadata metadata) Creates a VariantBuilder with a non-default metadata object.
-
-
Method Details
-
build
- Returns:
- the Variant value
-
encodedValue
- Returns:
- the constructed Variant value binary, without metadata.
-
appendEncodedValue
Directly append a Variant value. Its keys must already be in the metadata dictionary. -
appendString
Appends a string value to the Variant builder.- Parameters:
str- the string value to append
-
appendNull
public void appendNull()Appends a null value to the Variant builder. -
appendNullIfEmpty
public void appendNullIfEmpty() -
appendBoolean
public void appendBoolean(boolean b) Appends a boolean value to the Variant builder.- Parameters:
b- the boolean value to append
-
appendLong
public void appendLong(long l) Appends a long value to the variant builder.- Parameters:
l- the long value to append
-
appendInt
public void appendInt(int i) Appends an int value to the variant builder.- Parameters:
i- the int to append
-
appendShort
public void appendShort(short s) Appends a short value to the variant builder.- Parameters:
s- the short to append
-
appendByte
public void appendByte(byte b) Appends a byte value to the variant builder.- Parameters:
b- the byte to append
-
appendDouble
public void appendDouble(double d) Appends a double value to the variant builder.- Parameters:
d- the double to append
-
appendDecimal
Appends a decimal value to the variant builder. The actual encoded decimal type depends on the precision and scale of the decimal value.- Parameters:
d- the decimal value to append
-
appendDate
public void appendDate(int daysSinceEpoch) Appends a date value to the variant builder. The date is represented as the number of days since the epoch.- Parameters:
daysSinceEpoch- the number of days since the epoch
-
appendTimestampTz
public void appendTimestampTz(long microsSinceEpoch) Appends a TimestampTz value to the variant builder. The timestamp is represented as the number of microseconds since the epoch.- Parameters:
microsSinceEpoch- the number of microseconds since the epoch
-
appendTimestampNtz
public void appendTimestampNtz(long microsSinceEpoch) Appends a TimestampNtz value to the variant builder. The timestamp is represented as the number of microseconds since the epoch.- Parameters:
microsSinceEpoch- the number of microseconds since the epoch
-
appendTime
public void appendTime(long microsSinceMidnight) Appends a Time value to the variant builder. The time is represented as the number of microseconds since midnight.- Parameters:
microsSinceMidnight- the number of microseconds since midnight
-
appendTimestampNanosTz
public void appendTimestampNanosTz(long nanosSinceEpoch) Appends a TimestampNanosTz value to the variant builder. The timestamp is represented as the number of nanoseconds since the epoch.- Parameters:
nanosSinceEpoch- the number of nanoseconds since the epoch
-
appendTimestampNanosNtz
public void appendTimestampNanosNtz(long nanosSinceEpoch) Appends a TimestampNanosNtz value to the variant builder. The timestamp is represented as the number of nanoseconds since the epoch.- Parameters:
nanosSinceEpoch- the number of nanoseconds since the epoch
-
appendFloat
public void appendFloat(float f) Appends a float value to the variant builder.- Parameters:
f- the float to append
-
appendBinary
Appends binary data to the variant builder.- Parameters:
binary- the binary data to append
-
appendUUID
Appends a UUID value to the variant builder.- Parameters:
uuid- the UUID to append
-
startObject
Starts appending an object to this variant builder. The returned VariantObjectBuilder is used to append object keys and values. startObject() must be called before endObject(). No append*() methods can be called in between startObject() and endObject().Example usage: VariantBuilder builder = new VariantBuilder(); VariantObjectBuilder objBuilder = builder.startObject(); objBuilder.appendKey("key1"); objBuilder.appendString("value1"); builder.endObject();
- Returns:
- a VariantObjectBuilder to build an object
-
startOrContinueObject
-
startOrContinuePartialObject
public VariantObjectBuilder startOrContinuePartialObject(ByteBuffer value, Set<String> suppressedKeys) -
endObjectIfExists
public void endObjectIfExists() -
endObject
public void endObject()Finishes appending the object to this builder. This method must be called after startObject(), before other append*() methods can be called on this builder. -
startArray
Starts appending an array to this variant builder. The returned VariantArrayBuilder is used to append values ot the array. startArray() must be called before endArray(). No append*() methods can be called in between startArray() and endArray().Example usage: VariantBuilder builder = new VariantBuilder(); VariantArrayBuilder arrayBuilder = builder.startArray(); arrayBuilder.appendString("value1"); arrayBuilder.appendString("value2"); builder.endArray();
- Returns:
- a VariantArrayBuilder to use for startArrayElement() and endArray().
-
endArray
public void endArray()Ends appending an array to this variant builder. This method must be called after all elements have been added to the array. -
onAppend
protected void onAppend() -
onStartNested
protected void onStartNested() -
checkMultipleNested
-
checkAppendWhileNested
protected void checkAppendWhileNested() -
getMinIntegerSize
public static int getMinIntegerSize(int value)
-