MCPcopy Create free account
hub / github.com/clockworklabs/SpacetimeDB / write

Method write

crates/commitlog/src/commit.rs:162–181  ·  view source on GitHub ↗

Serialize and write `self` to `out`. Returns the crc32 checksum of the commit on success.

(&self, out: W)

Source from the content-addressed store, hash-verified

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 ///

Callers 6

set_epochMethod · 0.45
syncMethod · 0.45
flushMethod · 0.45
flush_and_syncMethod · 0.45
commitMethod · 0.45
commit_roundtripFunction · 0.45

Calls 5

to_le_bytesMethod · 0.80
newFunction · 0.50
OkFunction · 0.50
lenMethod · 0.45
into_innerMethod · 0.45

Tested by 1

commit_roundtripFunction · 0.36