Skip to main content

reassemble_from_chunks

Function reassemble_from_chunks 

Source
pub fn reassemble_from_chunks(chunks: Vec<ChunkFragment>) -> Result<Vec<u8>>
Expand description

Reassemble canonical bytecode from a list of parsed chunks.

Validates SPEC §4 rules 11–13 in order:

  1. All chunks must be Chunked (mixing with SingleString is rejected).
  2. All chunks share chunk_set_id and total_chunks (Error::ChunkSetIdMismatch, Error::ChunkedHeaderMalformed).
  3. chunk_index values cover 0..total_chunks exactly once (Error::ChunkedHeaderMalformed on gaps, duplicates, or out-of-range).
  4. The reassembled stream’s trailing 4-byte cross-chunk hash matches SHA-256(reassembled_bytecode)[0..4] (Error::CrossChunkHashMismatch).

Chunks may arrive in any order; this function sorts internally.