|
| 1 | +// Auto-generated by lcm-rust-gen. DO NOT EDIT. |
| 2 | + |
| 3 | +use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt}; |
| 4 | +use std::io::{self, Read, Write, Cursor}; |
| 5 | +use std::sync::OnceLock; |
| 6 | + |
| 7 | +#[derive(Debug, Clone, Default, PartialEq)] |
| 8 | +pub struct GoalStatus { |
| 9 | + pub goal_id: crate::actionlib_msgs::GoalID, |
| 10 | + pub status: u8, |
| 11 | + pub text: std::string::String, |
| 12 | +} |
| 13 | + |
| 14 | +impl GoalStatus { |
| 15 | + pub const HASH: i64 = 0xC0B4E95FEBDCD994u64 as i64; |
| 16 | + pub const NAME: &str = "actionlib_msgs.GoalStatus"; |
| 17 | + |
| 18 | + pub const PENDING: i8 = 0; |
| 19 | + pub const ACTIVE: i8 = 1; |
| 20 | + pub const PREEMPTED: i8 = 2; |
| 21 | + pub const SUCCEEDED: i8 = 3; |
| 22 | + pub const ABORTED: i8 = 4; |
| 23 | + pub const REJECTED: i8 = 5; |
| 24 | + pub const PREEMPTING: i8 = 6; |
| 25 | + pub const RECALLING: i8 = 7; |
| 26 | + pub const RECALLED: i8 = 8; |
| 27 | + pub const LOST: i8 = 9; |
| 28 | + |
| 29 | + fn packed_fingerprint() -> u64 { |
| 30 | + static CACHE: OnceLock<u64> = OnceLock::new(); |
| 31 | + *CACHE.get_or_init(|| Self::hash_recursive(&mut Vec::new())) |
| 32 | + } |
| 33 | + |
| 34 | + pub(crate) fn hash_recursive(parents: &mut Vec<u64>) -> u64 { |
| 35 | + let self_hash = Self::HASH as u64; |
| 36 | + if parents.contains(&self_hash) { |
| 37 | + return 0; |
| 38 | + } |
| 39 | + parents.push(self_hash); |
| 40 | + let mut tmphash = self_hash as u64; |
| 41 | + tmphash = tmphash.wrapping_add(crate::actionlib_msgs::GoalID::hash_recursive(parents)); |
| 42 | + parents.pop(); |
| 43 | + // rotate left by 1 |
| 44 | + tmphash << 1 | tmphash >> 63 |
| 45 | + } |
| 46 | + |
| 47 | + pub fn encode(&self) -> Vec<u8> { |
| 48 | + let mut buf = Vec::with_capacity(8 + self.encoded_size()); |
| 49 | + buf.write_u64::<BigEndian>(Self::packed_fingerprint()).unwrap(); |
| 50 | + self.encode_one(&mut buf).unwrap(); |
| 51 | + buf |
| 52 | + } |
| 53 | + |
| 54 | + pub fn decode(data: &[u8]) -> io::Result<Self> { |
| 55 | + let mut cursor = Cursor::new(data); |
| 56 | + let hash = cursor.read_u64::<BigEndian>()?; |
| 57 | + let expected = Self::packed_fingerprint(); |
| 58 | + if hash != expected { |
| 59 | + return Err(io::Error::new(io::ErrorKind::InvalidData, |
| 60 | + format!("Hash mismatch: expected {:016x}, got {:016x}", expected, hash))); |
| 61 | + } |
| 62 | + Self::decode_one(&mut cursor) |
| 63 | + } |
| 64 | + |
| 65 | + pub fn encode_one<W: Write>(&self, buf: &mut W) -> io::Result<()> { |
| 66 | + self.goal_id.encode_one(buf)?; |
| 67 | + buf.write_u8(self.status)?; |
| 68 | + { |
| 69 | + let bytes = self.text.as_bytes(); |
| 70 | + buf.write_u32::<BigEndian>((bytes.len() + 1) as u32)?; |
| 71 | + buf.write_all(bytes)?; |
| 72 | + buf.write_u8(0)?; |
| 73 | + } |
| 74 | + Ok(()) |
| 75 | + } |
| 76 | + |
| 77 | + pub fn decode_one<R: Read>(buf: &mut R) -> io::Result<Self> { |
| 78 | + let goal_id = crate::actionlib_msgs::GoalID::decode_one(buf)?; |
| 79 | + let status = buf.read_u8()?; |
| 80 | + let text = { |
| 81 | + let len = buf.read_u32::<BigEndian>()? as usize; |
| 82 | + let mut bytes = vec![0u8; len]; |
| 83 | + buf.read_exact(&mut bytes)?; |
| 84 | + std::string::String::from_utf8(bytes[..len - 1].to_vec()) |
| 85 | + .map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))? |
| 86 | + }; |
| 87 | + Ok(Self { |
| 88 | + goal_id, |
| 89 | + status, |
| 90 | + text, |
| 91 | + }) |
| 92 | + } |
| 93 | + |
| 94 | + pub fn encoded_size(&self) -> usize { |
| 95 | + let mut size = 0usize; |
| 96 | + size += self.goal_id.encoded_size(); |
| 97 | + size += 1; |
| 98 | + size += 4 + self.text.len() + 1; |
| 99 | + size |
| 100 | + } |
| 101 | + |
| 102 | +} |
0 commit comments