Package com.google.cloud.spanner.spi.v1
Class SsFormat
java.lang.Object
com.google.cloud.spanner.spi.v1.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.
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidappendBoolDecreasing(UnsynchronizedByteArrayOutputStream out, boolean value) Appends a boolean value in descending (decreasing) sort order.static voidappendBoolIncreasing(UnsynchronizedByteArrayOutputStream out, boolean value) Appends a boolean value in ascending (increasing) sort order.static voidappendBytesDecreasing(UnsynchronizedByteArrayOutputStream out, byte[] value) static voidappendBytesIncreasing(UnsynchronizedByteArrayOutputStream out, byte[] value) static voidappendCompositeTag(UnsynchronizedByteArrayOutputStream out, int tag) static voidappendDoubleDecreasing(UnsynchronizedByteArrayOutputStream out, double value) static voidappendDoubleIncreasing(UnsynchronizedByteArrayOutputStream out, double value) static voidappendInt64Decreasing(UnsynchronizedByteArrayOutputStream out, long value) static voidappendInt64Increasing(UnsynchronizedByteArrayOutputStream out, long value) static voidstatic voidstatic voidstatic voidstatic voidstatic voidstatic 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.static byte[]encodeUuid(long high, long low) Encodes a UUID (128-bit) as 16 bytes in big-endian order.static com.google.protobuf.ByteStringmakePrefixSuccessor(com.google.protobuf.ByteString key) Makes the given key a prefix successor.
-
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
-
appendNullOrderedFirst
-
appendNullOrderedLast
-
appendNotNullMarkerNullOrderedFirst
-
appendNotNullMarkerNullOrderedLast
-
appendBoolIncreasing
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 tovalue- the boolean value to encode
-
appendBoolDecreasing
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 tovalue- the boolean value to encode
-
appendInt64Increasing
-
appendInt64Decreasing
-
appendDoubleIncreasing
-
appendDoubleDecreasing
-
appendStringIncreasing
-
appendStringDecreasing
-
appendBytesIncreasing
-
appendBytesDecreasing
-
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.
-