58 lines
1.3 KiB
Rust
58 lines
1.3 KiB
Rust
use crate::rstd::inlining::*;
|
|
|
|
use super::*;
|
|
|
|
impl<const N: usize> Serializable for [u8; N] {
|
|
fn serialize(&self, serializer: &mut dyn Serializer) {
|
|
serializer.write(self)
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, PartialEq)]
|
|
pub enum ArrayParseError {
|
|
Eof,
|
|
ExtraData(usize),
|
|
}
|
|
|
|
impl Display for ArrayParseError {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
match self {
|
|
Self::Eof => write!(f, "encountered EOF write parsing an array"),
|
|
Self::ExtraData(length) => write!(
|
|
f,
|
|
"encountered extra data of length {length} while parsing an array",
|
|
),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl Error for ArrayParseError {}
|
|
|
|
impl From<&[u8]> for ArrayParseError {
|
|
fn from(_value: &[u8]) -> Self {
|
|
Self::Eof
|
|
}
|
|
}
|
|
|
|
impl<const N: usize> AtomicBase for [u8; N] {
|
|
type AParseError = ArrayParseError;
|
|
}
|
|
|
|
impl<const N: usize> ImplMode for [u8; N] {
|
|
type Mode = InliningMode;
|
|
}
|
|
|
|
impl<const N: usize> CInliningAtomic for [u8; N] {
|
|
fn ca_extension_error(tail: &[u8]) -> Self::AParseError {
|
|
ArrayParseError::ExtraData(tail.len())
|
|
}
|
|
|
|
fn ca_ideserialize<I: Stream>(stream: I) -> AIParseResult<Self, I> {
|
|
stream.iread_n_const::<N>(|slice| ArrayParseError::from(slice))
|
|
}
|
|
}
|
|
|
|
impl<const N: usize> ConstSizeAtomic for [u8; N] {
|
|
const SIZE: usize = N;
|
|
}
|