// SPDX-License-Identifier: AGPL-3.0-or-later use super::{from_vec, to_vec, Result}; use serde::{Deserialize, Serialize}; use serde_big_array::BigArray; #[test] fn test_empty_array_deserialization() -> Result<()> { #[derive(Deserialize, Debug, PartialEq)] struct Vacuous { // Of course you would never actually do this, but it should handle it properly regardless. #[serde(with = "BigArray")] nothing: [u8; 0], } let expected = Vacuous { nothing: [0u8; 0] }; let vec = vec![]; let result = from_vec(&vec); assert_eq!(expected, result?); Ok(()) } #[derive(Serialize, Deserialize, Debug, PartialEq)] struct S { #[serde(with = "BigArray")] array: [u8; 0x40], } #[test] fn test_big_array_deserialization() -> Result<()> { let expected = S { array: [ 0x81, 0xc0, 0xf, 0x3e, 0x2f, 0x11, 0xae, 0xc9, 0x48, 0x68, 0xc4, 0x66, 0x67, 0x1e, 0xda, 0x4e, 0xde, 0xf, 0x84, 0x23, 0x4d, 0x24, 0x0, 0x23, 0xe8, 0x84, 0xac, 0xc6, 0x7c, 0xb0, 0x34, 0x5, 0xa3, 0xc3, 0x4b, 0x59, 0xaa, 0x96, 0x9f, 0xc6, 0x2d, 0x31, 0x5a, 0xb5, 0x61, 0xfd, 0xad, 0x9b, 0x7a, 0xf8, 0xf3, 0xd7, 0xee, 0x4a, 0x86, 0xd7, 0x87, 0x20, 0x33, 0x32, 0x12, 0xc9, 0x55, 0x1e, ], }; let mut vec = vec![0; 0x40]; vec.copy_from_slice(expected.array.as_slice()); let result = from_vec(&vec); assert_eq!(expected, result?); Ok(()) } #[test] fn test_big_array_serialization() -> Result<()> { let value = S { array: [ 0x81, 0xc0, 0xf, 0x3e, 0x2f, 0x11, 0xae, 0xc9, 0x48, 0x68, 0xc4, 0x66, 0x67, 0x1e, 0xda, 0x4e, 0xde, 0xf, 0x84, 0x23, 0x4d, 0x24, 0x0, 0x23, 0xe8, 0x84, 0xac, 0xc6, 0x7c, 0xb0, 0x34, 0x5, 0xa3, 0xc3, 0x4b, 0x59, 0xaa, 0x96, 0x9f, 0xc6, 0x2d, 0x31, 0x5a, 0xb5, 0x61, 0xfd, 0xad, 0x9b, 0x7a, 0xf8, 0xf3, 0xd7, 0xee, 0x4a, 0x86, 0xd7, 0x87, 0x20, 0x33, 0x32, 0x12, 0xc9, 0x55, 0x1e, ], }; let mut expected = vec![0; 0x40]; expected.copy_from_slice(value.array.as_slice()); let result = to_vec(&value); assert_eq!(expected, result?); Ok(()) }