Serialize to bytes.
(&self)
| 42 | |
| 43 | /// Serialize to bytes. |
| 44 | pub fn to_bytes(&self) -> Result<Vec<u8>> { |
| 45 | let name_bytes = self.collection.as_bytes(); |
| 46 | if name_bytes.len() > MAX_COLLECTION_NAME_LEN { |
| 47 | return Err(WalError::PayloadTooLarge { |
| 48 | size: name_bytes.len(), |
| 49 | max: MAX_COLLECTION_NAME_LEN, |
| 50 | }); |
| 51 | } |
| 52 | let mut buf = Vec::with_capacity(self.wire_size()); |
| 53 | buf.extend_from_slice(&(name_bytes.len() as u32).to_le_bytes()); |
| 54 | buf.extend_from_slice(name_bytes); |
| 55 | buf.extend_from_slice(&self.purge_lsn.to_le_bytes()); |
| 56 | Ok(buf) |
| 57 | } |
| 58 | |
| 59 | /// Deserialize from bytes. Fails on truncation, oversize name, or non-UTF8. |
| 60 | pub fn from_bytes(buf: &[u8]) -> Result<Self> { |