MCPcopy Create free account
hub / github.com/base/base / parse_frames

Method parse_frames

crates/consensus/protocol/src/frame.rs:257–283  ·  view source on GitHub ↗

Parse the on-chain serialization of frame(s) in an L1 transaction. Currently only version 0 of the serialization format is supported. All frames must be parsed without error, there must not be any leftover data, and there must be at least one frame. Frames are stored in L1 transactions with the following format: `data = DerivationVersion0 ++ Frame(s)` Where there is one or more frames concatenate

(encoded: &[u8])

Source from the content-addressed store, hash-verified

255 /// * `data = DerivationVersion0 ++ Frame(s)` Where there is one or more frames concatenated
256 /// together.
257 pub fn parse_frames(encoded: &[u8]) -> Result<Vec<Self>, FrameParseError> {
258 if encoded.is_empty() {
259 return Err(FrameParseError::NoFrames);
260 }
261 if encoded[0] != DERIVATION_VERSION_0 {
262 return Err(FrameParseError::UnsupportedVersion);
263 }
264
265 let data = &encoded[1..];
266 let mut frames = Vec::new();
267 let mut offset = 0;
268 while offset < data.len() {
269 let (frame_length, frame) =
270 Self::decode(&data[offset..]).map_err(FrameParseError::FrameDecodingError)?;
271 frames.push(frame);
272 offset += frame_length;
273 }
274
275 if offset != data.len() {
276 return Err(FrameParseError::DataLengthMismatch);
277 }
278 if frames.is_empty() {
279 return Err(FrameParseError::NoFramesDecoded);
280 }
281
282 Ok(frames)
283 }
284
285 /// Calculates the size of the frame + overhead for storing the frame. The sum of the frame size
286 /// of each frame in a channel determines the channel's size. The sum of the channel sizes

Callers

nothing calls this directly

Calls 5

newFunction · 0.50
decodeFunction · 0.50
is_emptyMethod · 0.45
lenMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected