Use method number in rust yunq client.
This commit is contained in:
parent
d4f60f4942
commit
e41f58c714
|
@ -7,12 +7,13 @@ use mammoth::zion::ZError;
|
|||
const SENTINEL: u32 = 0xBEEFDEAD;
|
||||
|
||||
pub fn call_endpoint<Req: YunqMessage, Resp: YunqMessage, const N: usize>(
|
||||
request_id: u64,
|
||||
req: &Req,
|
||||
byte_buffer: &mut ByteBuffer<N>,
|
||||
endpoint_cap: z_cap_t,
|
||||
) -> Result<Resp, ZError> {
|
||||
byte_buffer.write_at(0, SENTINEL)?;
|
||||
byte_buffer.write_at(8, 1 as u64)?;
|
||||
byte_buffer.write_at(8, request_id as u64)?;
|
||||
|
||||
let mut cap_buffer = Vec::new();
|
||||
|
||||
|
|
|
@ -26,23 +26,24 @@ fn generate_message(message: &Message) -> TokenStream {
|
|||
}
|
||||
|
||||
fn generate_method(method: &Method) -> TokenStream {
|
||||
let id = proc_macro2::Literal::u64_suffixed(method.number);
|
||||
let name = ident(&method.name.to_case(Case::Snake));
|
||||
let maybe_req = method.request.clone().map(|r| ident(&r));
|
||||
let maybe_resp = method.response.clone().map(|r| ident(&r));
|
||||
match (maybe_req, maybe_resp) {
|
||||
(Some(req), Some(resp)) => quote! {
|
||||
pub fn #name (&mut self, req: & #req) -> Result<#resp, ZError> {
|
||||
yunq::client::call_endpoint(req, &mut self.byte_buffer, self.endpoint_cap)
|
||||
yunq::client::call_endpoint(#id, req, &mut self.byte_buffer, self.endpoint_cap)
|
||||
}
|
||||
},
|
||||
(Some(req), None) => quote! {
|
||||
pub fn #name (&mut self, req: & #req) -> Result<yunq::message::Empty, ZError> {
|
||||
yunq::client::call_endpoint(req, &mut self.byte_buffer, self.endpoint_cap)
|
||||
yunq::client::call_endpoint(#id, req, &mut self.byte_buffer, self.endpoint_cap)
|
||||
}
|
||||
},
|
||||
(None, Some(resp)) => quote! {
|
||||
pub fn #name (&mut self) -> Result<#resp, ZError> {
|
||||
yunq::client::call_endpoint(&yunq::message::Empty{}, &mut self.byte_buffer, self.endpoint_cap)
|
||||
yunq::client::call_endpoint(#id, &yunq::message::Empty{}, &mut self.byte_buffer, self.endpoint_cap)
|
||||
}
|
||||
},
|
||||
_ => unreachable!(),
|
||||
|
|
Loading…
Reference in New Issue