Advertisement
Guest User

Untitled

a guest
Oct 8th, 2015
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. pub fn decode_nv_list_embedded(xdr: &mut xdr::Xdr) -> xdr::XdrResult<NvList> {
  2. // Decode version and nvflag
  3. let version = try!(xdr.decode_i32());
  4. let nvflag = try!(xdr.decode_u32());
  5.  
  6. // TODO: Give an actual error
  7. if version != NV_VERSION {
  8. return Err(xdr::XdrError);
  9. }
  10.  
  11. let mut nv_list = NvList::new(nvflag);
  12.  
  13. // Decode the pairs
  14. loop {
  15. // Decode decoded/decoded size
  16. let encoded_size = try!(xdr.decode_u32());
  17. let decoded_size = try!(xdr.decode_u32());
  18.  
  19. // Check for 2 terminating zeros
  20. if (encoded_size == 0 && decoded_size == 0) {
  21. break;
  22. }
  23.  
  24. // Decode name
  25. let name = try!(xdr.decode_string());
  26.  
  27. // Decode data type
  28. let data_type =
  29. match DataType::from_u8(try!(xdr.decode_u8())) {
  30. Some(dt) => dt,
  31. None => { return Err(xdr::XdrError); },
  32. };
  33.  
  34. // Decode the number of elements
  35. let num_elements = try!(xdr.decode_i32()) as usize;
  36.  
  37. // Decode the value
  38. let value = try!(decode_nv_value(xdr, data_type, num_elements));
  39.  
  40. // Add the value to the list
  41. nv_list.pairs.push((name, value));
  42. }
  43.  
  44. Ok(nv_list)
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement