kona_protocol/batch/
type.rs1use alloy_rlp::{Decodable, Encodable};
14
15pub const SINGLE_BATCH_TYPE: u8 = 0x00;
17
18pub const SPAN_BATCH_TYPE: u8 = 0x01;
20
21#[derive(Debug, Clone, PartialEq, Eq)]
23#[repr(u8)]
24pub enum BatchType {
25 Single = SINGLE_BATCH_TYPE,
27 Span = SPAN_BATCH_TYPE,
29}
30
31impl From<u8> for BatchType {
32 fn from(val: u8) -> Self {
33 match val {
34 SINGLE_BATCH_TYPE => Self::Single,
35 SPAN_BATCH_TYPE => Self::Span,
36 _ => panic!("Invalid batch type: {val}"),
37 }
38 }
39}
40
41impl Encodable for BatchType {
42 fn encode(&self, out: &mut dyn alloy_rlp::BufMut) {
43 let val = match self {
44 Self::Single => SINGLE_BATCH_TYPE,
45 Self::Span => SPAN_BATCH_TYPE,
46 };
47 val.encode(out);
48 }
49}
50
51impl Decodable for BatchType {
52 fn decode(buf: &mut &[u8]) -> alloy_rlp::Result<Self> {
53 let val = u8::decode(buf)?;
54 Ok(Self::from(val))
55 }
56}
57
58#[cfg(test)]
59mod test {
60 use super::*;
61 use alloc::vec::Vec;
62
63 #[test]
64 fn test_batch_type_rlp_roundtrip() {
65 let batch_type = BatchType::Single;
66 let mut buf = Vec::new();
67 batch_type.encode(&mut buf);
68 let decoded = BatchType::decode(&mut buf.as_slice()).unwrap();
69 assert_eq!(batch_type, decoded);
70 }
71}