You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
978 B

  1. // Copyright (c) 2023 Espresso Systems (espressosys.com)
  2. // This file is part of the HyperPlonk library.
  3. // You should have received a copy of the MIT License
  4. // along with the HyperPlonk library. If not, see <https://mit-license.org/>.
  5. //! useful macros.
  6. /// Takes as input a struct, and converts them to a series of bytes. All traits
  7. /// that implement `CanonicalSerialize` can be automatically converted to bytes
  8. /// in this manner.
  9. #[macro_export]
  10. macro_rules! to_bytes {
  11. ($x:expr) => {{
  12. let mut buf = ark_std::vec![];
  13. ark_serialize::CanonicalSerialize::serialize_compressed($x, &mut buf).map(|_| buf)
  14. }};
  15. }
  16. #[cfg(test)]
  17. mod test {
  18. use ark_bls12_381::Fr;
  19. use ark_serialize::CanonicalSerialize;
  20. use ark_std::One;
  21. #[test]
  22. fn test_to_bytes() {
  23. let f1 = Fr::one();
  24. let mut bytes = ark_std::vec![];
  25. f1.serialize_compressed(&mut bytes).unwrap();
  26. assert_eq!(bytes, to_bytes!(&f1).unwrap());
  27. }
  28. }