}
// top of request packet, just to get to procedure
-#[derive(Debug)]
+#[derive(Debug,PartialEq)]
pub struct RpcRequestPacketPartial {
pub hdr: RpcPacketHeader,
}
))
);
+
+#[cfg(test)]
+mod tests {
+ use crate::nfs::rpc_records::*;
+ use nom::Err::Incomplete;
+ use nom::Needed::Size;
+
+ #[test]
+ fn test_partial_input_too_short() {
+ let buf: &[u8] = &[
+ 0x80, 0x00, 0x00, 0x9c, // flags
+ 0x8e, 0x28, 0x02, 0x7e // xid
+ ];
+
+ let r = parse_rpc_request_partial(buf);
+ match r {
+ Err(Incomplete(s)) => { assert_eq!(s, Size(4)); },
+ _ => { panic!("failed {:?}",r); }
+ }
+ }
+ #[test]
+ fn test_partial_input_ok() {
+ let buf: &[u8] = &[
+ 0x80, 0x00, 0x00, 0x9c, // flags
+ 0x8e, 0x28, 0x02, 0x7e, // xid
+ 0x00, 0x00, 0x00, 0x01, // msgtype
+ 0x00, 0x00, 0x00, 0x02, // rpcver
+ 0x00, 0x00, 0x00, 0x03, // program
+ 0x00, 0x00, 0x00, 0x04, // progver
+ 0x00, 0x00, 0x00, 0x05, // procedure
+ ];
+ let expected = RpcRequestPacketPartial {
+ hdr: RpcPacketHeader {
+ frag_is_last: true,
+ frag_len: 156,
+ xid: 2384986750,
+ msgtype: 1
+ },
+ rpcver: 2,
+ program: 3,
+ progver: 4,
+ procedure: 5
+ };
+ let r = parse_rpc_request_partial(buf);
+ match r {
+ Ok((rem, hdr)) => {
+ assert_eq!(rem.len(), 0);
+ assert_eq!(hdr, expected);
+ },
+ _ => { panic!("failed {:?}",r); }
+ }
+ }
+}