-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Conversation
}; | ||
} | ||
|
||
impl_tuples!(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R); |
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.
Please use impl_for_tuples
for this
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.
Ok: 0204e2f.
$( | ||
impl BoundedEncodedLen for $t { | ||
fn max_encoded_len() -> usize { | ||
// a compact encoding of a primitive can take 1 byte more than its actual size |
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.
But a primitive will never be compact encoded automatically?
You would need to implement the trait for Compact<T>
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.
Good point. d249f57
Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
…ate into prgn-boundedencodedlen
S: Get<u32>, | ||
BoundedVec<T, S>: Encode, | ||
{ | ||
fn max_encoded_len() -> usize { |
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.
the least significant comment: pity not to see SomeTrait { fn some_trait() }
, why not trait MaxEncodedLen
?
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.
No reason really; I like MaxEncodedLen
because it's shorter and agrees with the trait's function. af0b814
T: BoundedEncodedLen, | ||
{ | ||
// The compact encoding of a type usually requires fewer bytes, but can occupy 1 additional | ||
// byte in the worst 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.
I'd be curious to know exactly which case takes 1 extra byte?
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.
In general, our Compact
encoding uses two bits to indicate how many bytes follow. Therefore, we need an extra byte for all cases where T::count_ones() > T::BIT_WIDTH - 2
. u8
example.
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.
2^14 takes 4 bytes to be encoded in a compact way whereas it takes only 2 bytes to be encoded as a regular u16
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.
LGTM
Turns out that u16 doesn't play nicely with the pattern; those values take two extra bytes, where all other cases take one. :(
u64 => 9; | ||
// https://github.com/paritytech/parity-scale-codec/blob/f0341dabb01aa9ff0548558abb6dcc5c31c669a1/src/compact.rs#L413 | ||
u128 => 17; | ||
); |
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.
we could add a test that ensures Compact(u8::max_value()).encode().len()
is correctly 2 bytes etc... but anyway values are good to me.
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.
Yes, agree. 8b8576d.
bot merge |
Waiting for commit status. |
I like this. It should be feasible to write a derive macro in order to have this for composite data structures, right? |
Yes, I'm working on the derive macro right now.
…On Wed, May 5, 2021 at 10:49 AM Alexander Theißen ***@***.***> wrote:
I like this. It should be feasible to write a derive macro in order to
have this for composite data structures, right?
—
You are receiving this because you were assigned.
Reply to this email directly, view it on GitHub
<#8720 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AB3V4TQCHDOZMM6KOTZDEBTTMEBATANCNFSM44CJRZJA>
.
--
Wichtige Mitteilung
Diese Mitteilung wurde von Parity Technologies
Deutschland GmbH kommuniziert, eine im Handelsregister des Amtsgerichtes
Charlottenburg unter HRB 190583 B registrierte Gesellschaft mit
beschränkter Haftung (GmbH). Die Geschäftsführerin der GmbH ist Frau Dr.
Jutta Steiner. Der registrierte Geschäftssitz ist Glogauer Straße 6 in
10999 Berlin, Deutschland.
Diese Mitteilung enthält Informationen welche
vertraulich sind und welche eventuell die Vertraulichkeit der
Rechtsberatung ("Anwaltsgeheimnis") berühren. Sie ist ausschließlich für
den/die vorgesehenen Empfänger bestimmt. Wenn Sie nicht der/die
beabsichtigte(n) Empfänger sind, benachrichtigen Sie bitte ***@***.***
***@***.***> und löschen Sie diese Nachricht sofort.
Unsere
Datenschutzrichtlinie, einschließlich die Art und den Umfang von
personenbezogenen Daten, die wir erfassen, wie wir diese Daten erfassen und
verarbeiten, an wen wir sie in Bezug auf die von uns angebotenen Dienste
weitergeben dürfen, sowie bestimmte Rechte und Optionen, die Sie in dieser
Hinsicht haben, finden Sie unter: https://www.parity.io/privacy/
<https://www.parity.io/privacy/>
|
* implement BoundedEncodedLen * update header * update imports * use impl_for_tuples instead of a custom macro * remove redundant where clause Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * impl for Compact<T> * impl BoundedEncodedLen for BoundedVec (paritytech#8727) * impl BoundedEncodedLen for bool * explicitly implement BoundedEncodedLen for each Compact form Turns out that u16 doesn't play nicely with the pattern; those values take two extra bytes, where all other cases take one. :( * rename BoundedEncodedLen -> MaxEncodedLen * add tests of compact encoded length Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
Work moved from paritytech/parity-scale-codec#267
In support of #8719