~tdeo/serde_bare

b08eb8cabacbefcedb1e51dee5f9ab78dd59c7a3 — Tadeo Kondrak 1 year, 3 months ago 422b08c
Add explicit i128 errors
5 files changed, 46 insertions(+), 17 deletions(-)

M README
M src/de.rs
M src/error.rs
M src/lib.rs
M src/ser.rs
M README => README +1 -6
@@ 1,11 1,6 @@
serde_bare

An incomplete implementation of the BARE (https://git.sr.ht/~sircmpwn/bare) encoding format.

Missing types:
    - i128 (in Serde's data model, not in BARE)
    - u128 (in Serde's data model, not in BARE)
    - tagged unions (in BARE, not immediately clear how to integrate with Serde's data model)
An implementation of the BARE (https://git.sr.ht/~sircmpwn/bare) encoding format draft.

Licensed under either of Apache License, Version 2.0 or MIT license at your option.


M src/de.rs => src/de.rs +20 -0
@@ 78,6 78,16 @@ where
        visitor.visit_i64(i64::from_le_bytes(buf))
    }

    serde::serde_if_integer128! {
        /// Returns Error::I128Unsupported.
        fn deserialize_i128<V>(self, _visitor: V) -> Result<V::Value, Self::Error>
        where
            V: de::Visitor<'de>
        {
            Err(Error::I128Unsupported)
        }
    }

    /// BARE type: u8
    fn deserialize_u8<V>(self, visitor: V) -> Result<V::Value, Self::Error>
    where


@@ 118,6 128,16 @@ where
        visitor.visit_u64(u64::from_le_bytes(buf))
    }

    serde::serde_if_integer128! {
        /// Returns Error::U128Unsupported.
        fn deserialize_u128<V>(self, _visitor: V) -> Result<V::Value, Self::Error>
        where
            V: de::Visitor<'de>
        {
            Err(Error::U128Unsupported)
        }
    }

    /// BARE type: f32
    fn deserialize_f32<V>(self, visitor: V) -> Result<V::Value, Self::Error>
    where

M src/error.rs => src/error.rs +10 -5
@@ 10,10 10,15 @@ pub type Result<T> = std::result::Result<T, Error>;
pub enum Error {
    Message(String),
    Io(io::Error),

    AnyUnsupported,
    I128Unsupported,
    U128Unsupported,
    IdentifierUnsupported,

    InvalidUtf8,
    InvalidBool,
    IdentifierUnsupported,

    LengthOverflow,
    MapLengthRequired,
}


@@ 35,12 40,12 @@ impl Display for Error {
        match self {
            Error::Message(msg) => formatter.write_str(msg),
            Error::Io(e) => e.fmt(formatter),
            Error::AnyUnsupported => {
                formatter.write_str("any is unsupported because BARE is not self-describing")
            }
            Error::AnyUnsupported => formatter.write_str("BARE does not support any"),
            Error::U128Unsupported => formatter.write_str("Bare does not support u128"),
            Error::I128Unsupported => formatter.write_str("Bare does not support i128"),
            Error::IdentifierUnsupported => formatter.write_str("BARE does not support identifier"),
            Error::InvalidUtf8 => formatter.write_str("invalid utf-8 in string"),
            Error::InvalidBool => formatter.write_str("invalid bool, neither 0 or 1"),
            Error::IdentifierUnsupported => formatter.write_str("identifier is not supported"),
            Error::LengthOverflow => formatter.write_str("length above u32::MAX"),
            Error::MapLengthRequired => formatter.write_str("map length required"),
        }

M src/lib.rs => src/lib.rs +1 -6
@@ 2,12 2,7 @@
//!```text
//! serde_bare
//!
//! An incomplete implementation of the BARE (https://git.sr.ht/~sircmpwn/bare) encoding format.
//!
//! Missing types:
//!     - i128 (in Serde's data model, not in BARE)
//!     - u128 (in Serde's data model, not in BARE)
//!     - tagged unions (in BARE, not immediately clear how to integrate with Serde's data model)
//! An implementation of the BARE (https://git.sr.ht/~sircmpwn/bare) encoding format draft.
//!```

pub mod de;

M src/ser.rs => src/ser.rs +14 -0
@@ 63,6 63,13 @@ where
        Ok(())
    }

    serde::serde_if_integer128! {
        /// Returns Error::I128Unsupported.
        fn serialize_i128(self, _v: i128) -> Result<Self::Ok, Self::Error> {
            Err(Error::I128Unsupported)
        }
    }

    /// BARE type: u8
    fn serialize_u8(self, v: u8) -> Result<Self::Ok, Self::Error> {
        self.writer


@@ 95,6 102,13 @@ where
        Ok(())
    }

    serde::serde_if_integer128! {
        /// Returns Error::U128Unsupported.
        fn serialize_u128(self, _v: u128) -> Result<Self::Ok, Self::Error> {
            Err(Error::U128Unsupported)
        }
    }

    /// BARE type: f32
    fn serialize_f32(self, v: f32) -> Result<Self::Ok, Self::Error> {
        self.writer