use crate::snapshot::Version;
const WIRE_FORMAT_VERSION: u16 = 1;
const HEADER_LEN: usize = 20;
const SECTION_HEADER_LEN: usize = 8;
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub(crate) struct Header {
wire_format: u16,
telemetry_schema: u16,
producer: Version,
}
impl Header {
#[must_use]
pub(crate) const fn new(telemetry_schema: u16, producer: Version) -> Self {
Self {
wire_format: WIRE_FORMAT_VERSION,
telemetry_schema,
producer,
}
}
#[must_use]
pub(crate) const fn encoded_len() -> usize {
HEADER_LEN
}
#[must_use]
pub(crate) const fn wire_format(&self) -> u16 {
self.wire_format
}
#[must_use]
pub(crate) const fn telemetry_schema(&self) -> u16 {
self.telemetry_schema
}
#[must_use]
pub(crate) const fn producer(&self) -> Version {
self.producer
}
pub(crate) const fn from_wire(wire_format: u16, telemetry_schema: u16, producer: Version) -> Self {
Self {
wire_format,
telemetry_schema,
producer,
}
}
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub(crate) struct Section<'a> {
id: u16,
version: u16,
payload: &'a [u8],
}
impl<'a> Section<'a> {
#[must_use]
pub(crate) const fn encoded_len(payload_len: usize) -> usize {
SECTION_HEADER_LEN + payload_len
}
#[must_use]
pub(crate) const fn id(&self) -> u16 {
self.id
}
#[must_use]
pub(crate) const fn version(&self) -> u16 {
self.version
}
#[must_use]
pub(crate) const fn payload(&self) -> &'a [u8] {
self.payload
}
pub(crate) const fn new(id: u16, version: u16, payload: &'a [u8]) -> Self {
Self { id, version, payload }
}
}
pub(crate) const fn wire_format_version() -> u16 {
WIRE_FORMAT_VERSION
}
pub(crate) const fn magic() -> [u8; 8] {
*b"RALSNAP\0"
}