# `Slap.Streams.Offset`
[🔗](https://github.com/mjrusso/slap/blob/slap_streams-v0.4.0/slap_streams/lib/slap/streams/offset.ex#L1)

Offsets on the wire, in the official server's format and accounting, so
that offsets stay valid for streams migrated from it.

A token is `"0000000000000000_" <> byte_offset` zero-padded to 16 decimal
digits. Each stored message advances the offset by `4 + byte_size(message)`,
the official file store's framing (a 4-byte length prefix), although the
prefix is not stored here.

# `t`

```elixir
@type t() :: non_neg_integer()
```

# `advance`

```elixir
@spec advance(t(), non_neg_integer()) :: t()
```

The offset after a message of `size` bytes stored at `offset`.

# `encode`

```elixir
@spec encode(t()) :: String.t()
```

The token for `byte_offset`.

# `parse`

```elixir
@spec parse(String.t() | nil) :: {:ok, t() | :start | :now} | {:error, :bad_offset}
```

Parses a client offset. `"-1"` (and an absent offset, `nil` or `""`) is
`:start`, the earliest data the stream still has (after a trim, not 0);
`"now"` is `:now`.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
