Class OrderedBytes

java.lang.Object
io.confluent.serializers.OrderedBytes

public class OrderedBytes extends Object
Partial implementation of the HBase OrderedBytes encoding scheme - https://hbase.apache.org/apidocs/org/apache/hadoop/hbase/util/OrderedBytes.html

These byte arrays maintain the sort order of the original data structures so they can be used for scans in RocksDB - Each type begins with a byte marker - Nulls are allowed and they sort first before any other type - Strings are UTF-8 encoded with a null byte end marker - Fixed-length integers are encoded big endian

Rather than drag in hbase-common and it's dependencies, we're opting to implement a subset of the spec

  • Field Details

  • Constructor Details

    • OrderedBytes

      public OrderedBytes()
  • Method Details

    • writeNull

      public static int writeNull(ByteBuffer buffer)
    • startsWith

      public static boolean startsWith(byte[] array, byte[] prefix)
    • getMaxNumBytes

      public static int getMaxNumBytes(String string)
    • readString

      public static String readString(ByteBuffer buffer)
    • writeString

      public static int writeString(ByteBuffer buffer, String value)
    • readInt

      public static Integer readInt(ByteBuffer buffer)
    • writeInt

      public static int writeInt(ByteBuffer buffer, Integer value)
      Appends value to buffer, using (value ^ Integer.MIN_VALUE) to invert to sign bit so that the appended bytes will sort correctly
      Parameters:
      buffer - to append to
      value - to append
      Returns:
      # of bytes written to buffer
    • readLong

      public static Long readLong(ByteBuffer buffer)
    • writeLong

      public static int writeLong(ByteBuffer buffer, Long value)
      Appends value to buffer, using (value ^ Long.MIN_VALUE) to invert to sign bit so that the appended bytes will sort correctly
      Parameters:
      buffer - to append to
      value - to append
      Returns:
      # of bytes written to buffer
    • readShort

      public static Short readShort(ByteBuffer buffer)
    • writeShort

      public static int writeShort(ByteBuffer buffer, Short value)
      Appends value to buffer, using (value ^ Short.MIN_VALUE) to invert to sign bit so that the appended bytes will sort correctly
      Parameters:
      buffer - to append to
      value - to append
      Returns:
      # of bytes written to buffer
    • flipSignBit

      public static long flipSignBit(long in)
    • flipSignBit

      public static int flipSignBit(int in)
    • flipSignBit

      public static short flipSignBit(short in)