binius_utils/
serialization.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// Copyright 2024 Irreducible Inc.
use bytes::{Buf, BufMut};

#[derive(Clone, thiserror::Error, Debug)]
pub enum Error {
	#[error("Incorrect byte array length")]
	IncorrectLengthByteSlice,
	#[error("Write buffer is full")]
	WriteBufferFull,
	#[error("Not enough data in read buffer to deserialize")]
	NotEnoughBytes,
}

pub trait SerializeBytes {
	fn serialize(&self, write_buf: impl BufMut) -> Result<(), Error>;
}

pub trait DeserializeBytes {
	fn deserialize(read_buf: impl Buf) -> Result<Self, Error>
	where
		Self: Sized;
}