-
Notifications
You must be signed in to change notification settings - Fork 173
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
Sniff the first byte to glean if the incoming request is a single or batch request #419
Conversation
…batch request This works around the serde limitations around `untagged` enums and `RawValue`.
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.
Looks good, just a question on one bit that might cause panic on runtime?
Err(_) => (Id::Null, JsonRpcErrorCode::ParseError), | ||
}; | ||
send_error(id, &tx, code.into()); | ||
// Bacth of requests or notifications |
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.
// Bacth of requests or notifications | |
// Batch of requests or notifications |
/// Figure out if this is a sufficiently complete request that we can extract an [`Id`] out of, or just plain | ||
/// unparseable garbage. | ||
pub fn prepare_error(data: &[u8]) -> (Id<'_>, JsonRpcErrorCode) { | ||
match serde_json::from_slice::<JsonRpcInvalidRequest>(&data) { |
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.
match serde_json::from_slice::<JsonRpcInvalidRequest>(&data) { | |
match serde_json::from_slice::<JsonRpcInvalidRequest>(data) { |
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,
Did you notice any performance gains compared to master?
I did not run the benchmarks tbh. I should have. |
This works around the serde limitations around
untagged
enums andRawValue
by instead looking at the first byte of the request: if it's a[
then it's a batch request; if it's a{
then it's a single request.The http case is less nice because there we have notifications (i.e. requests without an id, requiring no response).
Also see #420 as an alternative to this.
Closes #296