Skip to main content

reifydb_codec/frame/
format.rs

1// SPDX-License-Identifier: Apache-2.0
2// Copyright (c) 2026 ReifyDB
3
4pub const RBCF_MAGIC: u32 = 0x46434252;
5
6pub const RBCF_VERSION: u16 = 1;
7
8pub const MESSAGE_HEADER_SIZE: usize = 16;
9
10pub const FRAME_HEADER_SIZE: usize = 12;
11
12pub const COLUMN_DESCRIPTOR_SIZE: usize = 28;
13
14pub const COL_FLAG_HAS_NONES: u8 = 1 << 0;
15
16#[derive(Debug, Clone, Copy, PartialEq, Eq)]
17#[repr(u8)]
18pub enum Encoding {
19	Plain = 0,
20
21	Dict = 1,
22
23	Rle = 2,
24
25	Delta = 3,
26
27	BitPack = 4,
28
29	DeltaRle = 5,
30}
31
32impl Encoding {
33	pub fn from_u8(v: u8) -> Option<Encoding> {
34		match v {
35			0 => Some(Encoding::Plain),
36			1 => Some(Encoding::Dict),
37			2 => Some(Encoding::Rle),
38			3 => Some(Encoding::Delta),
39			4 => Some(Encoding::BitPack),
40			5 => Some(Encoding::DeltaRle),
41			_ => None,
42		}
43	}
44}
45
46pub fn dict_index_width_from_flags(flags: u8) -> usize {
47	match (flags >> 4) & 0x03 {
48		0 => 1,
49		1 => 2,
50		2 => 4,
51		_ => 4,
52	}
53}
54
55pub fn dict_index_width_to_flags(width: usize) -> u8 {
56	match width {
57		1 => 0 << 4,
58		2 => 1 << 4,
59		4 => 2 << 4,
60		_ => 2 << 4,
61	}
62}