Class VariantBuilder

java.lang.Object
io.confluent.kafka.schemaregistry.type.VariantBuilder
Direct Known Subclasses:
VariantArrayBuilder, VariantObjectBuilder

public class VariantBuilder extends Object
Builder for creating Variant value and metadata.
  • Field Details

    • writeBuffer

      protected byte[] writeBuffer
      The 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 metadata
      Object and array builders share the same Metadata object as the main builder.
    • objectBuilder

      protected VariantObjectBuilder 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

      protected VariantArrayBuilder 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

      public Variant build()
      Returns:
      the Variant value
    • encodedValue

      public ByteBuffer encodedValue()
      Returns:
      the constructed Variant value binary, without metadata.
    • appendEncodedValue

      public void appendEncodedValue(ByteBuffer value)
      Directly append a Variant value. Its keys must already be in the metadata dictionary.
    • appendString

      public void appendString(String str)
      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

      public void appendDecimal(BigDecimal d)
      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

      public void appendBinary(ByteBuffer binary)
      Appends binary data to the variant builder.
      Parameters:
      binary - the binary data to append
    • appendUUID

      public void appendUUID(UUID uuid)
      Appends a UUID value to the variant builder.
      Parameters:
      uuid - the UUID to append
    • startObject

      public VariantObjectBuilder 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

      public VariantObjectBuilder 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

      public VariantArrayBuilder 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

      protected void checkMultipleNested(String message)
    • checkAppendWhileNested

      protected void checkAppendWhileNested()
    • getMinIntegerSize

      public static int getMinIntegerSize(int value)