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 serialization for empty tuples #158

Merged
merged 1 commit into from
Dec 29, 2020
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 CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

## Pending

The main features of this release are:
Expand Down Expand Up @@ -59,6 +58,7 @@ The main features of this release are:
- #144 (ark-poly) Add serialization for polynomials and evaluations
- #149 (ark-serialize) Add an impl of `CanonicalSerialize/Deserialize` for `String`.
- #153 (ark-serialize) Add an impl of `CanonicalSerialize/Deserialize` for `Rc<T>`.
- #158 (ark-serialize) Add an impl of `CanonicalSerialize/Deserialize` for `()`.

### Bug fixes
- #36 (ark-ec) In Short-Weierstrass curves, include an infinity bit in `ToConstraintField`.
Expand Down
43 changes: 23 additions & 20 deletions serialize/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,13 +352,13 @@ pub const fn buffer_byte_size(modulus_bits: usize) -> usize {

// Implement Serialization for tuples
macro_rules! impl_tuple {
($( $ty: ident : $no: tt, )+) => {
impl<$($ty, )+> CanonicalSerialize for ($($ty,)+) where
$($ty: CanonicalSerialize,)+
($( $ty: ident : $no: tt, )*) => {
impl<$($ty, )*> CanonicalSerialize for ($($ty,)*) where
$($ty: CanonicalSerialize,)*
{
#[inline]
fn serialize<W: Write>(&self, mut writer: W) -> Result<(), SerializationError> {
$(self.$no.serialize(&mut writer)?;)*
fn serialize<W: Write>(&self, mut _writer: W) -> Result<(), SerializationError> {
$(self.$no.serialize(&mut _writer)?;)*
Ok(())
}

Expand All @@ -370,14 +370,14 @@ macro_rules! impl_tuple {
}

#[inline]
fn serialize_uncompressed<W: Write>(&self, mut writer: W) -> Result<(), SerializationError> {
$(self.$no.serialize_uncompressed(&mut writer)?;)*
fn serialize_uncompressed<W: Write>(&self, mut _writer: W) -> Result<(), SerializationError> {
$(self.$no.serialize_uncompressed(&mut _writer)?;)*
Ok(())
}

#[inline]
fn serialize_unchecked<W: Write>(&self, mut writer: W) -> Result<(), SerializationError> {
$(self.$no.serialize_unchecked(&mut writer)?;)*
fn serialize_unchecked<W: Write>(&self, mut _writer: W) -> Result<(), SerializationError> {
$(self.$no.serialize_unchecked(&mut _writer)?;)*
Ok(())
}

Expand All @@ -389,33 +389,34 @@ macro_rules! impl_tuple {
}
}

impl<$($ty, )+> CanonicalDeserialize for ($($ty,)+) where
$($ty: CanonicalDeserialize,)+
impl<$($ty, )*> CanonicalDeserialize for ($($ty,)*) where
$($ty: CanonicalDeserialize,)*
{
#[inline]
fn deserialize<R: Read>(mut reader: R) -> Result<Self, SerializationError> {
fn deserialize<R: Read>(mut _reader: R) -> Result<Self, SerializationError> {
Ok(($(
$ty::deserialize(&mut reader)?,
)+))
$ty::deserialize(&mut _reader)?,
)*))
}

#[inline]
fn deserialize_uncompressed<R: Read>(mut reader: R) -> Result<Self, SerializationError> {
fn deserialize_uncompressed<R: Read>(mut _reader: R) -> Result<Self, SerializationError> {
Ok(($(
$ty::deserialize_uncompressed(&mut reader)?,
)+))
$ty::deserialize_uncompressed(&mut _reader)?,
)*))
}

#[inline]
fn deserialize_unchecked<R: Read>(mut reader: R) -> Result<Self, SerializationError> {
fn deserialize_unchecked<R: Read>(mut _reader: R) -> Result<Self, SerializationError> {
Ok(($(
$ty::deserialize_unchecked(&mut reader)?,
)+))
$ty::deserialize_unchecked(&mut _reader)?,
)*))
}
}
}
}

impl_tuple!();
impl_tuple!(A:0, B:1,);
impl_tuple!(A:0, B:1, C:2,);
impl_tuple!(A:0, B:1, C:2, D:3,);
Expand Down Expand Up @@ -967,6 +968,8 @@ mod test {

#[test]
fn test_tuple() {
test_serialize(());
test_serialize((123u64, Dummy));
test_serialize((123u64, 234u32, Dummy));
}

Expand Down