Class SsFormat

java.lang.Object
com.google.cloud.spanner.spi.v1.SsFormat

@InternalApi public final class SsFormat extends Object
Sortable String Format encoding utilities for Spanner keys.

This class provides methods to encode various data types into a byte format that preserves lexicographic ordering. The encoding supports both increasing and decreasing sort orders.

  • Method Details

    • makePrefixSuccessor

      public static com.google.protobuf.ByteString makePrefixSuccessor(com.google.protobuf.ByteString key)
      Makes the given key a prefix successor. This means that the returned key is the smallest possible key that is larger than the input key, and that does not have the input key as a prefix.

      This is done by flipping the least significant bit of the last byte of the key.

      Parameters:
      key - The key to make a prefix successor.
      Returns:
      The prefix successor key.
    • appendCompositeTag

      public static void appendCompositeTag(UnsynchronizedByteArrayOutputStream out, int tag)
    • appendNullOrderedFirst

      public static void appendNullOrderedFirst(UnsynchronizedByteArrayOutputStream out)
    • appendNullOrderedLast

      public static void appendNullOrderedLast(UnsynchronizedByteArrayOutputStream out)
    • appendNotNullMarkerNullOrderedFirst

      public static void appendNotNullMarkerNullOrderedFirst(UnsynchronizedByteArrayOutputStream out)
    • appendNotNullMarkerNullOrderedLast

      public static void appendNotNullMarkerNullOrderedLast(UnsynchronizedByteArrayOutputStream out)
    • appendBoolIncreasing

      public static void appendBoolIncreasing(UnsynchronizedByteArrayOutputStream out, boolean value)
      Appends a boolean value in ascending (increasing) sort order.

      Boolean values are encoded using unsigned integer encoding where false=0 and true=1. This preserves the natural ordering where false < true.

      Parameters:
      out - the output stream to append to
      value - the boolean value to encode
    • appendBoolDecreasing

      public static void appendBoolDecreasing(UnsynchronizedByteArrayOutputStream out, boolean value)
      Appends a boolean value in descending (decreasing) sort order.

      Boolean values are encoded using unsigned integer encoding where false=0 and true=1, then inverted for descending order. This preserves reverse ordering where true < false.

      Parameters:
      out - the output stream to append to
      value - the boolean value to encode
    • appendInt64Increasing

      public static void appendInt64Increasing(UnsynchronizedByteArrayOutputStream out, long value)
    • appendInt64Decreasing

      public static void appendInt64Decreasing(UnsynchronizedByteArrayOutputStream out, long value)
    • appendDoubleIncreasing

      public static void appendDoubleIncreasing(UnsynchronizedByteArrayOutputStream out, double value)
    • appendDoubleDecreasing

      public static void appendDoubleDecreasing(UnsynchronizedByteArrayOutputStream out, double value)
    • appendStringIncreasing

      public static void appendStringIncreasing(UnsynchronizedByteArrayOutputStream out, String value)
    • appendStringDecreasing

      public static void appendStringDecreasing(UnsynchronizedByteArrayOutputStream out, String value)
    • appendBytesIncreasing

      public static void appendBytesIncreasing(UnsynchronizedByteArrayOutputStream out, byte[] value)
    • appendBytesDecreasing

      public static void appendBytesDecreasing(UnsynchronizedByteArrayOutputStream out, byte[] value)
    • encodeTimestamp

      public static byte[] encodeTimestamp(long seconds, int nanos)
      Encodes a timestamp as 12 bytes: 8 bytes for seconds since epoch (with offset to handle negative), 4 bytes for nanoseconds.
    • encodeUuid

      public static byte[] encodeUuid(long high, long low)
      Encodes a UUID (128-bit) as 16 bytes in big-endian order.