Skip to content

Conversation

@niklasad1
Copy link
Contributor

@niklasad1 niklasad1 commented May 18, 2021

Similar should be done on Params and JsonRpcNotifParams to work properly but this PR is large enough as it is.

Further info see #292 (comment)

}

/// Request Id
#[derive(Debug, PartialEq, Clone, Hash, Eq, Deserialize, Serialize)]
Copy link
Contributor Author

@niklasad1 niklasad1 May 18, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clone should be cheap as deserialize just borrows the String AFAIU.

Then in the client code we just use Id::Number for now.

Thus, should never allocate in server at least?!

@niklasad1 niklasad1 changed the title [types]: typed ID instead of serde_json::RawValue [types]: ID type instead of serde_json::RawValue May 18, 2021
Copy link
Contributor

@dvdplm dvdplm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good cleanup here, and good riddance of those *Alloc types. 👍

if let Some(method) = methods.get(&*req.method) {
let params = RpcParams::new(req.params.map(|params| params.get()));
if let Err(err) = (method)(req.id, params, &tx, conn_id) {
if let Err(err) = (method)(req.id.clone(), params, &tx, conn_id) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So these clones are cheap then you say?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes 🙏

let err: JsonRpcErrorAlloc = serde_json::from_slice(&body).map_err(Error::ParseError)?;
return Err(Error::Request(err));
let err: JsonRpcError = serde_json::from_slice(&body).map_err(Error::ParseError)?;
return Err(Error::Request(err.to_string()));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: I changed the error type to a String in Error::Request to get rid of the alloc type.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I noticed that. I don't think there much else we can do right?

if let Ok(req) = serde_json::from_slice::<JsonRpcRequest>(&body) {
execute(&tx, req);
} else if let Ok(_req) = serde_json::from_slice::<JsonRpcNotification>(&body) {
return Ok::<_, HyperError>(response::ok_response("".into()));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

send empty response to notification,

currently we don't care if the method is registered or not (that API is not exposed)

send_error(Id::Null, &tx, JsonRpcErrorCode::InvalidRequest.into());
}
} else if let Ok(_batch) = serde_json::from_slice::<Vec<JsonRpcNotification>>(&body) {
return Ok::<_, HyperError>(response::ok_response("".into()));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

send empty response to batch notification,

currently we don't care if the method is registered or not (that API is not exposed)

/// Method
pub method: &'a str,
/// Params.
pub params: JsonRpcNotificationParams<'a>,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In another PR; merge JsonRpcNotificationParams and JsonRpcNotificationParamsNotification

/// Parameter values of the request.
pub params: JsonRpcNotificationParams<'a>,
#[serde(borrow)]
pub params: Option<&'a RawValue>,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In another PR, hopefully merge JsonRpcParams/RpcParams and replace RawValue here,

That's the reason why some de-serialize tests still fail

@niklasad1 niklasad1 marked this pull request as ready for review May 18, 2021 19:22
@niklasad1 niklasad1 requested a review from TarikGul May 19, 2021 12:25
assert_eq!(response.status, StatusCode::OK);
// Note: this is *not* according to spec. Response should be the empty string, `""`.
assert_eq!(response.body, r#"[{"jsonrpc":"2.0","result":"","id":null},{"jsonrpc":"2.0","result":"","id":null}]"#);
// Note: on HTTP we ack the notification with an empty response.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does ack mean here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK - acknowledge, maybe it's a bad term ^^

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh makes sense, yea I wouldn't have been able to deduce that. But now that I know what it means I like it. For the general user, it would probably make sense to write out the whole word though in this case.

Copy link
Member

@TarikGul TarikGul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, After a brief explanation from @niklasad1 I was able to follow along the type changes, and understand the direction of the PR. 👍

@niklasad1 niklasad1 merged commit 4e95f43 into master May 19, 2021
@niklasad1 niklasad1 deleted the na-jsonrpc-types-id-and-params branch May 19, 2021 15:20
@dvdplm dvdplm mentioned this pull request Jun 15, 2021
13 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants