-
-
Notifications
You must be signed in to change notification settings - Fork 38
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
Change Key::from_ord_bytes to accept Cow #254
Comments
Unfortunately this isn't possible to support while still supporting composite key decoding. The reason is quite complicated, but it boils down to this: With This causes all sorts of issues when trying to apply these changes to composite key decoding, since it requires using only part of the input bytes for each field. Additionally, it has performance implications with Option/Result encoding due to those types encoding a single extra byte. If anyone wants to try their hands at fixing the issues on this branch: https://github.com/khonsulabs/bonsaidb/compare/a9c6af0dc161daaa41ced39b5822f3d63f219039...ecton:cow_key?expand=1, it should be fairly straightfoward to reproduce the errors. There needs to be an update to |
After #254, null bytes no longer need to be either allow/deny. Instead, we can now escape which is the default behavior. This will cause extra allocations when null bytes are encountered during the encoding process, but the correct sort behavior is preserved. Allow/deny is still an option for situations where users do not want the extra overhead that encoding can incur.
From a conversation with @asonix on Discord, a suggestion was made to pass
Cow<'k, [u8]>
instead of&'k [u8]
. After some thought, I realized this was a wonderful idea even though it initially sounds like it complicates things.One of the ugly parts of the to-be-released
CompositeKeyEncoder
is that it doesn't support values that contain null bytes. The reason is that borrowed data couldn't be supported properly in those situations due needing to escape the data, which necessarily requires extra allocations that cannot be borrowed from. By passing the Cow instead of always giving a slice, it gives the implementor of Key the option of implementing either version or returning an error if it can't fulfill the deserialization given the lifetime requirements.The text was updated successfully, but these errors were encountered: