1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
use bytes::BytesMut;

/// A to represent a length type with zero length.
///
/// This type is useful for encoding/decoding types that have no length prefix,
/// and should either:
/// - decode as the rest of the buffer.
/// - encode with no length prefix
#[derive(Debug, Clone, Copy, Default)]
pub struct Remaining;

impl crate::Decoder<usize> for Remaining {
    type Error = crate::Error;

    #[inline]
    fn decode(buf: &mut BytesMut) -> Result<usize, Self::Error> {
        Ok(buf.len())
    }
}

impl crate::RawDecoder<usize> for Remaining {
    type Error = crate::Error;

    #[inline]
    fn raw_decode<'a>(buf: &'a [u8]) -> Result<(usize, usize), Self::Error>
    where
        usize: 'a,
    {
        Ok((buf.len(), 0))
    }
}

impl crate::Encoder<usize> for Remaining {
    type Error = crate::Error;

    #[inline]
    fn encode(_input: &usize, _buf: &mut BytesMut) -> Result<(), Self::Error> {
        Ok(())
    }

    #[inline]
    fn size_of(_input: &usize) -> usize {
        0
    }
}