feat: Move flat en/de from aiken to pallas (#303)

Nothing new is going on within the code itself.
I simply popped the crate into pallas_codec
as a submodule `pallas_codec::flat`. I also moved
over the tests that we had in the crate. In general
this is in solid shape and hasn't had any changes for
months. That said there could be some things that require love
like dealing with BigInt.

Co-authored-by: Kasey White <kwhitemsg@gmail.com>
This commit is contained in:
Lucas 2023-10-04 19:08:52 -04:00 committed by GitHub
parent f82fbcd7d9
commit 11687d7f85
15 changed files with 1122 additions and 15 deletions

View file

@ -0,0 +1,67 @@
mod decoder;
mod error;
use crate::flat::filler::Filler;
pub use decoder::Decoder;
pub use error::Error;
pub trait Decode<'b>: Sized {
fn decode(d: &mut Decoder) -> Result<Self, Error>;
}
impl Decode<'_> for Filler {
fn decode(d: &mut Decoder) -> Result<Filler, Error> {
d.filler()?;
Ok(Filler::FillerEnd)
}
}
impl Decode<'_> for Vec<u8> {
fn decode(d: &mut Decoder) -> Result<Self, Error> {
d.bytes()
}
}
impl Decode<'_> for u8 {
fn decode(d: &mut Decoder) -> Result<Self, Error> {
d.u8()
}
}
impl Decode<'_> for isize {
fn decode(d: &mut Decoder) -> Result<Self, Error> {
d.integer()
}
}
impl Decode<'_> for i128 {
fn decode(d: &mut Decoder) -> Result<Self, Error> {
d.big_integer()
}
}
impl Decode<'_> for usize {
fn decode(d: &mut Decoder) -> Result<Self, Error> {
d.word()
}
}
impl Decode<'_> for char {
fn decode(d: &mut Decoder) -> Result<Self, Error> {
d.char()
}
}
impl Decode<'_> for String {
fn decode(d: &mut Decoder) -> Result<Self, Error> {
d.utf8()
}
}
impl Decode<'_> for bool {
fn decode(d: &mut Decoder) -> Result<bool, Error> {
d.bool()
}
}