Expand description
The versioned envelope wrapped around every value written to a shared backend by 0.6.0 and later.
§Byte layout
offset size field encoding notes
------ ---- ---------------- ---------------------------- --------------------------------
0 3 MAGIC 0x54 0x48 0x43 ("THC") constant
3 1 FORMAT_VERSION 0x01 bumped only on envelope changes
4 1 CODEC_ID 0x01 = postcard 0x02..=0x7F reserved by this crate
0x80..=0xFF free for user codecs
5 8 expires_at_ms u64 little-endian ms since UNIX_EPOCH
13 8 stale_until_ms u64 little-endian ms since UNIX_EPOCH
21 N payload CacheCodec::encode(&entry) N = buf.len() - 21
------ ----
21 ENVELOPE_HEADER_LENThere is no payload length field: the transport frames the value exactly
(both Redis GET and memcached get return the stored length), and the
codec detects truncation on its own.
Putting the timestamps in the header rather than in the codec payload keeps
CacheCodec’s signature free of expiry concerns, makes the timings
readable with redis-cli without running a codec, and removes the extra
copy of the body that the 0.5.x Redis backend spent on double-encoding.
Constants§
- CODEC_
POSTCARD - Codec id of
PostcardCodec. - CODEC_
USER - Default codec id for codecs implemented outside this crate.
- ENVELOPE_
HEADER_ LEN - Size of the envelope header in bytes.
- FORMAT_
V1 - Envelope format version written by this release.
- LEGACY_
REDIS_ OVERHEAD - Fixed overhead of the 0.5.x Redis outer record: an 8-byte
u64length prefix for the inner payload plus two 8-byteu64timestamps. - MAGIC
- Magic prefix identifying a 0.6.0 envelope:
b"THC".
Functions§
- decode_
v2 - Decodes an envelope written by this release.
- is_
legacy_ redis - Exact structural test for a 0.5.x Redis value.
- looks_
like_ v2 - Reports whether
bytescarries an envelope header this release understands. - read_
stored - Reads a stored value, transparently accepting 0.5.x Redis entries.
- unix_
ms_ to_ system_ time - Converts milliseconds since
UNIX_EPOCHinto aSystemTime, the encoding used by the envelope’s two timestamp fields. - wrap
- Wraps an encoded payload in an envelope header.