pub(crate) const MAGIC_BASE: u32 = 0xD7B1_A5C0;
#[cfg(feature = "decompression")]
pub(crate) const MAGIC_PADDING: u32 = 16;
pub(crate) const FLAG_CONTENT_CHECKSUM: u8 = 1 << 0;
pub(crate) const FLAG_COMPRESSED_CHECKSUM: u8 = 1 << 1;
#[cfg(feature = "decompression")]
pub(crate) const FLAG_COMMENT: u8 = 1 << 2;
#[cfg(feature = "decompression")]
pub(crate) const FLAG_BUNDLE_ID: u8 = 1 << 3;
#[cfg(feature = "decompression")]
pub(crate) const COMMENT_VERSION_MIN: u32 = 22;
pub(crate) const WIDE_CODEC_ID_VERSION_MIN: u32 = 24;
#[cfg(feature = "decompression")]
pub(crate) const BUNDLE_VERSION_MIN: u32 = 25;
#[cfg(feature = "decompression")]
pub(crate) const COMMENT_MAX: u64 = 10_000;
pub(crate) const END_OF_FRAME: u8 = 0;
#[cfg(feature = "decompression")]
pub(crate) const INPUT_LIMIT: usize = 2048;
#[cfg(feature = "decompression")]
pub(crate) const NODE_LIMIT: u64 = 20_000;
#[cfg(feature = "decompression")]
pub(crate) const STREAM_LIMIT: u64 = 110_000;
#[cfg(feature = "zstd")]
pub(crate) const CODEC_ZSTD: u32 = 22;
#[cfg(all(feature = "compression", feature = "zstd"))]
pub(crate) const MIN_STREAM_SIZE: usize = 10;
pub(crate) const fn codec_id_bits(version: u32) -> u32 {
if version < WIDE_CODEC_ID_VERSION_MIN {
6
} else {
7
}
}
#[cfg(feature = "decompression")]
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub(crate) enum StreamType {
Serial,
Struct,
Numeric,
String,
}
#[cfg(feature = "decompression")]
impl StreamType {
pub(crate) const fn from_code(code: u8) -> Self {
match code & 3 {
0 => Self::Serial,
1 => Self::Struct,
2 => Self::Numeric,
_ => Self::String,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn codec_id_width_grows_at_version_24() {
assert_eq!(codec_id_bits(21), 6);
assert_eq!(codec_id_bits(23), 6);
assert_eq!(codec_id_bits(24), 7);
assert_eq!(codec_id_bits(27), 7);
}
#[cfg(feature = "decompression")]
#[test]
fn type_codes_follow_the_reference_order() {
assert_eq!(StreamType::from_code(0), StreamType::Serial);
assert_eq!(StreamType::from_code(1), StreamType::Struct);
assert_eq!(StreamType::from_code(2), StreamType::Numeric);
assert_eq!(StreamType::from_code(3), StreamType::String);
}
}