-
Notifications
You must be signed in to change notification settings - Fork 153
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
Update to new empty amt serialization #623
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,11 +37,11 @@ pub fn deserialize<'de, D>(deserializer: D) -> Result<BigInt, D::Error> | |
where | ||
D: serde::Deserializer<'de>, | ||
{ | ||
let mut bz: Vec<u8> = serde_bytes::Deserialize::deserialize(deserializer)?; | ||
let bz: &[u8] = serde_bytes::Deserialize::deserialize(deserializer)?; | ||
if bz.is_empty() { | ||
return Ok(BigInt::default()); | ||
} | ||
let sign_byte = bz.remove(0); | ||
let sign_byte = bz[0]; | ||
let sign: Sign = match sign_byte { | ||
1 => Sign::Minus, | ||
0 => Sign::Plus, | ||
|
@@ -51,5 +51,5 @@ where | |
)); | ||
} | ||
}; | ||
Ok(BigInt::from_bytes_be(sign, &bz)) | ||
Ok(BigInt::from_bytes_be(sign, &bz[1..])) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What happens if there's only a sign byte? This will panic i think, but what is the expected behaviour? I would assume 0 or something, since empty bytes -> bigint deserializes to 0? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. on the 0 case, it is serialized as empty bytes, even if it was a sign byte and nothing else, this would just deserialize as zero. Also the functionality is basically the same as it was before. |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,16 +35,16 @@ pub fn deserialize<'de, D>(deserializer: D) -> Result<BigUint, D::Error> | |
where | ||
D: serde::Deserializer<'de>, | ||
{ | ||
let mut bz: Vec<u8> = serde_bytes::Deserialize::deserialize(deserializer)?; | ||
let bz: &[u8] = serde_bytes::Deserialize::deserialize(deserializer)?; | ||
if bz.is_empty() { | ||
return Ok(BigUint::default()); | ||
} | ||
|
||
if bz.remove(0) != 0 { | ||
if bz.get(0) != Some(&0) { | ||
return Err(serde::de::Error::custom( | ||
"First byte must be 0 to decode as BigUint", | ||
)); | ||
} | ||
|
||
Ok(BigUint::from_bytes_be(&bz)) | ||
Ok(BigUint::from_bytes_be(&bz[1..])) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same thing here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. empty bytes get serialized as 0 and this would still not have an issue (but again Lotus and our client would not ever serialize as this case) |
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cow!!!!!