Skip to main content

tuwunel_core/matrix/pdu/
id.rs

1use super::{Count, RawId, ShortRoomId};
2
3/// Typed components of a PDU database key.
4///
5/// The room surrogate scopes the key and the count locates the event within the
6/// normal or backfilled timeline. Conversion to `RawId` packs both components.
7#[derive(Clone, Copy, Debug, Eq, PartialEq)]
8pub struct Id {
9	/// Compact local identifier of the event's room.
10	///
11	/// This is encoded first so room-scoped database scans share a fixed
12	/// prefix.
13	pub shortroomid: ShortRoomId,
14
15	/// Timeline sequence assigned to the event.
16	///
17	/// The count selects the normal or backfilled raw-key layout when encoded.
18	pub count: Count,
19}
20
21impl From<RawId> for Id {
22	#[inline]
23	fn from(raw: RawId) -> Self {
24		Self {
25			shortroomid: u64::from_be_bytes(raw.shortroomid()),
26			count: Count::from_unsigned(u64::from_be_bytes(raw.count())),
27		}
28	}
29}