Skip to main content

Module compact

Module compact 

Source
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§

AttachmentFlags
Packed flags for attachment state (1 byte instead of multiple bools)
CompactAttachment
Memory-efficient attachment with binary hashes and compact strings.
CompactMessage
Memory-efficient message with binary IDs and interned npubs.
CompactMessageVec
Sorted message storage with O(log n) lookup by ID.
CompactReaction
Memory-efficient reaction with binary IDs and interned author.
MessageFlags
Bitflags for message state (1 byte instead of 4+ bytes for separate bools)
NpubInterner
String interner for npubs using sorted Vec + binary search.
TinyVec
Ultra-compact vector using a thin pointer (8 bytes on stack).

Constants§

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.