Skip to content

Not able to serialize and deserialize the PrimeField #121

Description

@AnmolBansalDEV

I want to be able to reconstruct the PrimeField and also be able to store it in a db/text file or any other thing so that if my node goes down I'm able to recover my Field.

Serde doesn't automatically serialize the PrimeField, so I'm trying to write a custom serializer but not able to figure out. I think my serializer is working but can't figure out deserializer.

    pub fn serialize<S, T>(field: &T, serializer: S) -> Result<S::Ok, S::Error>
    where
        S: Serializer,
        T: PrimeField,
    {
        let bytes = field.to_repr();
        let bits = bytes.as_bits::<Lsb0>();
        let str = bits.to_string();
        serializer.serialize_str(&str)
    }

Would appreciate help writing a deserializer as well. Thanks for the help!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions