fn deserialize_envelope(
    packet_type: PacketType,
    mut reader: &[u8],
) -> Result<(usize, &[u8]), ParseError> {
    if reader.remaining() < PacketType::LEN {
        return Err(OerError::UnexpectedEof.into());
    }
    let got_type = reader.get_u8();

    if got_type != packet_type as u8 {
        return Err(PacketTypeError::Unexpected(got_type, packet_type as u8).into());
    }

    let content_offset = PacketType::LEN + {
        // This could probably be determined a better way...
        let mut peek = reader;
        let before = peek.len();
        peek.read_var_octet_string_length()?;
        before - peek.len()
    };

    let content = reader.read_var_octet_string()?;

    ensure_no_outer_trailing_bytes(reader)?;

    Ok((content_offset, content))
}
/// Parses the outermost ILP packet ("envelope") to expected type (first byte).
///
/// ```text
/// +------+------------+---------//--+
/// | type |   varlen   |   content   |
/// |  u8  | 1..9 bytes |             |
/// +------+------------+---------//--+
///  0      1            n
///                      ^
///                      |
///  returned (offset and slice start)
/// ```
///
/// Returns the offset and slice starting with the offset.
Parses the outermost ILP packet ("envelope") to expected type (first byte).

Returns the offset and slice starting with the offset.
Parses the outermost ILP packet ( " envelope " ) to expected type ( first byte ) . Returns the offset and slice starting with the offset .
fn deserialize_envelope(
    packet_type: PacketType,
    mut reader: &[u8],
) -> Result<(usize, &[u8]), ParseError> {
    if reader.remaining() < PacketType::LEN {
        return Err(OerError::UnexpectedEof.into());
    }
    let got_type = reader.get_u8();
    if got_type != packet_type as u8 {
        return Err(PacketTypeError::Unexpected(got_type, packet_type as u8).into());
    }
    let content_offset = PacketType::LEN + {
        // This could probably be determined a better way...
        let mut peek = reader;
        let before = peek.len();
        peek.read_var_octet_string_length()?;
        before - peek.len()
    };
    let content = reader.read_var_octet_string()?;
    ensure_no_outer_trailing_bytes(reader)?;
    Ok((content_offset, content))
}
fn deserialize_envelope ( packet_type : PacketType , mut reader : & [ u8 ] , ) -> Result < ( usize , & [ u8 ] ) , ParseError > { if reader . remaining ( ) < PacketType :: LEN { return Err ( OerError :: UnexpectedEof . into ( ) ) ; } let got_type = reader . get_u8 ( ) ; if got_type != packet_type as u8 { return Err ( PacketTypeError :: Unexpected ( got_type , packet_type as u8 ) . into ( ) ) ; } let content_offset = PacketType :: LEN + { // This could probably be determined a better way... let mut peek = reader ; let before = peek . len ( ) ; peek . read_var_octet_string_length ( ) ? ; before - peek . len ( ) } ; let content = reader . read_var_octet_string ( ) ? ; ensure_no_outer_trailing_bytes ( reader ) ? ; Ok ( ( content_offset , content ) ) }
Parses the outermost ILP packet ("envelope") to expected type (first byte).
Parses the outermost ILP packet ( " envelope " ) to expected type ( first byte ) .
packet_type
PacketType
reader
&[u8]
packet_type
PacketType
reader
&[u8]