Class SsFormat (6.107.0)

public final class SsFormat

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.

Inheritance

java.lang.Object > SsFormat

Static Methods

appendBoolDecreasing(UnsynchronizedByteArrayOutputStream out, boolean value)

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
Name Description
out UnsynchronizedByteArrayOutputStream

the output stream to append to

value boolean

the boolean value to encode

appendBoolIncreasing(UnsynchronizedByteArrayOutputStream out, boolean value)

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
Name Description
out UnsynchronizedByteArrayOutputStream

the output stream to append to

value boolean

the boolean value to encode

appendBytesDecreasing(UnsynchronizedByteArrayOutputStream out, byte[] value)

public static void appendBytesDecreasing(UnsynchronizedByteArrayOutputStream out, byte[] value)
Parameters
Name Description
out UnsynchronizedByteArrayOutputStream
value byte[]

appendBytesIncreasing(UnsynchronizedByteArrayOutputStream out, byte[] value)

public static void appendBytesIncreasing(UnsynchronizedByteArrayOutputStream out, byte[] value)
Parameters
Name Description
out UnsynchronizedByteArrayOutputStream
value byte[]

appendCompositeTag(UnsynchronizedByteArrayOutputStream out, int tag)

public static void appendCompositeTag(UnsynchronizedByteArrayOutputStream out, int tag)
Parameters
Name Description
out UnsynchronizedByteArrayOutputStream
tag int

appendDoubleDecreasing(UnsynchronizedByteArrayOutputStream out, double value)

public static void appendDoubleDecreasing(UnsynchronizedByteArrayOutputStream out, double value)
Parameters
Name Description
out UnsynchronizedByteArrayOutputStream
value double

appendDoubleIncreasing(UnsynchronizedByteArrayOutputStream out, double value)

public static void appendDoubleIncreasing(UnsynchronizedByteArrayOutputStream out, double value)
Parameters
Name Description
out UnsynchronizedByteArrayOutputStream
value double

appendInt64Decreasing(UnsynchronizedByteArrayOutputStream out, long value)

public static void appendInt64Decreasing(UnsynchronizedByteArrayOutputStream out, long value)
Parameters
Name Description
out UnsynchronizedByteArrayOutputStream
value long

appendInt64Increasing(UnsynchronizedByteArrayOutputStream out, long value)

public static void appendInt64Increasing(UnsynchronizedByteArrayOutputStream out, long value)
Parameters
Name Description
out UnsynchronizedByteArrayOutputStream
value long

appendNotNullMarkerNullOrderedFirst(UnsynchronizedByteArrayOutputStream out)

public static void appendNotNullMarkerNullOrderedFirst(UnsynchronizedByteArrayOutputStream out)
Parameter
Name Description
out UnsynchronizedByteArrayOutputStream

appendNotNullMarkerNullOrderedLast(UnsynchronizedByteArrayOutputStream out)

public static void appendNotNullMarkerNullOrderedLast(UnsynchronizedByteArrayOutputStream out)
Parameter
Name Description
out UnsynchronizedByteArrayOutputStream

appendNullOrderedFirst(UnsynchronizedByteArrayOutputStream out)

public static void appendNullOrderedFirst(UnsynchronizedByteArrayOutputStream out)
Parameter
Name Description
out UnsynchronizedByteArrayOutputStream

appendNullOrderedLast(UnsynchronizedByteArrayOutputStream out)

public static void appendNullOrderedLast(UnsynchronizedByteArrayOutputStream out)
Parameter
Name Description
out UnsynchronizedByteArrayOutputStream

appendStringDecreasing(UnsynchronizedByteArrayOutputStream out, String value)

public static void appendStringDecreasing(UnsynchronizedByteArrayOutputStream out, String value)
Parameters
Name Description
out UnsynchronizedByteArrayOutputStream
value String

appendStringIncreasing(UnsynchronizedByteArrayOutputStream out, String value)

public static void appendStringIncreasing(UnsynchronizedByteArrayOutputStream out, String value)
Parameters
Name Description
out UnsynchronizedByteArrayOutputStream
value String

encodeTimestamp(long seconds, int nanos)

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.

Parameters
Name Description
seconds long
nanos int
Returns
Type Description
byte[]

encodeUuid(long high, long low)

public static byte[] encodeUuid(long high, long low)

Encodes a UUID (128-bit) as 16 bytes in big-endian order.

Parameters
Name Description
high long
low long
Returns
Type Description
byte[]

makePrefixSuccessor(ByteString key)

public static ByteString makePrefixSuccessor(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.

Parameter
Name Description
key ByteString

The key to make a prefix successor.

Returns
Type Description
ByteString

The prefix successor key.