| 82 | } |
| 83 | |
| 84 | pub fn to_bytes(&self) -> Result<Vec<u8>> { |
| 85 | let name_bytes = self.name.as_bytes(); |
| 86 | if name_bytes.len() > MAX_COLLECTION_NAME_LEN { |
| 87 | return Err(WalError::PayloadTooLarge { |
| 88 | size: name_bytes.len(), |
| 89 | max: MAX_COLLECTION_NAME_LEN, |
| 90 | }); |
| 91 | } |
| 92 | let mut buf = Vec::with_capacity(self.wire_size()); |
| 93 | buf.push(self.engine as u8); |
| 94 | buf.extend_from_slice(&(name_bytes.len() as u32).to_le_bytes()); |
| 95 | buf.extend_from_slice(name_bytes); |
| 96 | buf.extend_from_slice(&self.cutoff_system_ms.to_le_bytes()); |
| 97 | buf.extend_from_slice(&self.purged_count.to_le_bytes()); |
| 98 | Ok(buf) |
| 99 | } |
| 100 | |
| 101 | pub fn from_bytes(buf: &[u8]) -> Result<Self> { |
| 102 | if buf.len() < 1 + 4 { |