armour-core 0.1.0

Core types for armour ecosystem
Documentation
use core::num::NonZeroU64;

use crate::key_type::KeyType;

/// group_id calc
///
/// 24 bits prefix for id in big endian
///
/// each group is 256 elements for ID
pub const SEQ_BITS: u32 = 24;

/// group_id calc
///
/// 16 bits prefix for id in big endian
///
/// each group is 65536 elements for ID
pub const SEQ64_BITS: u32 = 16;

// 30 bit timestamp in ms represent 12 days
// другими словами, первые 10 бит - уникальные для группы. Одна группа будет содержать идентификаторы, созданные в окне из 12 дней. В году будет 31 группа.
// +- 1 bit = 12 days * 2
// 30 bit = 1_073_741_824 ms = 12 days
// 40 - 30 = 10 bit = 1024
// groups represent 32 bit numbers, поэтому:
// 32 - 10 = 22, 2^22 = 4_194_304 = 0x40_0000
pub const MILLISECOND_BITS: u32 = 10;

pub trait KeyPart: Sized {
    const TY: KeyType;
    const PREFIX_BITS: u32;
}

impl KeyPart for NonZeroU64 {
    const TY: KeyType = KeyType::U64;
    const PREFIX_BITS: u32 = SEQ64_BITS;
}