-
Notifications
You must be signed in to change notification settings - Fork 107
Support for UInt256
#48
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
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 |
What's the status on this one. We are dealing with UInt256/Int256 data types. There should be a better way of handling this. Using the workaround above currently. |
For anyone who is using ruint directly or the alloy-rs re-export of it, this is how I am doing serde: pub mod u256 {
use alloy_primitives::U256;
use serde::{
de::{Deserialize, Deserializer},
ser::{Serialize, Serializer},
};
/// evm U256 is represented in big-endian, but ClickHouse expects little-endian
pub fn serialize<S: Serializer>(u: &U256, serializer: S) -> Result<S::Ok, S::Error> {
let buf: [u8; 32] = u.to_le_bytes();
buf.serialize(serializer)
}
/// ClickHouse stores U256 in little-endian
pub fn deserialize<'de, D>(deserializer: D) -> Result<U256, D::Error>
where
D: Deserializer<'de>,
{
let buf: [u8; 32] = Deserialize::deserialize(deserializer)?;
Ok(U256::from_le_bytes(buf))
}
} |
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: