Skip to content

Commit

Permalink
Implement BorshSchema (#498)
Browse files Browse the repository at this point in the history
  • Loading branch information
jnitard committed Mar 24, 2022
1 parent 2de2a6d commit 88125c8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/decimal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,10 @@ pub struct UnpackedDecimal {
#[derive(Clone, Copy)]
#[cfg_attr(feature = "diesel", derive(FromSqlRow, AsExpression), sql_type = "Numeric")]
#[cfg_attr(feature = "c-repr", repr(C))]
#[cfg_attr(feature = "borsh", derive(borsh::BorshDeserialize, borsh::BorshSerialize))]
#[cfg_attr(
feature = "borsh",
derive(borsh::BorshDeserialize, borsh::BorshSerialize, borsh::BorshSchema)
)]
pub struct Decimal {
// Bits 0-15: unused
// Bits 16-23: Contains "e", a value between 0-28 that indicates the scale
Expand Down
3 changes: 3 additions & 0 deletions tests/decimal_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ fn it_can_serialize_deserialize_borsh() {
borsh::BorshSerialize::serialize(&a, &mut bytes).unwrap();
let b: Decimal = borsh::BorshDeserialize::deserialize(&mut bytes.as_slice()).unwrap();
assert_eq!(test.to_string(), b.to_string());
let bytes = borsh::schema_helper::serialize_with_schema(&a);
let b: Decimal = borsh::schema_helper::deserialize_with_schema(&bytes);
assert_eq!(test.to_string(), b.to_string());
}
}

Expand Down

0 comments on commit 88125c8

Please sign in to comment.