halo2curves_axiom/
serde.rs

1use std::io::{self, Read, Write};
2
3/// Trait for converting raw bytes to/from the internal representation of a type.
4/// For example, field elements are represented in Montgomery form and serialized/deserialized without Montgomery reduction.
5pub trait SerdeObject: Sized {
6    /// The purpose of unchecked functions is to read the internal memory representation
7    /// of a type from bytes as quickly as possible. No sanitization checks are performed
8    /// to ensure the bytes represent a valid object. As such this function should only be
9    /// used internally as an extension of machine memory. It should not be used to deserialize
10    /// externally provided data.
11    fn from_raw_bytes_unchecked(bytes: &[u8]) -> Self;
12    fn from_raw_bytes(bytes: &[u8]) -> Option<Self>;
13
14    fn to_raw_bytes(&self) -> Vec<u8>;
15
16    /// The purpose of unchecked functions is to read the internal memory representation
17    /// of a type from disk as quickly as possible. No sanitization checks are performed
18    /// to ensure the bytes represent a valid object. This function should only be used
19    /// internally when some machine state cannot be kept in memory (e.g., between runs)
20    /// and needs to be reloaded as quickly as possible.
21    fn read_raw_unchecked<R: Read>(reader: &mut R) -> Self;
22    fn read_raw<R: Read>(reader: &mut R) -> io::Result<Self>;
23
24    fn write_raw<W: Write>(&self, writer: &mut W) -> io::Result<()>;
25}