-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Define gRPC Invocation in Rust SDK (#530)
- Encapsulate a request receiver and a response sender into a single object which implements `Encodable` and `Decodable`. - Add `#[must_use]` to a couple places where return status codes were not checked. We should probably consider using `Result` types everywhere. Fixes #528
- Loading branch information
Showing
5 changed files
with
128 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// | ||
// Copyright 2020 The Project Oak Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
/// A gRPC invocation, consisting of exactly two channels: one to read incoming requests from the | ||
/// client, and one to write outgoing responses to the client. | ||
pub struct Invocation { | ||
pub request_receiver: crate::io::Receiver<crate::proto::grpc_encap::GrpcRequest>, | ||
pub response_sender: crate::io::Sender<crate::proto::grpc_encap::GrpcResponse>, | ||
} | ||
|
||
// TODO(#389): Automatically generate this code. | ||
impl crate::io::Encodable for Invocation { | ||
fn encode(&self) -> Result<crate::io::Message, crate::OakError> { | ||
let bytes = vec![]; | ||
let handles = vec![ | ||
self.request_receiver.handle.handle, | ||
self.response_sender.handle.handle, | ||
]; | ||
Ok(crate::io::Message { bytes, handles }) | ||
} | ||
} | ||
|
||
// TODO(#389): Automatically generate this code. | ||
impl crate::io::Decodable for Invocation { | ||
fn decode(message: &crate::io::Message) -> Result<Self, crate::OakError> { | ||
if !message.bytes.is_empty() { | ||
panic!( | ||
"incorrect number of bytes received: {} (expected: 0)", | ||
message.bytes.len() | ||
); | ||
} | ||
if message.handles.len() != 2 { | ||
panic!( | ||
"incorrect number of handles received: {} (expected: 2)", | ||
message.handles.len() | ||
); | ||
} | ||
Ok(Invocation { | ||
request_receiver: crate::io::Receiver::new(crate::ReadHandle { | ||
handle: message.handles[0], | ||
}), | ||
response_sender: crate::io::Sender::new(crate::WriteHandle { | ||
handle: message.handles[1], | ||
}), | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters