-
Notifications
You must be signed in to change notification settings - Fork 88
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
Support for UInt256
#48
Comments
Hi, thanks for the questions! U256Now there is no default way to do it in this crate because I don't know one good crate for it. For instance, However, you can implement ser/de for mod u256 {
use primitive_types::U256;
use serde::{
de::{Deserialize, Deserializer},
ser::{Serialize, Serializer},
};
pub fn serialize<S: Serializer>(u: &U256, serializer: S) -> Result<S::Ok, S::Error> {
u.0.serialize(serializer)
}
pub fn deserialize<'de, D>(deserializer: D) -> Result<U256, D::Error>
where
D: Deserializer<'de>,
{
let u: [u64; 4] = Deserialize::deserialize(deserializer)?;
Ok(U256(u))
}
}
#[derive(Debug, Row, Serialize, Deserialize)]
struct MyRow {
#[serde(with = "u256")]
u: U256,
} I'm not sure it works correctly on big-endian machines, because I believe the documentation lies that it's LE. So, a more reliable way to do ser/de is pub fn serialize<S: Serializer>(u: &U256, serializer: S) -> Result<S::Ok, S::Error> {
let mut buf: [u8; 32] = [0; 32];
u.to_little_endian(&mut buf);
buf.serialize(serializer)
}
pub fn deserialize<'de, D>(deserializer: D) -> Result<U256, D::Error>
where
D: Deserializer<'de>,
{
let u: [u8; 32] = Deserialize::deserialize(deserializer)?;
Ok(U256::from_little_endian(&u))
} DateTime
|
Thank you so much for the very detailed answer. This is great 👍 I'll use the implementation you suggested for U256 and wait for |
Closing since 0.11.1 has been released! Thank you. |
Reopened, because the issue is about |
Regarding
U256
, not sure if there is one, what should we use? Something like this would be nice.I saw a previous discussion about
DateTime
in Insert a DateTime Type #1. Any interest in supporting chrono or time instead ofu32
?The text was updated successfully, but these errors were encountered: