Expand description
Compact message storage with binary IDs and interned strings.
Part of vector-core — the single source of truth for compact message types.
This module provides memory-efficient message storage:
[u8; 32]for IDs instead of hex strings (saves ~56 bytes per ID)- Interned npubs via
NpubInterner(each unique npub stored once) - Bitflags for boolean states (1 byte instead of 4+)
- Binary search for O(log n) message lookup
- Boxed optional fields (replied_to, wrapper_id) to save inline space
- Compact timestamp (u32 seconds since 2020 epoch)
Structs§
- Attachment
Flags - Packed attachment state: the three bools, where the local path comes from, and whether the original hash is the id.
- Compact
Attachment - Memory-efficient attachment: binary hashes, the extension as a code, the local path derived from the id or name when it can be, image metadata in one allocation, and the rarely-set fields behind one box.
- Compact
Message - Memory-efficient message: binary ids, interned npubs and emoji, packed flags, and the fields most messages never carry (a reply, edits, a link preview, custom emoji, bot targets) behind two optional boxes. 96 bytes inline.
- Compact
Message Vec - Sorted message storage with O(log n) lookup by ID.
- Compact
Reaction - Memory-efficient reaction: binary id, interned author, interned (emoji, url) pair.
40 bytes and
Copy, so adding or removing one never allocates per reaction. - Compact
Reply - The replied-to message, as quoted on this one.
- Message
Extras - The rarely-set parts of a message, boxed together so a plain message pays 8 bytes.
- Message
Flags - Bitflags for message state (1 byte instead of 4+ bytes for separate bools)
- Npub
Interner - String interner for npubs using sorted Vec + binary search.
- TinyVec
- Ultra-compact vector using a thin pointer (8 bytes on stack).
Constants§
- MAX_
REACTION_ GROUPS - Distinct-emoji ceiling on a single message’s reaction set. Joining an existing group is never bounded by this; opening a group past it is refused at the STATE chokepoint (inbound and outbound alike). The UI’s reaction row mirrors this number.
- NO_NPUB
- Sentinel value for “no npub” (avoids Option overhead)
Functions§
- decode_
message_ id - Decode 32 bytes back to an ID string, handling pending IDs specially.
- encode_
message_ id - Encode an ID string to 32 bytes, handling pending IDs specially.
- secs_
from_ compact - Convert compact u32 back to Unix seconds timestamp. Preserves 0 as sentinel for “never set”.
- secs_
to_ compact - Convert Unix seconds timestamp to compact u32 (seconds since 2020). Preserves 0 as sentinel for “never set”.
- timestamp_
from_ compact - Convert compact timestamp back to milliseconds.
- timestamp_
to_ compact - Convert milliseconds timestamp to compact storage. Stores full u64 milliseconds — no precision loss.