Serialize and write `self` to `out`. Returns the crc32 checksum of the commit on success.
(&self, out: W)
| 160 | /// |
| 161 | /// Returns the crc32 checksum of the commit on success. |
| 162 | pub fn write<W: Write>(&self, out: W) -> io::Result<u32> { |
| 163 | let mut out = Crc32cWriter::new(out); |
| 164 | |
| 165 | let min_tx_offset = self.min_tx_offset.to_le_bytes(); |
| 166 | let epoch = self.epoch.to_le_bytes(); |
| 167 | let n = self.n.to_le_bytes(); |
| 168 | let len = (self.records.len() as u32).to_le_bytes(); |
| 169 | |
| 170 | out.write_all(&min_tx_offset)?; |
| 171 | out.write_all(&epoch)?; |
| 172 | out.write_all(&n)?; |
| 173 | out.write_all(&len)?; |
| 174 | out.write_all(&self.records)?; |
| 175 | |
| 176 | let crc = out.crc32c(); |
| 177 | let mut out = out.into_inner(); |
| 178 | out.write_all(&crc.to_le_bytes())?; |
| 179 | |
| 180 | Ok(crc) |
| 181 | } |
| 182 | |
| 183 | /// Attempt to read one [`Commit`] from the given [`Read`]er. |
| 184 | /// |