MCPcopy Create free account
hub / github.com/argumentcomputer/ix / to_bytes

Method to_bytes

crates/kernel/src/shard.rs:1390–1427  ·  view source on GitHub ↗

Serialize to the `.ixes` binary format.

(&self)

Source from the content-addressed store, hash-verified

1388 cross_ingress_total={} max_shard_cross={}",
1389 self.shards.len(),
1390 empty,
1391 min,
1392 mean,
1393 max,
1394 if mean == 0 { 0.0 } else { max as f64 / mean as f64 },
1395 self.total_cross_ingress,
1396 max_cross,
1397 )
1398 }
1399
1400 /// Serialize to the `.ixes` binary format.
1401 pub fn to_bytes(&self) -> Vec<u8> {
1402 let mut out = Vec::new();
1403 out.extend_from_slice(SHARD_MAGIC);
1404 out.extend_from_slice(&self.total_cross_ingress.to_le_bytes());
1405 out.extend_from_slice(&(self.shards.len() as u32).to_le_bytes());
1406 let put_addrs = |out: &mut Vec<u8>, addrs: &[Address]| {
1407 out.extend_from_slice(&(addrs.len() as u32).to_le_bytes());
1408 for a in addrs {
1409 out.extend_from_slice(a.as_bytes());
1410 }
1411 };
1412 for sh in &self.shards {
1413 out.extend_from_slice(&sh.id.to_le_bytes());
1414 out.extend_from_slice(&sh.heartbeats.to_le_bytes());
1415 out.extend_from_slice(&sh.own_size.to_le_bytes());
1416 out.extend_from_slice(&sh.cross_ingress.to_le_bytes());
1417 match &sh.assumption_root {
1418 Some(a) => {
1419 out.push(1);
1420 out.extend_from_slice(a.as_bytes());
1421 },
1422 None => out.push(0),
1423 }
1424 put_addrs(&mut out, &sh.blocks);
1425 put_addrs(&mut out, &sh.foreign_blocks);
1426 }
1427 // Trailing optional bisection-tree section: presence byte then preorder
1428 // tree. Appended after the shards so older readers that stop at the shard
1429 // count simply ignore it, and `from_bytes` treats end-of-input as `None`.
1430 match &self.tree {

Callers 5

shard_espFunction · 0.45
shard_esp_capFunction · 0.45
shard_esp_file_roundtripFunction · 0.45
manifest_tree_roundtripFunction · 0.45

Calls 4

as_bytesMethod · 0.80
pushMethod · 0.80
lenMethod · 0.45
putMethod · 0.45

Tested by 3

shard_esp_file_roundtripFunction · 0.36
manifest_tree_roundtripFunction · 0.36