Skip to main content

peat_lite/protocol/
crdt_type.rs

1//! CRDT type identifiers for Data messages.
2
3/// CRDT type identifiers carried in the first byte of a `Data` payload.
4#[derive(Debug, Clone, Copy, PartialEq, Eq)]
5#[repr(u8)]
6pub enum CrdtType {
7    LwwRegister = 0x01,
8    GCounter = 0x02,
9    PnCounter = 0x03,
10    OrSet = 0x04,
11}
12
13impl CrdtType {
14    /// Convert a raw byte to a `CrdtType`, if valid.
15    pub fn from_u8(v: u8) -> Option<Self> {
16        match v {
17            0x01 => Some(Self::LwwRegister),
18            0x02 => Some(Self::GCounter),
19            0x03 => Some(Self::PnCounter),
20            0x04 => Some(Self::OrSet),
21            _ => None,
22        }
23    }
24}