feat: support Int256/UInt256
#352
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This ended up being harder than expected because the Serde data model has no support for 256-bit integers, and just serializing to bytes gave the wrong result because it adds a length prefix. This required quite a bit of hacking around.
These are problems we shouldn't have when we implement bespoke traits: #336
I ended up punting on explicitly adding any crate integrations, as there's no obvious winners:
ruint(used in the Alloy Ethereum SDK) only supports unsigned integersCargo.lockin a way that annoys users and confuses automated tools, e.g. triggering RUSTSEC alerts on crates that aren't actually used; we learned this the hard way in SQLx: [KNOWN ISSUE] Unexpected/unwanted crates inCargo.locklaunchbadge/sqlx#3211primitive-typesis specifically designed for use with Ethereum, and also only supports unsigned integers.bnum(which I did use in the implementation) is worth watching because it supports both signed and unsigned integers, but to expose it now would be a SemVer hazard because it looks to have some major breaking changes on the horizon: Design choices and new features for big upcoming update to bnum isaacholt100/bnum#54num-bigintbecause it requires dynamic allocationsIn most cases, these types have
from_le_bytes/to_le_bytes(orfrom_little_endian/to_little_endian) methods that can be used to manually convert using{UInt256, Int256}::to_le_bytesandfrom_le_bytes, respectively.closes #48
closes #308
CHANGELOG Description
clickhouse::types::{UInt256, Int256}for serializing and deserializing 256-bit integers.FromandTryIntotraits, and thefrom_le_bytes()andto_le_bytes()methods.Int256/UInt256#352 for details.Checklist
Delete items not relevant to your PR: