serde_jam/visitor/
vlen.rs

1//! Variable length byte array visitor
2//!
3//! TODO: this visitor should be removed in the next optimization.
4
5#[cfg(feature = "std")]
6use crate::{Vec, compact::vlen};
7use core::fmt;
8use serde::de;
9
10/// Visitor for variable-length numbers.
11pub struct VlenBytesVisitor;
12
13impl de::Visitor<'_> for VlenBytesVisitor {
14    type Value = u64;
15
16    fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
17        formatter.write_str("a variable length prefixed byte array")
18    }
19
20    fn visit_u64<E>(self, v: u64) -> Result<Self::Value, E> {
21        Ok(v)
22    }
23
24    #[cfg(feature = "std")]
25    fn visit_byte_buf<E>(self, v: Vec<u8>) -> Result<Self::Value, E> {
26        let (value, _) = vlen::decode_from(&v);
27        Ok(value)
28    }
29}