INNER CODE UNIT · Rust
encode
risc0/risc0-ethereum · crates/aggregation/src/lib.rs:102
pub fn encode(&self) -> Vec<u8> {
[self.self_image_id.as_bytes(), &self.mmr.encode()].concat()
}
/// Decodes the [GuestState] for the journal. Uses a specialized codec.
/// See [MerkleMountainRange::encode].
pub fn decode(bytes: impl AsRef<[u8]>) -> Result<Self, DecodingError> {
// Read the first 32 bytes as the self_image_id.
let (chunk, bytes) = bytes
.as_ref()
.split_at_checked(U256::BYTES)
.ok_or(DecodingError::UnexpectedEnd)?;
let self_image_id = Digest::try_from(chunk).unwrap();
let mmr = MerkleMountainRange::decode(bytes)?;
Ok(Self { self_image_id, mmr })
}
/// Create a [GuestInput] from this [GuestState]. When run with the guest, the given claims