CursorCodec

Encodes and decodes the opaque cursor tokens used by the wire protocol — the cursor envelope's cursor and the pagination envelope's nextCursor.

A cursor wraps a server-side change sequence number, optionally together with the epoch of the store that issued it. The encoding (URL-safe Base64) is an implementation detail: clients must treat cursors as opaque and echo them back unchanged. On the server side, decode returning null — absent, malformed, or foreign cursor — is the signal to fall back to a full reset snapshot.

An epoch is a random value a store picks when it is created. A store's sequence starts over with the store, for example when the app process restarts, but clients keep polling with the cursors they hold. Decoding with the epoch rejects those stale cursors instead of mistaking one for the new store's current sequence.

Tabs serving snapshot-style observable lists rarely need this directly; use DebugResponse.cursorEnvelope, which applies the full envelope contract.

Functions

Link copied to clipboard
fun decode(cursor: String?): Long?

Decodes a cursor previously produced by encode back into its change sequence, or null when cursor is null or not a valid token.

fun decode(cursor: String?, epoch: Long): Long?

Decodes a cursor previously produced by encode with the same epoch back into its change sequence, or null when cursor is null, not a valid token, or issued under another epoch or none.

Link copied to clipboard
fun encode(sequence: Long): String

Encodes the change sequence as an opaque cursor token.

fun encode(sequence: Long, epoch: Long): String

Encodes the change sequence of the store identified by epoch as an opaque cursor token.