Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for 128bit numbers #24

Merged
merged 2 commits into from
Aug 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ keywords = ["serde", "erasure"]
include = ["Cargo.toml", "src/**/*.rs", "LICENSE-*"]

[dependencies]
serde = "1.0"
serde = "1.0.63"

[dev-dependencies]
serde_cbor = "0.8"
Expand Down
50 changes: 50 additions & 0 deletions src/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ pub trait Deserializer<'de> {
fn erased_deserialize_i16(&mut self, &mut Visitor<'de>) -> Result<Out, Error>;
fn erased_deserialize_i32(&mut self, &mut Visitor<'de>) -> Result<Out, Error>;
fn erased_deserialize_i64(&mut self, &mut Visitor<'de>) -> Result<Out, Error>;
serde_if_integer128! {
fn erased_deserialize_i128(&mut self, &mut Visitor<'de>) -> Result<Out, Error>;
fn erased_deserialize_u128(&mut self, &mut Visitor<'de>) -> Result<Out, Error>;
}
fn erased_deserialize_f32(&mut self, &mut Visitor<'de>) -> Result<Out, Error>;
fn erased_deserialize_f64(&mut self, &mut Visitor<'de>) -> Result<Out, Error>;
fn erased_deserialize_char(&mut self, &mut Visitor<'de>) -> Result<Out, Error>;
Expand Down Expand Up @@ -131,6 +135,10 @@ pub trait Visitor<'de> {
fn erased_visit_u16(&mut self, u16) -> Result<Out, Error>;
fn erased_visit_u32(&mut self, u32) -> Result<Out, Error>;
fn erased_visit_u64(&mut self, u64) -> Result<Out, Error>;
serde_if_integer128! {
fn erased_visit_i128(&mut self, i128) -> Result<Out, Error>;
fn erased_visit_u128(&mut self, u128) -> Result<Out, Error>;
}
fn erased_visit_f32(&mut self, f32) -> Result<Out, Error>;
fn erased_visit_f64(&mut self, f64) -> Result<Out, Error>;
fn erased_visit_char(&mut self, char) -> Result<Out, Error>;
Expand Down Expand Up @@ -327,6 +335,14 @@ impl<'de, T> Deserializer<'de> for erase::Deserializer<T> where T: serde::Deseri
fn erased_deserialize_i64(&mut self, visitor: &mut Visitor<'de>) -> Result<Out, Error> {
self.take().deserialize_i64(visitor).map_err(erase)
}
serde_if_integer128! {
fn erased_deserialize_i128(&mut self, visitor: &mut Visitor<'de>) -> Result<Out, Error> {
self.take().deserialize_i128(visitor).map_err(erase)
}
fn erased_deserialize_u128(&mut self, visitor: &mut Visitor<'de>) -> Result<Out, Error> {
self.take().deserialize_u128(visitor).map_err(erase)
}
}
fn erased_deserialize_f32(&mut self, visitor: &mut Visitor<'de>) -> Result<Out, Error> {
self.take().deserialize_f32(visitor).map_err(erase)
}
Expand Down Expand Up @@ -420,6 +436,14 @@ impl<'de, T> Visitor<'de> for erase::Visitor<T> where T: serde::de::Visitor<'de>
fn erased_visit_u64(&mut self, v: u64) -> Result<Out, Error> {
self.take().visit_u64(v).map(Out::new)
}
serde_if_integer128! {
fn erased_visit_i128(&mut self, v: i128) -> Result<Out, Error> {
self.take().visit_i128(v).map(Out::new)
}
fn erased_visit_u128(&mut self, v: u128) -> Result<Out, Error> {
self.take().visit_u128(v).map(Out::new)
}
}
fn erased_visit_f32(&mut self, v: f32) -> Result<Out, Error> {
self.take().visit_f32(v).map(Out::new)
}
Expand Down Expand Up @@ -572,6 +596,16 @@ macro_rules! impl_deserializer_for_trait_object {
let mut erased = erase::Visitor { state: Some(visitor) };
self.erased_deserialize_i64(&mut erased).map(Out::take)
}
serde_if_integer128! {
fn deserialize_i128<V>($($mut)* self, visitor: V) -> Result<V::Value, Error> where V: serde::de::Visitor<'de> {
let mut erased = erase::Visitor { state: Some(visitor) };
self.erased_deserialize_i128(&mut erased).map(Out::take)
}
fn deserialize_u128<V>($($mut)* self, visitor: V) -> Result<V::Value, Error> where V: serde::de::Visitor<'de> {
let mut erased = erase::Visitor { state: Some(visitor) };
self.erased_deserialize_u128(&mut erased).map(Out::take)
}
}
fn deserialize_f32<V>($($mut)* self, visitor: V) -> Result<V::Value, Error> where V: serde::de::Visitor<'de> {
let mut erased = erase::Visitor { state: Some(visitor) };
self.erased_deserialize_f32(&mut erased).map(Out::take)
Expand Down Expand Up @@ -696,6 +730,14 @@ impl<'de, 'a> serde::de::Visitor<'de> for &'a mut Visitor<'de> {
fn visit_u64<E>(self, v: u64) -> Result<Out, E> where E: serde::de::Error {
self.erased_visit_u64(v).map_err(unerase)
}
serde_if_integer128! {
fn visit_i128<E>(self, v: i128) -> Result<Out, E> where E: serde::de::Error {
self.erased_visit_i128(v).map_err(unerase)
}
fn visit_u128<E>(self, v: u128) -> Result<Out, E> where E: serde::de::Error {
self.erased_visit_u128(v).map_err(unerase)
}
}
fn visit_f32<E>(self, v: f32) -> Result<Out, E> where E: serde::de::Error {
self.erased_visit_f32(v).map_err(unerase)
}
Expand Down Expand Up @@ -848,6 +890,14 @@ macro_rules! deref_erased_deserializer {
fn erased_deserialize_i64(&mut self, visitor: &mut Visitor<'de>) -> Result<Out, Error> {
(**self).erased_deserialize_i64(visitor)
}
serde_if_integer128! {
fn erased_deserialize_i128(&mut self, visitor: &mut Visitor<'de>) -> Result<Out, Error> {
(**self).erased_deserialize_i128(visitor)
}
fn erased_deserialize_u128(&mut self, visitor: &mut Visitor<'de>) -> Result<Out, Error> {
(**self).erased_deserialize_u128(visitor)
}
}
fn erased_deserialize_f32(&mut self, visitor: &mut Visitor<'de>) -> Result<Out, Error> {
(**self).erased_deserialize_f32(visitor)
}
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@

#![cfg_attr(feature = "unstable-debug", feature(core_intrinsics))]

#[macro_use]
extern crate serde;

#[cfg(test)]
Expand Down
28 changes: 28 additions & 0 deletions src/ser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ pub trait Serializer {
fn erased_serialize_u16(&mut self, u16) -> Result<Ok, Error>;
fn erased_serialize_u32(&mut self, u32) -> Result<Ok, Error>;
fn erased_serialize_u64(&mut self, u64) -> Result<Ok, Error>;
serde_if_integer128! {
fn erased_serialize_i128(&mut self, i128) -> Result<Ok, Error>;
fn erased_serialize_u128(&mut self, u128) -> Result<Ok, Error>;
}
fn erased_serialize_f32(&mut self, f32) -> Result<Ok, Error>;
fn erased_serialize_f64(&mut self, f64) -> Result<Ok, Error>;
fn erased_serialize_char(&mut self, char) -> Result<Ok, Error>;
Expand Down Expand Up @@ -261,6 +265,14 @@ impl<T> Serializer for erase::Serializer<T> where T: serde::Serializer {
fn erased_serialize_u64(&mut self, v: u64) -> Result<Ok, Error> {
self.take().serialize_u64(v).map(Ok::new).map_err(erase)
}
serde_if_integer128! {
fn erased_serialize_i128(&mut self, v: i128) -> Result<Ok, Error> {
self.take().serialize_i128(v).map(Ok::new).map_err(erase)
}
fn erased_serialize_u128(&mut self, v: u128) -> Result<Ok, Error> {
self.take().serialize_u128(v).map(Ok::new).map_err(erase)
}
}
fn erased_serialize_f32(&mut self, v: f32) -> Result<Ok, Error> {
self.take().serialize_f32(v).map(Ok::new).map_err(erase)
}
Expand Down Expand Up @@ -411,6 +423,14 @@ macro_rules! impl_serializer_for_trait_object {
fn serialize_u64(self, v: u64) -> Result<Ok, Error> {
self.erased_serialize_u64(v)
}
serde_if_integer128! {
fn serialize_i128(self, v: i128) -> Result<Ok, Error> {
self.erased_serialize_i128(v)
}
fn serialize_u128(self, v: u128) -> Result<Ok, Error> {
self.erased_serialize_u128(v)
}
}
fn serialize_f32(self, v: f32) -> Result<Ok, Error> {
self.erased_serialize_f32(v)
}
Expand Down Expand Up @@ -757,6 +777,14 @@ macro_rules! deref_erased_serializer {
fn erased_serialize_u64(&mut self, v: u64) -> Result<Ok, Error> {
(**self).erased_serialize_u64(v)
}
serde_if_integer128! {
fn erased_serialize_i128(&mut self, v: i128) -> Result<Ok, Error> {
(**self).erased_serialize_i128(v)
}
fn erased_serialize_u128(&mut self, v: u128) -> Result<Ok, Error> {
(**self).erased_serialize_u128(v)
}
}
fn erased_serialize_f32(&mut self, v: f32) -> Result<Ok, Error> {
(**self).erased_serialize_f32(v)
}
Expand Down