-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoutput
More file actions
47 lines (35 loc) · 1.37 KB
/
output
File metadata and controls
47 lines (35 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
extern crate oak;
extern crate protobuf;
mod proto;
use protobuf::Message;
struct Node;
impl oak::Node for Node {
fn new() -> Self {
Node
}
fn invoke(&mut self, method_name: &str, request: &mut oak::Reader, response: &mut oak::Writer) {
// TODO: Generate this code via a macro or code generation (e.g. a protoc plugin).
match method_name {
"/oak.examples.hello_world.HelloWorld/SayHello" => {
let mut in_stream = protobuf::CodedInputStream::new(request);
HelloWorld
let mut req = proto::hello_world::SayHelloRequest::new();
req.merge_from(&mut in_stream)
.expect("could not read request");
let mut res = proto::hello_world::SayHelloResponse::new();
res.message = format!("HELLO {}!", req.name);
let mut out_stream = protobuf::CodedOutputStream::new(response);
res.write_to(&mut out_stream)
.expect("could not write response");
out_stream.flush().expect("could not flush");
}
_ => {
panic!("unknown method name");
}
};
}
}
oak::oak_node!(Node);
trait HelloWorld {
fn SayHello(input: &proto::hello_world::SayHelloRequest) -> proto::hello_world::SayHelloResponse;
}