-
Notifications
You must be signed in to change notification settings - Fork 55
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
hex serde #278
base: master
Are you sure you want to change the base?
Conversation
let n = self.0; | ||
let (h4, h3, h2, h1) = ( | ||
(n >> 48) & 0xffff, | ||
(n >> 32) & 0xffff, | ||
(n >> 16) & 0xffff, | ||
n & 0xffff, | ||
); | ||
let f = if h4 != 0 { | ||
format!("0x{h4:04x}{h3:04x}{h2:04x}{h1:04x}") | ||
} else if h3 != 0 { | ||
format!("0x{h3:04x}{h2:04x}{h1:04x}") | ||
} else if h2 != 0 { | ||
format!("0x{h2:04x}{h1:04x}") | ||
} else if h1 & 0xff00 != 0 { | ||
format!("0x{h1:04x}") | ||
} else if h1 != 0 { | ||
format!("0x{:02x}", h1 & 0xff) | ||
} else { | ||
"0".to_string() | ||
}; | ||
serializer.serialize_str(&f) |
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.
this could be replaced with
let hex_length = ((64 - n.leading_zeros() + 3)/4) as usize;
let width = (4 - (hex_length % 4)) % 4 + hex_length;
format!("0x{:0width$x}", n)
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.
Forgot about this. Thanks.
But there is bigger issue. It does not do what I want. It creates |
yeah, that's something for the serializer to do,
|
No description provided.