-
Notifications
You must be signed in to change notification settings - Fork 73
Add support for binary custom metadata fields #102
Conversation
What this commit does is to introduce _bin APIs for dealing with binary metadata keys, and distinct Binary vs Ascii MetadataKey types. It doesn't actually do any encoding or enforce any invariants yet.
It is just unhelpful for the user of MetadataMap that they were separate.
With the split of binary vs ascii keys I can't think of a reasonable way to implement this that doesn't have an API that is so complicated that it's not worth using for the very small performance benefits it provides. It's still possible to go down to the lower HeaderMap level and use drain from there.
That way it's more natural that both MetadataValue and MetadataKey use them.
This is a first step towards making the code automatically base64 encode and decode the binary values in MetadataMaps.
They should be constructed from byte arrays, not strings.
The "name" name is an outdated reference to HeaderName.
Converting to Binary is possible but I can't think of a use case. Let's add it if it turns out it's useful. MVP etc.
I can't think of a reasonable use case where this shortcut helps meaningfully. Instead of implementing the necessary base64 encoding here I'll just remove it.
… way This is a step towards making this method do the right thing for MetadataValue<Binary>.
It seems unnecessary to provide this helper for binary values.
…e for Ascii It's not possible to return a slice to a the decoded base64 data for Binary values.
Turns out it is useful after all, otherwise there is no way to construct binary metadata values without copying.
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 think the plan here is pretty sound!
I have addressed the review comments, except for preventing construction of the error types outside of the crate. I might be missing something but still think the potential future benefit of being able to add non-Default, non-Option fields to those error types (which I expect will remain empty structs forever) is much smaller than the current benefit of not requiring every single client with unit tests to wrap every call to this library in order to be able to test error conditions. |
For fixing the build.
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.
🎉
@carllerche do you also want to review this PR before I merge? I'll probably merge this tomorrow unless I get more comments. |
I'm back now! I will try to take a look in the next 24 hours. I'm still catching up on email :) |
@carllerche Aha, I see! No worries, I'm in no particular rush with this really. I'm off to vacation myself next week and will likely not spend much time on this until January. |
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 love it! Thanks so much for this PR (and sorry for the very long 24 hours).
I like the API strategy you took. I think it is probably the best we can do.
I left some questions inline, but they are not related to this PR, so not worth blocking the merge.
unsafe impl<'a> Sync for Drain<'a> {} | ||
unsafe impl<'a> Send for Drain<'a> {} | ||
unsafe impl<'a, VE: ValueEncoding> Sync for ValueDrain<'a, VE> {} | ||
unsafe impl<'a, VE: ValueEncoding> Send for ValueDrain<'a, VE> {} |
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.
Are these two unsafe impls required? The struct doesn't contain any unsafe types (the version in http
did require it as it had raw pointers).
unsafe impl<'a> Sync for ValueIterMut<'a> {} | ||
unsafe impl<'a> Send for ValueIterMut<'a> {} | ||
unsafe impl<'a, VE: ValueEncoding> Sync for ValueIterMut<'a, VE> {} | ||
unsafe impl<'a, VE: ValueEncoding> Send for ValueIterMut<'a, VE> {} |
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.
Same, I don't think these unsafe impls are needed?
Adds support for base64 encoded "-bin" gRPC custom metadata.
[EDIT] I thought this would be enough to solve #79 but it's not: With this PR you can write custom metadata but not yet read it in a sane way, and it's not possible at all to differentiate between initial and trailing metadata in a response (not sure it even stores both).
Necessary for #27. See discussion at #90. This is a follow-up of #92.
Things to look for when reviewing:
ValueEncoding
trait is afaik not importable from outside of this crate. Is that enough to prevent others from making implementations of it? It's not supposed to be possible.Ping @carllerche here is a more or less fully fleshed out PR of what we discussed before.