diff --git a/Cargo.lock b/Cargo.lock index 21313c137f0..00442469108 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -12,8 +12,7 @@ dependencies = [ "oak 0.1.0", "oak_abi 0.1.0", "oak_utils 0.1.0", - "protobuf 2.10.1 (registry+https://github.com/rust-lang/crates.io-index)", - "protoc-rust-grpc 0.7.0", + "prost 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)", "rand_core 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "regex 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)", @@ -28,7 +27,7 @@ dependencies = [ "abitest_common 0.1.0", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "oak 0.1.0", - "protobuf 2.10.1 (registry+https://github.com/rust-lang/crates.io-index)", + "prost 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.47 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -55,7 +54,7 @@ dependencies = [ "oak_abi 0.1.0", "oak_runtime 0.1.0", "oak_tests 0.1.0", - "protobuf 2.10.1 (registry+https://github.com/rust-lang/crates.io-index)", + "prost 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "simple_logger 1.5.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -72,8 +71,7 @@ dependencies = [ "oak_runtime 0.1.0", "oak_tests 0.1.0", "oak_utils 0.1.0", - "protobuf 2.10.1 (registry+https://github.com/rust-lang/crates.io-index)", - "protoc-rust-grpc 0.7.0", + "prost 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "simple_logger 1.5.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -86,7 +84,6 @@ dependencies = [ "futures-util 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "prost 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", - "protobuf 2.10.1 (registry+https://github.com/rust-lang/crates.io-index)", "tokio 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", "tonic 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "tonic-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -335,8 +332,7 @@ dependencies = [ "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "oak 0.1.0", "oak_utils 0.1.0", - "protobuf 2.10.1 (registry+https://github.com/rust-lang/crates.io-index)", - "protoc-rust-grpc 0.7.0", + "prost 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)", "rand_core 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)", @@ -706,14 +702,6 @@ dependencies = [ "regex 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "grpc-compiler" -version = "0.7.0" -dependencies = [ - "protobuf 2.10.1 (registry+https://github.com/rust-lang/crates.io-index)", - "protobuf-codegen 2.10.1 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "h2" version = "0.2.1" @@ -759,8 +747,7 @@ dependencies = [ "oak_runtime 0.1.0", "oak_tests 0.1.0", "oak_utils 0.1.0", - "protobuf 2.10.1 (registry+https://github.com/rust-lang/crates.io-index)", - "protoc-rust-grpc 0.7.0", + "prost 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "simple_logger 1.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "translator_common 0.1.0", ] @@ -946,7 +933,7 @@ version = "0.1.0" dependencies = [ "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "oak 0.1.0", - "protobuf 2.10.1 (registry+https://github.com/rust-lang/crates.io-index)", + "prost 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)", "rand_distr 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "rusty-machine 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1149,8 +1136,8 @@ dependencies = [ "oak_abi 0.1.0", "oak_tests 0.1.0", "oak_utils 0.1.0", - "protobuf 2.10.1 (registry+https://github.com/rust-lang/crates.io-index)", - "protoc-rust 2.10.1 (registry+https://github.com/rust-lang/crates.io-index)", + "prost 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", + "prost-types 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "rand_core 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.47 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1194,7 +1181,7 @@ dependencies = [ "oak_utils 0.1.0", "prost 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "prost-build 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", - "protobuf 2.10.1 (registry+https://github.com/rust-lang/crates.io-index)", + "prost-types 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)", "tokio 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", "wasmi 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1212,8 +1199,7 @@ dependencies = [ "oak 0.1.0", "oak_abi 0.1.0", "oak_runtime 0.1.0", - "protobuf 2.10.1 (registry+https://github.com/rust-lang/crates.io-index)", - "protoc-rust 2.10.1 (registry+https://github.com/rust-lang/crates.io-index)", + "prost 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1222,8 +1208,10 @@ name = "oak_utils" version = "0.1.0" dependencies = [ "maplit 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "protoc-rust 2.10.1 (registry+https://github.com/rust-lang/crates.io-index)", - "protoc-rust-grpc 0.7.0", + "proc-macro2 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)", + "prost 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", + "prost-build 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "tempfile 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "walkdir 2.3.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1336,8 +1324,7 @@ dependencies = [ "oak_runtime 0.1.0", "oak_tests 0.1.0", "oak_utils 0.1.0", - "protobuf 2.10.1 (registry+https://github.com/rust-lang/crates.io-index)", - "protoc-rust-grpc 0.7.0", + "prost 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "simple_logger 1.5.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1435,49 +1422,6 @@ dependencies = [ "prost 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "protobuf" -version = "2.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "protobuf-codegen" -version = "2.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "protobuf 2.10.1 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "protoc" -version = "2.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "protoc-rust" -version = "2.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "protobuf 2.10.1 (registry+https://github.com/rust-lang/crates.io-index)", - "protobuf-codegen 2.10.1 (registry+https://github.com/rust-lang/crates.io-index)", - "protoc 2.10.1 (registry+https://github.com/rust-lang/crates.io-index)", - "tempfile 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "protoc-rust-grpc" -version = "0.7.0" -dependencies = [ - "grpc-compiler 0.7.0", - "protobuf 2.10.1 (registry+https://github.com/rust-lang/crates.io-index)", - "protoc 2.10.1 (registry+https://github.com/rust-lang/crates.io-index)", - "protoc-rust 2.10.1 (registry+https://github.com/rust-lang/crates.io-index)", - "tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "quick-error" version = "1.2.3" @@ -1673,8 +1617,7 @@ dependencies = [ "oak_runtime 0.1.0", "oak_tests 0.1.0", "oak_utils 0.1.0", - "protobuf 2.10.1 (registry+https://github.com/rust-lang/crates.io-index)", - "protoc-rust-grpc 0.7.0", + "prost 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "simple_logger 1.5.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1879,8 +1822,7 @@ dependencies = [ "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "oak 0.1.0", "oak_utils 0.1.0", - "protobuf 2.10.1 (registry+https://github.com/rust-lang/crates.io-index)", - "protoc-rust-grpc 0.7.0", + "prost 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "rustfmt-nightly 1.4.11 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2210,15 +2152,6 @@ dependencies = [ "unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "tempdir" -version = "0.3.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "rand 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "remove_dir_all 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "tempfile" version = "3.1.0" @@ -2600,7 +2533,7 @@ dependencies = [ "oak 0.1.0", "oak_runtime 0.1.0", "oak_tests 0.1.0", - "protobuf 2.10.1 (registry+https://github.com/rust-lang/crates.io-index)", + "prost 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "simple_logger 1.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "translator_common 0.1.0", ] @@ -2612,8 +2545,7 @@ dependencies = [ "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "oak 0.1.0", "oak_utils 0.1.0", - "protobuf 2.10.1 (registry+https://github.com/rust-lang/crates.io-index)", - "protoc-rust-grpc 0.7.0", + "prost 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -3005,10 +2937,6 @@ dependencies = [ "checksum prost-build 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "02b10678c913ecbd69350e8535c3aef91a8676c0773fc1d7b95cdd196d7f2f26" "checksum prost-derive 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "537aa19b95acde10a12fec4301466386f757403de4cd4e5b4fa78fb5ecb18f72" "checksum prost-types 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1834f67c0697c001304b75be76f67add9c89742eda3a085ad8ee0bb38c3417aa" -"checksum protobuf 2.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "6686ddd96a8dbe2687b5f2a687b2cfb520854010ec480f2d74c32e7c9873d3c5" -"checksum protobuf-codegen 2.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "6456421eecf7fc72905868cd760c3e35848ded3552e480cfe67726ed4dbd8d23" -"checksum protoc 2.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9fd83d2547a9e2c8bc6016607281b3ec7ef4871c55be6930915481d80350ab88" -"checksum protoc-rust 2.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "30fe03ab363474c2f5d1062f5d169ba8defd1d30c161261d7c71afd8412727d8" "checksum quick-error 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" "checksum quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "053a8c8bcc71fcce321828dc897a98ab9760bef03a4fc36693c231e5b3216cfe" "checksum rand 0.3.23 (registry+https://github.com/rust-lang/crates.io-index)" = "64ac302d8f83c0c1974bf758f6b041c6c8ada916fbb44a609158ca8b064cc76c" @@ -3080,7 +3008,6 @@ dependencies = [ "checksum syn 1.0.14 (registry+https://github.com/rust-lang/crates.io-index)" = "af6f3550d8dff9ef7dc34d384ac6f107e5d31c8f57d9f28e0081503f547ac8f5" "checksum syn-mid 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7be3539f6c128a931cf19dcee741c1af532c7fd387baa739c03dd2e96479338a" "checksum synstructure 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)" = "67656ea1dc1b41b1451851562ea232ec2e5a80242139f7e679ceccfb5d61f545" -"checksum tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "15f2b5fb00ccdf689e0149d1b1b3c03fead81c2b37735d812fa8bddbbf41b6d8" "checksum tempfile 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e24d9338a0a5be79593e2fa15a648add6138caa803e2d5bc782c371732ca9" "checksum term 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c0863a3345e70f61d613eab32ee046ccd1bcc5f9105fe402c61fcd0c13eeb8b5" "checksum term_size 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9e5b9a66db815dcfd2da92db471106457082577c3c278d4138ab3e3b4e189327" diff --git a/Cargo.toml b/Cargo.toml index dd6f874891e..52ee8f81588 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -63,5 +63,3 @@ split_grpc_proxy = { path = "experimental/split_grpc/proxy" } split_grpc_server = { path = "experimental/split_grpc/server" } # Third party. expect = { path = "third_party/expect" } -grpc-compiler = { path = "third_party/grpc-rust/grpc-compiler" } -protoc-rust-grpc = { path = "third_party/grpc-rust/protoc-rust-grpc" } diff --git a/docs/programming-oak.md b/docs/programming-oak.md index 046da5896f0..4bed0b1179d 100644 --- a/docs/programming-oak.md +++ b/docs/programming-oak.md @@ -95,7 +95,7 @@ with the automatically generated `Dispatcher`, as described in the next section. ```Rust oak::entrypoint!(oak_main => { oak::logger::init_default(); - Dispatcher::new(Node) + FormatServiceDispatcher::new(Node) } ``` @@ -123,14 +123,10 @@ generated file appearing in `src/proto/_grpc.rs`. [embedmd]:# (../examples/hello_world/module/rust/build.rs Rust /fn main/ /^}/) ```Rust fn main() { - oak_utils::run_protoc_rust_grpc(protoc_rust_grpc::Args { - out_dir: "src/proto", - input: &["../../proto/hello_world.proto"], - includes: &["../../proto", "../../../../third_party"], - rust_protobuf: true, // also generate protobuf messages, not just services - ..Default::default() - }) - .expect("protoc-rust-grpc"); + oak_utils::compile_protos( + &["../../proto/hello_world.proto"], + &["../../proto", "../../../../third_party"], + ); } ``` @@ -146,14 +142,11 @@ methods in the gRPC service, taking the relevant (auto-generated) request and response types. The Oak Node implements the gRPC service by implementing this trait. - -[embedmd]:# (../examples/rustfmt/module/rust/src/proto/rustfmt_grpc.rs Rust /pub trait FormatService/ /^}/) ```Rust pub trait FormatService { fn format(&mut self, req: super::rustfmt::FormatRequest) -> grpc::Result; } ``` - The second part of the autogenerated code includes a `Dispatcher` struct which maps a request (as a method name and encoded request) to an invocation of the @@ -444,7 +437,6 @@ fn test_say_hello() { let req = HelloRequest { greeting: "world".into(), - ..Default::default() }; let result: grpc::Result = oak_tests::grpc_request( &runtime, @@ -512,7 +504,7 @@ pub extern "C" fn frontend_oak_main(in_handle: u64) { let _ = std::panic::catch_unwind(|| { oak::set_panic_hook(); let node = FrontendNode::new(); - let dispatcher = Dispatcher::new(node); + let dispatcher = OakAbiTestServiceDispatcher::new(node); oak::run_event_loop(dispatcher, in_handle); }); } diff --git a/examples/abitest/module_0/rust/Cargo.toml b/examples/abitest/module_0/rust/Cargo.toml index 8b99bd3f810..ace41fc8096 100644 --- a/examples/abitest/module_0/rust/Cargo.toml +++ b/examples/abitest/module_0/rust/Cargo.toml @@ -15,7 +15,7 @@ hex = "*" log = "*" oak = "=0.1.0" oak_abi = "=0.1.0" -protobuf = "*" +prost = "*" rand_core = "*" rand = "*" regex = "*" @@ -24,4 +24,3 @@ serde_json = "*" [build-dependencies] oak_utils = "*" -protoc-rust-grpc = { path = "../../../../third_party/grpc-rust/protoc-rust-grpc" } diff --git a/examples/abitest/module_0/rust/build.rs b/examples/abitest/module_0/rust/build.rs index 830ba327abf..b6707734389 100644 --- a/examples/abitest/module_0/rust/build.rs +++ b/examples/abitest/module_0/rust/build.rs @@ -15,12 +15,8 @@ // fn main() { - oak_utils::run_protoc_rust_grpc(protoc_rust_grpc::Args { - out_dir: "src/proto", - input: &["../../proto/abitest.proto"], - includes: &["../../proto", "../../../../third_party"], - rust_protobuf: true, // also generate protobuf messages, not just services - ..Default::default() - }) - .expect("protoc-rust-grpc"); + oak_utils::compile_protos( + &["../../proto/abitest.proto"], + &["../../proto", "../../../../third_party"], + ); } diff --git a/examples/abitest/module_0/rust/src/lib.rs b/examples/abitest/module_0/rust/src/lib.rs index c0d73a17463..b37f702bc91 100644 --- a/examples/abitest/module_0/rust/src/lib.rs +++ b/examples/abitest/module_0/rust/src/lib.rs @@ -14,18 +14,19 @@ // limitations under the License. // -pub mod proto; +pub mod proto { + include!(concat!(env!("OUT_DIR"), "/oak.examples.abitest.rs")); +} use abitest_common::{InternalMessage, LOG_CONFIG_NAME}; use byteorder::WriteBytesExt; use expect::{expect, expect_eq, expect_matches}; use log::{debug, info}; use oak::{grpc, ChannelReadStatus, OakError, OakStatus}; -use proto::abitest::GrpcTestRequest_oneof_method_result::{err_code, ok_text}; -use proto::abitest::{ABITestRequest, ABITestResponse, ABITestResponse_TestResult}; -use proto::abitest::{GrpcTestRequest, GrpcTestResponse}; -use proto::abitest_grpc::{Dispatcher, OakABITestService, OakABITestServiceClient}; -use protobuf::{Message, ProtobufEnum}; +use prost::Message; +use proto::{AbiTestRequest, AbiTestResponse}; +use proto::{GrpcTestRequest, GrpcTestResponse}; +use proto::{OakAbiTestService, OakAbiTestServiceClient, OakAbiTestServiceDispatcher}; use rand::Rng; use std::collections::HashMap; @@ -41,8 +42,8 @@ struct FrontendNode { storage: Option, absent_storage: Option, storage_name: Vec, - grpc_service: Option, - absent_grpc_service: Option, + grpc_service: Option, + absent_grpc_service: Option, } impl FrontendNode { @@ -84,9 +85,9 @@ impl FrontendNode { absent_storage: oak::storage::Storage::new("absent-storage"), storage_name: storage_name.as_bytes().to_vec(), grpc_service: oak::grpc::client::Client::new("grpc-client", "ignored") - .map(OakABITestServiceClient), + .map(OakAbiTestServiceClient), absent_grpc_service: oak::grpc::client::Client::new("absent-grpc-client", "ignored") - .map(OakABITestServiceClient), + .map(OakAbiTestServiceClient), } } } @@ -96,7 +97,7 @@ pub extern "C" fn frontend_oak_main(in_handle: u64) { let _ = std::panic::catch_unwind(|| { oak::set_panic_hook(); let node = FrontendNode::new(); - let dispatcher = Dispatcher::new(node); + let dispatcher = OakAbiTestServiceDispatcher::new(node); oak::run_event_loop(dispatcher, in_handle); }); } @@ -104,15 +105,15 @@ pub extern "C" fn frontend_oak_main(in_handle: u64) { type TestResult = Result<(), Box>; type TestFn = fn(&mut FrontendNode) -> TestResult; -impl OakABITestService for FrontendNode { - fn run_tests(&mut self, req: ABITestRequest) -> grpc::Result { +impl OakAbiTestService for FrontendNode { + fn run_tests(&mut self, req: AbiTestRequest) -> grpc::Result { info!( "Run tests matching '{}' except those matching '{}'", req.include, req.exclude ); let include = regex::Regex::new(&req.include).unwrap(); let exclude = regex::Regex::new(&req.exclude).unwrap(); - let mut results = protobuf::RepeatedField::::new(); + let mut results = Vec::::new(); // Manual registry of all tests. let mut tests: HashMap<&str, TestFn> = HashMap::new(); @@ -177,72 +178,76 @@ impl OakABITestService for FrontendNode { ); continue; } - let mut result = ABITestResponse_TestResult::new(); - result.set_name(name.to_string()); + let mut result = proto::abi_test_response::TestResult::default(); + result.name = name.to_string(); if name.starts_with("DISABLED_") { debug!("skip test '{}' as marked as disabled", name); - result.set_disabled(true); - result.set_success(false); - result.set_details("Test disabled".to_string()); + result.disabled = true; + result.success = false; + result.details = "Test disabled".to_string(); results.push(result); continue; } info!("running test {}", name); match testfn(self) { - Ok(()) => result.set_success(true), + Ok(()) => result.success = true, Err(err) => { - result.set_success(false); - result.set_details(format!("Error: {}", err)); + result.success = false; + result.details = format!("Error: {}", err); } } results.push(result); } - let mut res = ABITestResponse::new(); - res.set_results(results); + let mut res = AbiTestResponse::default(); + res.results = results; Ok(res) } // gRPC test methods. fn unary_method(&mut self, req: GrpcTestRequest) -> grpc::Result { - if req.has_err_code() { - info!("unary_method -> Err({})", req.get_err_code()); - return Err(grpc::build_status( - grpc::Code::from_i32(req.get_err_code()).unwrap(), - "Deliberate error", - )); + match req.method_result { + Some(proto::grpc_test_request::MethodResult::ErrCode(err_code)) => { + info!("unary_method -> Err({})", err_code); + Err(grpc::build_status( + grpc::Code::from_i32(err_code).unwrap(), + "Deliberate error", + )) + } + Some(proto::grpc_test_request::MethodResult::OkText(ok_text)) => { + info!("unary_method -> Ok({})", ok_text); + let rsp = GrpcTestResponse { text: ok_text }; + Ok(rsp) + } + None => panic!("invalid request"), } - info!("unary_method -> Ok({})", req.get_ok_text()); - let mut rsp = GrpcTestResponse::new(); - rsp.text = req.get_ok_text().to_string(); - Ok(rsp) } fn server_streaming_method( &mut self, req: GrpcTestRequest, mut writer: grpc::ChannelResponseWriter, ) { - if req.has_err_code() { - info!("server_streaming_method -> Err({})", req.get_err_code()); - let status = grpc::build_status( - grpc::Code::from_i32(req.get_err_code()).unwrap(), - "Deliberate error", - ); - writer.close(Err(status)).expect("failed to close writer"); - return; - } - // Write two responses to exercise streaming. - info!("server_streaming_method -> 2 x Ok({})", req.get_ok_text()); - let mut rsp = GrpcTestResponse::new(); - rsp.set_text(req.get_ok_text().to_string()); - writer - .write(&rsp, grpc::WriteMode::KeepOpen) - .expect("Failed to write response"); - rsp.set_text(req.get_ok_text().to_string()); - writer - .write(&rsp, grpc::WriteMode::Close) - .expect("Failed to write response"); + match req.method_result { + Some(proto::grpc_test_request::MethodResult::ErrCode(err_code)) => { + info!("server_streaming_method -> Err({})", err_code); + let status = + grpc::build_status(grpc::Code::from_i32(err_code).unwrap(), "Deliberate error"); + writer.close(Err(status)).expect("failed to close writer"); + } + Some(proto::grpc_test_request::MethodResult::OkText(ok_text)) => { + // Write two responses to exercise streaming. + info!("server_streaming_method -> 2 x Ok({})", ok_text); + let rsp = GrpcTestResponse { text: ok_text }; + writer + .write(&rsp, grpc::WriteMode::KeepOpen) + .expect("Failed to write response"); + writer + .write(&rsp, grpc::WriteMode::Close) + .expect("Failed to write response"); + } + None => panic!("invalid request"), + }; } fn client_streaming_method( &mut self, @@ -250,10 +255,12 @@ impl OakABITestService for FrontendNode { ) -> grpc::Result { // If any request triggers an error, return it. for req in &reqs { - if req.has_err_code() { - info!("client_streaming_method -> Err({})", req.get_err_code()); + if let Some(proto::grpc_test_request::MethodResult::ErrCode(err_code)) = + req.method_result + { + info!("client_streaming_method -> Err({})", err_code); return Err(grpc::build_status( - grpc::Code::from_i32(req.get_err_code()).unwrap(), + grpc::Code::from_i32(err_code).unwrap(), "Deliberate error", )); } @@ -261,10 +268,14 @@ impl OakABITestService for FrontendNode { // Otherwise return the text from all the requests combined. let mut combined_text = String::new(); for req in &reqs { - combined_text.push_str(req.get_ok_text()); + if let Some(proto::grpc_test_request::MethodResult::OkText(ok_text)) = + &req.method_result + { + combined_text.push_str(&ok_text); + } } info!("client_streaming_method -> Ok({})", combined_text); - let mut rsp = GrpcTestResponse::new(); + let mut rsp = GrpcTestResponse::default(); rsp.text = combined_text; Ok(rsp) } @@ -274,21 +285,25 @@ impl OakABITestService for FrontendNode { mut writer: grpc::ChannelResponseWriter, ) { for req in &reqs { - if req.has_err_code() { - info!("bidi_streaming_method -> Err({})", req.get_err_code()); - let status = grpc::build_status( - grpc::Code::from_i32(req.get_err_code()).unwrap(), - "Deliberate error", - ); - writer.close(Err(status)).expect("failed to close writer"); - return; - } - info!("bidi_streaming_method -> Ok({})", req.get_ok_text()); - let mut rsp = GrpcTestResponse::new(); - rsp.set_text(req.get_ok_text().to_string()); - writer - .write(&rsp, grpc::WriteMode::KeepOpen) - .expect("Failed to write response"); + match &req.method_result { + Some(proto::grpc_test_request::MethodResult::ErrCode(err_code)) => { + info!("bidi_streaming_method -> Err({})", err_code); + let status = grpc::build_status( + grpc::Code::from_i32(*err_code).unwrap(), + "Deliberate error", + ); + writer.close(Err(status)).expect("failed to close writer"); + } + Some(proto::grpc_test_request::MethodResult::OkText(ok_text)) => { + info!("bidi_streaming_method -> Ok({})", ok_text); + let mut rsp = GrpcTestResponse::default(); + rsp.text = ok_text.to_string(); + writer + .write(&rsp, grpc::WriteMode::KeepOpen) + .expect("Failed to write response"); + } + None => panic!("invalid request"), + }; } } } @@ -1166,16 +1181,19 @@ impl FrontendNode { ) .expect("could not write to channel"); + let mut bytes = Vec::new(); + oak::proto::oak::log::LogMessage { + level: oak::proto::oak::log::Level::Info as i32, + file: "abitest".to_string(), + line: 1988, + message: "Wellformed message sent direct to logging channel!".to_string(), + } + .encode(&mut bytes) + .unwrap(); + oak::channel_write( logging_handle, - &oak::proto::log::LogMessage { - level: oak::proto::log::Level::INFO, - file: "abitest".to_string(), - message: "Wellformed message sent direct to logging channel!".to_string(), - ..Default::default() - } - .write_to_bytes() - .unwrap()[..], + &bytes[..], &[in_handle.handle, out_handle.handle], ) .expect("could not write to channel"); @@ -1290,7 +1308,7 @@ impl FrontendNode { let key2 = b"test-key-bogus"; let got = storage.read(&self.storage_name, key2); expect_matches!(got, Err(_)); - expect_eq!(grpc::Code::NOT_FOUND.value(), got.unwrap_err().get_code()); + expect_eq!(grpc::Code::NotFound as i32, got.unwrap_err().code); let got = storage.read(&self.storage_name, key).map_err(from_proto)?; expect_eq!(value.to_vec(), got); @@ -1301,7 +1319,7 @@ impl FrontendNode { let got = storage.read(&self.storage_name, key); expect_matches!(got, Err(_)); - expect_eq!(grpc::Code::NOT_FOUND.value(), got.unwrap_err().get_code()); + expect_eq!(grpc::Code::NotFound as i32, got.unwrap_err().code); storage .delete(&self.storage_name, key) @@ -1326,13 +1344,13 @@ impl FrontendNode { let got = storage.write(&self.storage_name, key, value); expect_matches!(got, Err(_)); - expect_eq!(grpc::Code::UNAVAILABLE.value(), got.unwrap_err().get_code()); + expect_eq!(grpc::Code::Unavailable as i32, got.unwrap_err().code); let got = storage.read(&self.storage_name, key); expect_matches!(got, Err(_)); - expect_eq!(grpc::Code::UNAVAILABLE.value(), got.unwrap_err().get_code()); + expect_eq!(grpc::Code::Unavailable as i32, got.unwrap_err().code); let got = storage.delete(&self.storage_name, key); expect_matches!(got, Err(_)); - expect_eq!(grpc::Code::UNAVAILABLE.value(), got.unwrap_err().get_code()); + expect_eq!(grpc::Code::Unavailable as i32, got.unwrap_err().code); Ok(()) } @@ -1346,25 +1364,26 @@ impl FrontendNode { // Successful unary method invocation of external service via gRPC client pseudo-Node. let ok_req = GrpcTestRequest { - method_result: Some(ok_text("test".to_string())), - ..Default::default() + method_result: Some(proto::grpc_test_request::MethodResult::OkText( + "test".to_string(), + )), }; let ok_rsp = GrpcTestResponse { text: "test".to_string(), - ..Default::default() }; expect_eq!(grpc_stub.unary_method(ok_req), Ok(ok_rsp)); // Errored unary method invocation of external service via gRPC client pseudo-Node. let err_req = GrpcTestRequest { - method_result: Some(err_code(grpc::Code::FAILED_PRECONDITION.value())), - ..Default::default() + method_result: Some(proto::grpc_test_request::MethodResult::ErrCode( + grpc::Code::FailedPrecondition as i32, + )), }; let result = grpc_stub.unary_method(err_req); expect_matches!(result, Err(_)); expect_eq!( - grpc::Code::FAILED_PRECONDITION.value(), - result.unwrap_err().get_code() + grpc::Code::FailedPrecondition as i32, + result.unwrap_err().code ); Ok(()) @@ -1379,12 +1398,12 @@ impl FrontendNode { // Successful server-streaming method invocation of external service via // gRPC client pseudo-Node. let ok_req = GrpcTestRequest { - method_result: Some(ok_text("test".to_string())), - ..Default::default() + method_result: Some(proto::grpc_test_request::MethodResult::OkText( + "test".to_string(), + )), }; let ok_rsp = GrpcTestResponse { text: "test".to_string(), - ..Default::default() }; let receiver = grpc_stub .server_streaming_method(ok_req) @@ -1394,10 +1413,14 @@ impl FrontendNode { match receiver.receive() { Ok(grpc_rsp) => { // TODO(#592): get typed response directly from receiver. - expect_eq!(oak::grpc::Code::OK.value(), grpc_rsp.get_status().code); - let rsp: GrpcTestResponse = - protobuf::parse_from_bytes(&grpc_rsp.get_rsp_msg().value) - .expect("failed to parse GrpcTestResponse"); + expect_eq!( + oak::grpc::Code::Ok as i32, + grpc_rsp.status.unwrap_or_default().code + ); + let rsp = GrpcTestResponse::decode( + grpc_rsp.rsp_msg.unwrap_or_default().value.as_slice(), + ) + .expect("failed to parse GrpcTestResponse"); expect_eq!(rsp.clone(), ok_rsp.clone()); count += 1; } @@ -1412,8 +1435,9 @@ impl FrontendNode { // Errored server-streaming method invocation of external service via // gRPC client pseudo-Node. let err_req = GrpcTestRequest { - method_result: Some(err_code(grpc::Code::FAILED_PRECONDITION.value())), - ..Default::default() + method_result: Some(proto::grpc_test_request::MethodResult::ErrCode( + grpc::Code::FailedPrecondition as i32, + )), }; let receiver = grpc_stub .server_streaming_method(err_req) @@ -1423,8 +1447,8 @@ impl FrontendNode { match receiver.receive() { Ok(grpc_rsp) => { expect_eq!( - grpc::Code::FAILED_PRECONDITION.value(), - grpc_rsp.get_status().code + grpc::Code::FailedPrecondition as i32, + grpc_rsp.status.unwrap_or_default().code ); seen_err_code = true; } @@ -1447,8 +1471,9 @@ impl FrontendNode { )) })?; let req = GrpcTestRequest { - method_result: Some(ok_text("test".to_string())), - ..Default::default() + method_result: Some(proto::grpc_test_request::MethodResult::OkText( + "test".to_string(), + )), }; // Attempting to invoke any sort of method should fail. @@ -1463,7 +1488,7 @@ impl FrontendNode { info!("absent.server_streaming_method().receive() -> {:?}", result); match result { Ok(grpc_rsp) => { - expect!(grpc_rsp.get_status().code != grpc::Code::OK.value()); + expect!(grpc_rsp.status.unwrap_or_default().code != grpc::Code::Ok as i32); } Err(OakError::OakStatus(OakStatus::ErrBadHandle)) => break, Err(OakError::OakStatus(OakStatus::ErrChannelClosed)) => break, @@ -1477,7 +1502,7 @@ impl FrontendNode { } // Helper for storage error conversion. -fn from_proto(status: oak::proto::status::Status) -> Box { +fn from_proto(status: oak::proto::google::rpc::Status) -> Box { Box::new(std::io::Error::new( std::io::ErrorKind::Other, format!("status code {} message '{}'", status.code, status.message), diff --git a/examples/abitest/module_0/rust/src/proto/abitest.rs b/examples/abitest/module_0/rust/src/proto/abitest.rs deleted file mode 100644 index ff53a55450b..00000000000 --- a/examples/abitest/module_0/rust/src/proto/abitest.rs +++ /dev/null @@ -1,1156 +0,0 @@ -// This file is generated by rust-protobuf 2.10.1. Do not edit -// @generated - -// https://github.com/rust-lang/rust-clippy/issues/702 -#![allow(unknown_lints)] -#![allow(clippy::all)] - -#![cfg_attr(rustfmt, rustfmt_skip)] - -#![allow(box_pointers)] -#![allow(dead_code)] -#![allow(missing_docs)] -#![allow(non_camel_case_types)] -#![allow(non_snake_case)] -#![allow(non_upper_case_globals)] -#![allow(trivial_casts)] -#![allow(unsafe_code)] -#![allow(unused_imports)] -#![allow(unused_results)] -//! Generated file from `abitest.proto` - -use protobuf::Message as Message_imported_for_functions; -use protobuf::ProtobufEnum as ProtobufEnum_imported_for_functions; - -/// Generated files are compatible only with the same version -/// of protobuf runtime. -// const _PROTOBUF_VERSION_CHECK: () = ::protobuf::VERSION_2_10_1; - -#[derive(PartialEq,Clone,Default)] -pub struct ABITestRequest { - // message fields - pub include: ::std::string::String, - pub exclude: ::std::string::String, - // special fields - pub unknown_fields: ::protobuf::UnknownFields, - pub cached_size: ::protobuf::CachedSize, -} - -impl<'a> ::std::default::Default for &'a ABITestRequest { - fn default() -> &'a ABITestRequest { - ::default_instance() - } -} - -impl ABITestRequest { - pub fn new() -> ABITestRequest { - ::std::default::Default::default() - } - - // string include = 1; - - - pub fn get_include(&self) -> &str { - &self.include - } - pub fn clear_include(&mut self) { - self.include.clear(); - } - - // Param is passed by value, moved - pub fn set_include(&mut self, v: ::std::string::String) { - self.include = v; - } - - // Mutable pointer to the field. - // If field is not initialized, it is initialized with default value first. - pub fn mut_include(&mut self) -> &mut ::std::string::String { - &mut self.include - } - - // Take field - pub fn take_include(&mut self) -> ::std::string::String { - ::std::mem::replace(&mut self.include, ::std::string::String::new()) - } - - // string exclude = 2; - - - pub fn get_exclude(&self) -> &str { - &self.exclude - } - pub fn clear_exclude(&mut self) { - self.exclude.clear(); - } - - // Param is passed by value, moved - pub fn set_exclude(&mut self, v: ::std::string::String) { - self.exclude = v; - } - - // Mutable pointer to the field. - // If field is not initialized, it is initialized with default value first. - pub fn mut_exclude(&mut self) -> &mut ::std::string::String { - &mut self.exclude - } - - // Take field - pub fn take_exclude(&mut self) -> ::std::string::String { - ::std::mem::replace(&mut self.exclude, ::std::string::String::new()) - } -} - -impl ::protobuf::Message for ABITestRequest { - fn is_initialized(&self) -> bool { - true - } - - fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> { - while !is.eof()? { - let (field_number, wire_type) = is.read_tag_unpack()?; - match field_number { - 1 => { - ::protobuf::rt::read_singular_proto3_string_into(wire_type, is, &mut self.include)?; - }, - 2 => { - ::protobuf::rt::read_singular_proto3_string_into(wire_type, is, &mut self.exclude)?; - }, - _ => { - ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; - }, - }; - } - ::std::result::Result::Ok(()) - } - - // Compute sizes of nested messages - #[allow(unused_variables)] - fn compute_size(&self) -> u32 { - let mut my_size = 0; - if !self.include.is_empty() { - my_size += ::protobuf::rt::string_size(1, &self.include); - } - if !self.exclude.is_empty() { - my_size += ::protobuf::rt::string_size(2, &self.exclude); - } - my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); - self.cached_size.set(my_size); - my_size - } - - fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { - if !self.include.is_empty() { - os.write_string(1, &self.include)?; - } - if !self.exclude.is_empty() { - os.write_string(2, &self.exclude)?; - } - os.write_unknown_fields(self.get_unknown_fields())?; - ::std::result::Result::Ok(()) - } - - fn get_cached_size(&self) -> u32 { - self.cached_size.get() - } - - fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { - &self.unknown_fields - } - - fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { - &mut self.unknown_fields - } - - fn as_any(&self) -> &dyn (::std::any::Any) { - self as &dyn (::std::any::Any) - } - fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { - self as &mut dyn (::std::any::Any) - } - fn into_any(self: Box) -> ::std::boxed::Box { - self - } - - fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { - Self::descriptor_static() - } - - fn new() -> ABITestRequest { - ABITestRequest::new() - } - - fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor { - static mut descriptor: ::protobuf::lazy::Lazy<::protobuf::reflect::MessageDescriptor> = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const ::protobuf::reflect::MessageDescriptor, - }; - unsafe { - descriptor.get(|| { - let mut fields = ::std::vec::Vec::new(); - fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeString>( - "include", - |m: &ABITestRequest| { &m.include }, - |m: &mut ABITestRequest| { &mut m.include }, - )); - fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeString>( - "exclude", - |m: &ABITestRequest| { &m.exclude }, - |m: &mut ABITestRequest| { &mut m.exclude }, - )); - ::protobuf::reflect::MessageDescriptor::new::( - "ABITestRequest", - fields, - file_descriptor_proto() - ) - }) - } - } - - fn default_instance() -> &'static ABITestRequest { - static mut instance: ::protobuf::lazy::Lazy = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const ABITestRequest, - }; - unsafe { - instance.get(ABITestRequest::new) - } - } -} - -impl ::protobuf::Clear for ABITestRequest { - fn clear(&mut self) { - self.include.clear(); - self.exclude.clear(); - self.unknown_fields.clear(); - } -} - -impl ::std::fmt::Debug for ABITestRequest { - fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { - ::protobuf::text_format::fmt(self, f) - } -} - -impl ::protobuf::reflect::ProtobufValue for ABITestRequest { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { - ::protobuf::reflect::ProtobufValueRef::Message(self) - } -} - -#[derive(PartialEq,Clone,Default)] -pub struct ABITestResponse { - // message fields - pub results: ::protobuf::RepeatedField, - // special fields - pub unknown_fields: ::protobuf::UnknownFields, - pub cached_size: ::protobuf::CachedSize, -} - -impl<'a> ::std::default::Default for &'a ABITestResponse { - fn default() -> &'a ABITestResponse { - ::default_instance() - } -} - -impl ABITestResponse { - pub fn new() -> ABITestResponse { - ::std::default::Default::default() - } - - // repeated .oak.examples.abitest.ABITestResponse.TestResult results = 1; - - - pub fn get_results(&self) -> &[ABITestResponse_TestResult] { - &self.results - } - pub fn clear_results(&mut self) { - self.results.clear(); - } - - // Param is passed by value, moved - pub fn set_results(&mut self, v: ::protobuf::RepeatedField) { - self.results = v; - } - - // Mutable pointer to the field. - pub fn mut_results(&mut self) -> &mut ::protobuf::RepeatedField { - &mut self.results - } - - // Take field - pub fn take_results(&mut self) -> ::protobuf::RepeatedField { - ::std::mem::replace(&mut self.results, ::protobuf::RepeatedField::new()) - } -} - -impl ::protobuf::Message for ABITestResponse { - fn is_initialized(&self) -> bool { - for v in &self.results { - if !v.is_initialized() { - return false; - } - }; - true - } - - fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> { - while !is.eof()? { - let (field_number, wire_type) = is.read_tag_unpack()?; - match field_number { - 1 => { - ::protobuf::rt::read_repeated_message_into(wire_type, is, &mut self.results)?; - }, - _ => { - ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; - }, - }; - } - ::std::result::Result::Ok(()) - } - - // Compute sizes of nested messages - #[allow(unused_variables)] - fn compute_size(&self) -> u32 { - let mut my_size = 0; - for value in &self.results { - let len = value.compute_size(); - my_size += 1 + ::protobuf::rt::compute_raw_varint32_size(len) + len; - }; - my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); - self.cached_size.set(my_size); - my_size - } - - fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { - for v in &self.results { - os.write_tag(1, ::protobuf::wire_format::WireTypeLengthDelimited)?; - os.write_raw_varint32(v.get_cached_size())?; - v.write_to_with_cached_sizes(os)?; - }; - os.write_unknown_fields(self.get_unknown_fields())?; - ::std::result::Result::Ok(()) - } - - fn get_cached_size(&self) -> u32 { - self.cached_size.get() - } - - fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { - &self.unknown_fields - } - - fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { - &mut self.unknown_fields - } - - fn as_any(&self) -> &dyn (::std::any::Any) { - self as &dyn (::std::any::Any) - } - fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { - self as &mut dyn (::std::any::Any) - } - fn into_any(self: Box) -> ::std::boxed::Box { - self - } - - fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { - Self::descriptor_static() - } - - fn new() -> ABITestResponse { - ABITestResponse::new() - } - - fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor { - static mut descriptor: ::protobuf::lazy::Lazy<::protobuf::reflect::MessageDescriptor> = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const ::protobuf::reflect::MessageDescriptor, - }; - unsafe { - descriptor.get(|| { - let mut fields = ::std::vec::Vec::new(); - fields.push(::protobuf::reflect::accessor::make_repeated_field_accessor::<_, ::protobuf::types::ProtobufTypeMessage>( - "results", - |m: &ABITestResponse| { &m.results }, - |m: &mut ABITestResponse| { &mut m.results }, - )); - ::protobuf::reflect::MessageDescriptor::new::( - "ABITestResponse", - fields, - file_descriptor_proto() - ) - }) - } - } - - fn default_instance() -> &'static ABITestResponse { - static mut instance: ::protobuf::lazy::Lazy = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const ABITestResponse, - }; - unsafe { - instance.get(ABITestResponse::new) - } - } -} - -impl ::protobuf::Clear for ABITestResponse { - fn clear(&mut self) { - self.results.clear(); - self.unknown_fields.clear(); - } -} - -impl ::std::fmt::Debug for ABITestResponse { - fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { - ::protobuf::text_format::fmt(self, f) - } -} - -impl ::protobuf::reflect::ProtobufValue for ABITestResponse { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { - ::protobuf::reflect::ProtobufValueRef::Message(self) - } -} - -#[derive(PartialEq,Clone,Default)] -pub struct ABITestResponse_TestResult { - // message fields - pub name: ::std::string::String, - pub success: bool, - pub details: ::std::string::String, - pub disabled: bool, - // special fields - pub unknown_fields: ::protobuf::UnknownFields, - pub cached_size: ::protobuf::CachedSize, -} - -impl<'a> ::std::default::Default for &'a ABITestResponse_TestResult { - fn default() -> &'a ABITestResponse_TestResult { - ::default_instance() - } -} - -impl ABITestResponse_TestResult { - pub fn new() -> ABITestResponse_TestResult { - ::std::default::Default::default() - } - - // string name = 1; - - - pub fn get_name(&self) -> &str { - &self.name - } - pub fn clear_name(&mut self) { - self.name.clear(); - } - - // Param is passed by value, moved - pub fn set_name(&mut self, v: ::std::string::String) { - self.name = v; - } - - // Mutable pointer to the field. - // If field is not initialized, it is initialized with default value first. - pub fn mut_name(&mut self) -> &mut ::std::string::String { - &mut self.name - } - - // Take field - pub fn take_name(&mut self) -> ::std::string::String { - ::std::mem::replace(&mut self.name, ::std::string::String::new()) - } - - // bool success = 2; - - - pub fn get_success(&self) -> bool { - self.success - } - pub fn clear_success(&mut self) { - self.success = false; - } - - // Param is passed by value, moved - pub fn set_success(&mut self, v: bool) { - self.success = v; - } - - // string details = 3; - - - pub fn get_details(&self) -> &str { - &self.details - } - pub fn clear_details(&mut self) { - self.details.clear(); - } - - // Param is passed by value, moved - pub fn set_details(&mut self, v: ::std::string::String) { - self.details = v; - } - - // Mutable pointer to the field. - // If field is not initialized, it is initialized with default value first. - pub fn mut_details(&mut self) -> &mut ::std::string::String { - &mut self.details - } - - // Take field - pub fn take_details(&mut self) -> ::std::string::String { - ::std::mem::replace(&mut self.details, ::std::string::String::new()) - } - - // bool disabled = 4; - - - pub fn get_disabled(&self) -> bool { - self.disabled - } - pub fn clear_disabled(&mut self) { - self.disabled = false; - } - - // Param is passed by value, moved - pub fn set_disabled(&mut self, v: bool) { - self.disabled = v; - } -} - -impl ::protobuf::Message for ABITestResponse_TestResult { - fn is_initialized(&self) -> bool { - true - } - - fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> { - while !is.eof()? { - let (field_number, wire_type) = is.read_tag_unpack()?; - match field_number { - 1 => { - ::protobuf::rt::read_singular_proto3_string_into(wire_type, is, &mut self.name)?; - }, - 2 => { - if wire_type != ::protobuf::wire_format::WireTypeVarint { - return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); - } - let tmp = is.read_bool()?; - self.success = tmp; - }, - 3 => { - ::protobuf::rt::read_singular_proto3_string_into(wire_type, is, &mut self.details)?; - }, - 4 => { - if wire_type != ::protobuf::wire_format::WireTypeVarint { - return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); - } - let tmp = is.read_bool()?; - self.disabled = tmp; - }, - _ => { - ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; - }, - }; - } - ::std::result::Result::Ok(()) - } - - // Compute sizes of nested messages - #[allow(unused_variables)] - fn compute_size(&self) -> u32 { - let mut my_size = 0; - if !self.name.is_empty() { - my_size += ::protobuf::rt::string_size(1, &self.name); - } - if self.success != false { - my_size += 2; - } - if !self.details.is_empty() { - my_size += ::protobuf::rt::string_size(3, &self.details); - } - if self.disabled != false { - my_size += 2; - } - my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); - self.cached_size.set(my_size); - my_size - } - - fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { - if !self.name.is_empty() { - os.write_string(1, &self.name)?; - } - if self.success != false { - os.write_bool(2, self.success)?; - } - if !self.details.is_empty() { - os.write_string(3, &self.details)?; - } - if self.disabled != false { - os.write_bool(4, self.disabled)?; - } - os.write_unknown_fields(self.get_unknown_fields())?; - ::std::result::Result::Ok(()) - } - - fn get_cached_size(&self) -> u32 { - self.cached_size.get() - } - - fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { - &self.unknown_fields - } - - fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { - &mut self.unknown_fields - } - - fn as_any(&self) -> &dyn (::std::any::Any) { - self as &dyn (::std::any::Any) - } - fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { - self as &mut dyn (::std::any::Any) - } - fn into_any(self: Box) -> ::std::boxed::Box { - self - } - - fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { - Self::descriptor_static() - } - - fn new() -> ABITestResponse_TestResult { - ABITestResponse_TestResult::new() - } - - fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor { - static mut descriptor: ::protobuf::lazy::Lazy<::protobuf::reflect::MessageDescriptor> = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const ::protobuf::reflect::MessageDescriptor, - }; - unsafe { - descriptor.get(|| { - let mut fields = ::std::vec::Vec::new(); - fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeString>( - "name", - |m: &ABITestResponse_TestResult| { &m.name }, - |m: &mut ABITestResponse_TestResult| { &mut m.name }, - )); - fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeBool>( - "success", - |m: &ABITestResponse_TestResult| { &m.success }, - |m: &mut ABITestResponse_TestResult| { &mut m.success }, - )); - fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeString>( - "details", - |m: &ABITestResponse_TestResult| { &m.details }, - |m: &mut ABITestResponse_TestResult| { &mut m.details }, - )); - fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeBool>( - "disabled", - |m: &ABITestResponse_TestResult| { &m.disabled }, - |m: &mut ABITestResponse_TestResult| { &mut m.disabled }, - )); - ::protobuf::reflect::MessageDescriptor::new::( - "ABITestResponse_TestResult", - fields, - file_descriptor_proto() - ) - }) - } - } - - fn default_instance() -> &'static ABITestResponse_TestResult { - static mut instance: ::protobuf::lazy::Lazy = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const ABITestResponse_TestResult, - }; - unsafe { - instance.get(ABITestResponse_TestResult::new) - } - } -} - -impl ::protobuf::Clear for ABITestResponse_TestResult { - fn clear(&mut self) { - self.name.clear(); - self.success = false; - self.details.clear(); - self.disabled = false; - self.unknown_fields.clear(); - } -} - -impl ::std::fmt::Debug for ABITestResponse_TestResult { - fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { - ::protobuf::text_format::fmt(self, f) - } -} - -impl ::protobuf::reflect::ProtobufValue for ABITestResponse_TestResult { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { - ::protobuf::reflect::ProtobufValueRef::Message(self) - } -} - -#[derive(PartialEq,Clone,Default)] -pub struct GrpcTestRequest { - // message oneof groups - pub method_result: ::std::option::Option, - // special fields - pub unknown_fields: ::protobuf::UnknownFields, - pub cached_size: ::protobuf::CachedSize, -} - -impl<'a> ::std::default::Default for &'a GrpcTestRequest { - fn default() -> &'a GrpcTestRequest { - ::default_instance() - } -} - -#[derive(Clone,PartialEq,Debug)] -pub enum GrpcTestRequest_oneof_method_result { - err_code(i32), - ok_text(::std::string::String), -} - -impl GrpcTestRequest { - pub fn new() -> GrpcTestRequest { - ::std::default::Default::default() - } - - // int32 err_code = 1; - - - pub fn get_err_code(&self) -> i32 { - match self.method_result { - ::std::option::Option::Some(GrpcTestRequest_oneof_method_result::err_code(v)) => v, - _ => 0, - } - } - pub fn clear_err_code(&mut self) { - self.method_result = ::std::option::Option::None; - } - - pub fn has_err_code(&self) -> bool { - match self.method_result { - ::std::option::Option::Some(GrpcTestRequest_oneof_method_result::err_code(..)) => true, - _ => false, - } - } - - // Param is passed by value, moved - pub fn set_err_code(&mut self, v: i32) { - self.method_result = ::std::option::Option::Some(GrpcTestRequest_oneof_method_result::err_code(v)) - } - - // string ok_text = 2; - - - pub fn get_ok_text(&self) -> &str { - match self.method_result { - ::std::option::Option::Some(GrpcTestRequest_oneof_method_result::ok_text(ref v)) => v, - _ => "", - } - } - pub fn clear_ok_text(&mut self) { - self.method_result = ::std::option::Option::None; - } - - pub fn has_ok_text(&self) -> bool { - match self.method_result { - ::std::option::Option::Some(GrpcTestRequest_oneof_method_result::ok_text(..)) => true, - _ => false, - } - } - - // Param is passed by value, moved - pub fn set_ok_text(&mut self, v: ::std::string::String) { - self.method_result = ::std::option::Option::Some(GrpcTestRequest_oneof_method_result::ok_text(v)) - } - - // Mutable pointer to the field. - pub fn mut_ok_text(&mut self) -> &mut ::std::string::String { - if let ::std::option::Option::Some(GrpcTestRequest_oneof_method_result::ok_text(_)) = self.method_result { - } else { - self.method_result = ::std::option::Option::Some(GrpcTestRequest_oneof_method_result::ok_text(::std::string::String::new())); - } - match self.method_result { - ::std::option::Option::Some(GrpcTestRequest_oneof_method_result::ok_text(ref mut v)) => v, - _ => panic!(), - } - } - - // Take field - pub fn take_ok_text(&mut self) -> ::std::string::String { - if self.has_ok_text() { - match self.method_result.take() { - ::std::option::Option::Some(GrpcTestRequest_oneof_method_result::ok_text(v)) => v, - _ => panic!(), - } - } else { - ::std::string::String::new() - } - } -} - -impl ::protobuf::Message for GrpcTestRequest { - fn is_initialized(&self) -> bool { - true - } - - fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> { - while !is.eof()? { - let (field_number, wire_type) = is.read_tag_unpack()?; - match field_number { - 1 => { - if wire_type != ::protobuf::wire_format::WireTypeVarint { - return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); - } - self.method_result = ::std::option::Option::Some(GrpcTestRequest_oneof_method_result::err_code(is.read_int32()?)); - }, - 2 => { - if wire_type != ::protobuf::wire_format::WireTypeLengthDelimited { - return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); - } - self.method_result = ::std::option::Option::Some(GrpcTestRequest_oneof_method_result::ok_text(is.read_string()?)); - }, - _ => { - ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; - }, - }; - } - ::std::result::Result::Ok(()) - } - - // Compute sizes of nested messages - #[allow(unused_variables)] - fn compute_size(&self) -> u32 { - let mut my_size = 0; - if let ::std::option::Option::Some(ref v) = self.method_result { - match v { - &GrpcTestRequest_oneof_method_result::err_code(v) => { - my_size += ::protobuf::rt::value_size(1, v, ::protobuf::wire_format::WireTypeVarint); - }, - &GrpcTestRequest_oneof_method_result::ok_text(ref v) => { - my_size += ::protobuf::rt::string_size(2, &v); - }, - }; - } - my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); - self.cached_size.set(my_size); - my_size - } - - fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { - if let ::std::option::Option::Some(ref v) = self.method_result { - match v { - &GrpcTestRequest_oneof_method_result::err_code(v) => { - os.write_int32(1, v)?; - }, - &GrpcTestRequest_oneof_method_result::ok_text(ref v) => { - os.write_string(2, v)?; - }, - }; - } - os.write_unknown_fields(self.get_unknown_fields())?; - ::std::result::Result::Ok(()) - } - - fn get_cached_size(&self) -> u32 { - self.cached_size.get() - } - - fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { - &self.unknown_fields - } - - fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { - &mut self.unknown_fields - } - - fn as_any(&self) -> &dyn (::std::any::Any) { - self as &dyn (::std::any::Any) - } - fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { - self as &mut dyn (::std::any::Any) - } - fn into_any(self: Box) -> ::std::boxed::Box { - self - } - - fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { - Self::descriptor_static() - } - - fn new() -> GrpcTestRequest { - GrpcTestRequest::new() - } - - fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor { - static mut descriptor: ::protobuf::lazy::Lazy<::protobuf::reflect::MessageDescriptor> = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const ::protobuf::reflect::MessageDescriptor, - }; - unsafe { - descriptor.get(|| { - let mut fields = ::std::vec::Vec::new(); - fields.push(::protobuf::reflect::accessor::make_singular_i32_accessor::<_>( - "err_code", - GrpcTestRequest::has_err_code, - GrpcTestRequest::get_err_code, - )); - fields.push(::protobuf::reflect::accessor::make_singular_string_accessor::<_>( - "ok_text", - GrpcTestRequest::has_ok_text, - GrpcTestRequest::get_ok_text, - )); - ::protobuf::reflect::MessageDescriptor::new::( - "GrpcTestRequest", - fields, - file_descriptor_proto() - ) - }) - } - } - - fn default_instance() -> &'static GrpcTestRequest { - static mut instance: ::protobuf::lazy::Lazy = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const GrpcTestRequest, - }; - unsafe { - instance.get(GrpcTestRequest::new) - } - } -} - -impl ::protobuf::Clear for GrpcTestRequest { - fn clear(&mut self) { - self.method_result = ::std::option::Option::None; - self.method_result = ::std::option::Option::None; - self.unknown_fields.clear(); - } -} - -impl ::std::fmt::Debug for GrpcTestRequest { - fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { - ::protobuf::text_format::fmt(self, f) - } -} - -impl ::protobuf::reflect::ProtobufValue for GrpcTestRequest { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { - ::protobuf::reflect::ProtobufValueRef::Message(self) - } -} - -#[derive(PartialEq,Clone,Default)] -pub struct GrpcTestResponse { - // message fields - pub text: ::std::string::String, - // special fields - pub unknown_fields: ::protobuf::UnknownFields, - pub cached_size: ::protobuf::CachedSize, -} - -impl<'a> ::std::default::Default for &'a GrpcTestResponse { - fn default() -> &'a GrpcTestResponse { - ::default_instance() - } -} - -impl GrpcTestResponse { - pub fn new() -> GrpcTestResponse { - ::std::default::Default::default() - } - - // string text = 1; - - - pub fn get_text(&self) -> &str { - &self.text - } - pub fn clear_text(&mut self) { - self.text.clear(); - } - - // Param is passed by value, moved - pub fn set_text(&mut self, v: ::std::string::String) { - self.text = v; - } - - // Mutable pointer to the field. - // If field is not initialized, it is initialized with default value first. - pub fn mut_text(&mut self) -> &mut ::std::string::String { - &mut self.text - } - - // Take field - pub fn take_text(&mut self) -> ::std::string::String { - ::std::mem::replace(&mut self.text, ::std::string::String::new()) - } -} - -impl ::protobuf::Message for GrpcTestResponse { - fn is_initialized(&self) -> bool { - true - } - - fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> { - while !is.eof()? { - let (field_number, wire_type) = is.read_tag_unpack()?; - match field_number { - 1 => { - ::protobuf::rt::read_singular_proto3_string_into(wire_type, is, &mut self.text)?; - }, - _ => { - ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; - }, - }; - } - ::std::result::Result::Ok(()) - } - - // Compute sizes of nested messages - #[allow(unused_variables)] - fn compute_size(&self) -> u32 { - let mut my_size = 0; - if !self.text.is_empty() { - my_size += ::protobuf::rt::string_size(1, &self.text); - } - my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); - self.cached_size.set(my_size); - my_size - } - - fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { - if !self.text.is_empty() { - os.write_string(1, &self.text)?; - } - os.write_unknown_fields(self.get_unknown_fields())?; - ::std::result::Result::Ok(()) - } - - fn get_cached_size(&self) -> u32 { - self.cached_size.get() - } - - fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { - &self.unknown_fields - } - - fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { - &mut self.unknown_fields - } - - fn as_any(&self) -> &dyn (::std::any::Any) { - self as &dyn (::std::any::Any) - } - fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { - self as &mut dyn (::std::any::Any) - } - fn into_any(self: Box) -> ::std::boxed::Box { - self - } - - fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { - Self::descriptor_static() - } - - fn new() -> GrpcTestResponse { - GrpcTestResponse::new() - } - - fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor { - static mut descriptor: ::protobuf::lazy::Lazy<::protobuf::reflect::MessageDescriptor> = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const ::protobuf::reflect::MessageDescriptor, - }; - unsafe { - descriptor.get(|| { - let mut fields = ::std::vec::Vec::new(); - fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeString>( - "text", - |m: &GrpcTestResponse| { &m.text }, - |m: &mut GrpcTestResponse| { &mut m.text }, - )); - ::protobuf::reflect::MessageDescriptor::new::( - "GrpcTestResponse", - fields, - file_descriptor_proto() - ) - }) - } - } - - fn default_instance() -> &'static GrpcTestResponse { - static mut instance: ::protobuf::lazy::Lazy = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const GrpcTestResponse, - }; - unsafe { - instance.get(GrpcTestResponse::new) - } - } -} - -impl ::protobuf::Clear for GrpcTestResponse { - fn clear(&mut self) { - self.text.clear(); - self.unknown_fields.clear(); - } -} - -impl ::std::fmt::Debug for GrpcTestResponse { - fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { - ::protobuf::text_format::fmt(self, f) - } -} - -impl ::protobuf::reflect::ProtobufValue for GrpcTestResponse { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { - ::protobuf::reflect::ProtobufValueRef::Message(self) - } -} - -static file_descriptor_proto_data: &'static [u8] = b"\ - \n\rabitest.proto\x12\x14oak.examples.abitest\"D\n\x0eABITestRequest\x12\ - \x18\n\x07include\x18\x01\x20\x01(\tR\x07include\x12\x18\n\x07exclude\ - \x18\x02\x20\x01(\tR\x07exclude\"\xcf\x01\n\x0fABITestResponse\x12J\n\ - \x07results\x18\x01\x20\x03(\x0b20.oak.examples.abitest.ABITestResponse.\ - TestResultR\x07results\x1ap\n\nTestResult\x12\x12\n\x04name\x18\x01\x20\ - \x01(\tR\x04name\x12\x18\n\x07success\x18\x02\x20\x01(\x08R\x07success\ - \x12\x18\n\x07details\x18\x03\x20\x01(\tR\x07details\x12\x1a\n\x08disabl\ - ed\x18\x04\x20\x01(\x08R\x08disabled\"Z\n\x0fGrpcTestRequest\x12\x1b\n\ - \x08err_code\x18\x01\x20\x01(\x05H\0R\x07errCode\x12\x19\n\x07ok_text\ - \x18\x02\x20\x01(\tH\0R\x06okTextB\x0f\n\rmethod_result\"&\n\x10GrpcTest\ - Response\x12\x12\n\x04text\x18\x01\x20\x01(\tR\x04text2\x88\x04\n\x11Oak\ - ABITestService\x12W\n\x08RunTests\x12$.oak.examples.abitest.ABITestReque\ - st\x1a%.oak.examples.abitest.ABITestResponse\x12\\\n\x0bUnaryMethod\x12%\ - .oak.examples.abitest.GrpcTestRequest\x1a&.oak.examples.abitest.GrpcTest\ - Response\x12h\n\x15ServerStreamingMethod\x12%.oak.examples.abitest.GrpcT\ - estRequest\x1a&.oak.examples.abitest.GrpcTestResponse0\x01\x12h\n\x15Cli\ - entStreamingMethod\x12%.oak.examples.abitest.GrpcTestRequest\x1a&.oak.ex\ - amples.abitest.GrpcTestResponse(\x01\x12h\n\x13BidiStreamingMethod\x12%.\ - oak.examples.abitest.GrpcTestRequest\x1a&.oak.examples.abitest.GrpcTestR\ - esponse(\x010\x01b\x06proto3\ -"; - -static mut file_descriptor_proto_lazy: ::protobuf::lazy::Lazy<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const ::protobuf::descriptor::FileDescriptorProto, -}; - -fn parse_descriptor_proto() -> ::protobuf::descriptor::FileDescriptorProto { - ::protobuf::parse_from_bytes(file_descriptor_proto_data).unwrap() -} - -pub fn file_descriptor_proto() -> &'static ::protobuf::descriptor::FileDescriptorProto { - unsafe { - file_descriptor_proto_lazy.get(|| { - parse_descriptor_proto() - }) - } -} diff --git a/examples/abitest/module_0/rust/src/proto/abitest_grpc.rs b/examples/abitest/module_0/rust/src/proto/abitest_grpc.rs deleted file mode 100644 index 14e34a64e87..00000000000 --- a/examples/abitest/module_0/rust/src/proto/abitest_grpc.rs +++ /dev/null @@ -1,73 +0,0 @@ -// This file is generated. Do not edit -// @generated - -// https://github.com/rust-lang/rust-clippy/issues/702 -#![allow(unknown_lints)] -#![allow(clippy::all)] - -#![cfg_attr(rustfmt, rustfmt_skip)] - -#![allow(box_pointers)] -#![allow(dead_code)] -#![allow(missing_docs)] -#![allow(non_camel_case_types)] -#![allow(non_snake_case)] -#![allow(non_upper_case_globals)] -#![allow(trivial_casts)] -#![allow(unsafe_code)] -#![allow(unused_imports)] -#![allow(unused_results)] - - -use oak::grpc; -use protobuf::Message; -use std::io::Write; -use log::error; - -// Oak Node server interface -pub trait OakABITestService { - fn run_tests(&mut self, req: super::abitest::ABITestRequest) -> grpc::Result; - fn unary_method(&mut self, req: super::abitest::GrpcTestRequest) -> grpc::Result; - fn server_streaming_method(&mut self, req: super::abitest::GrpcTestRequest, writer: grpc::ChannelResponseWriter); - fn client_streaming_method(&mut self, reqs: Vec) -> grpc::Result; - fn bidi_streaming_method(&mut self, reqs: Vec, writer: grpc::ChannelResponseWriter); -} - -// Oak Node gRPC method dispatcher -pub struct Dispatcher(T); - -impl Dispatcher { - pub fn new(node: T) -> Dispatcher { - Dispatcher(node) - } -} - -impl grpc::ServerNode for Dispatcher { - fn invoke(&mut self, method: &str, req: &[u8], writer: grpc::ChannelResponseWriter) { - match method { - "/oak.examples.abitest.OakABITestService/RunTests" => grpc::handle_req_rsp(|r| self.0.run_tests(r), req, writer), - "/oak.examples.abitest.OakABITestService/UnaryMethod" => grpc::handle_req_rsp(|r| self.0.unary_method(r), req, writer), - "/oak.examples.abitest.OakABITestService/ServerStreamingMethod" => grpc::handle_req_stream(|r, w| self.0.server_streaming_method(r, w), req, writer), - "/oak.examples.abitest.OakABITestService/ClientStreamingMethod" => grpc::handle_stream_rsp(|rr| self.0.client_streaming_method(rr), req, writer), - "/oak.examples.abitest.OakABITestService/BidiStreamingMethod" => grpc::handle_stream_stream(|rr, w| self.0.bidi_streaming_method(rr, w), req, writer), - _ => { - error!("unknown method name: {}", method); - } - }; - } -} - -// Client interface -pub struct OakABITestServiceClient(pub oak::grpc::client::Client); - -impl OakABITestServiceClient { - pub fn run_tests(&self, req: super::abitest::ABITestRequest) -> grpc::Result { - oak::grpc::invoke_grpc_method("/oak.examples.abitest.OakABITestService/RunTests", &req, Some("type.googleapis.com/oak.examples.abitest.ABITestRequest"), &self.0.invocation_sender) - } - pub fn unary_method(&self, req: super::abitest::GrpcTestRequest) -> grpc::Result { - oak::grpc::invoke_grpc_method("/oak.examples.abitest.OakABITestService/UnaryMethod", &req, Some("type.googleapis.com/oak.examples.abitest.GrpcTestRequest"), &self.0.invocation_sender) - } - pub fn server_streaming_method(&self, req: super::abitest::GrpcTestRequest) -> grpc::Result> { - oak::grpc::invoke_grpc_method_stream("/oak.examples.abitest.OakABITestService/ServerStreamingMethod", &req, Some("type.googleapis.com/oak.examples.abitest.GrpcTestRequest"), &self.0.invocation_sender) - } -} diff --git a/examples/abitest/module_0/rust/src/proto/mod.rs b/examples/abitest/module_0/rust/src/proto/mod.rs deleted file mode 100644 index fe71700bf62..00000000000 --- a/examples/abitest/module_0/rust/src/proto/mod.rs +++ /dev/null @@ -1,18 +0,0 @@ -// -// Copyright 2019 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. -// - -pub mod abitest; -pub mod abitest_grpc; diff --git a/examples/abitest/module_1/rust/Cargo.toml b/examples/abitest/module_1/rust/Cargo.toml index 7a275a9e34e..ee3104c5203 100644 --- a/examples/abitest/module_1/rust/Cargo.toml +++ b/examples/abitest/module_1/rust/Cargo.toml @@ -11,6 +11,6 @@ crate-type = ["cdylib", "lib"] log = "*" abitest_common = { path = "../../abitest_common" } oak = "=0.1.0" -protobuf = "*" +prost = "*" serde = { version = "*", features = ["derive"] } serde_json = "*" diff --git a/examples/abitest/tests/Cargo.toml b/examples/abitest/tests/Cargo.toml index 945ed9c7693..94f9acefeea 100644 --- a/examples/abitest/tests/Cargo.toml +++ b/examples/abitest/tests/Cargo.toml @@ -13,7 +13,7 @@ abitest_1_backend = { path = "../module_1/rust" } log = "*" oak = "=0.1.0" oak_abi = "=0.1.0" -protobuf = "*" +prost = "*" [dev-dependencies] assert_matches = "*" diff --git a/examples/abitest/tests/src/tests.rs b/examples/abitest/tests/src/tests.rs index 0b81e0812ef..b5e677b3d4e 100644 --- a/examples/abitest/tests/src/tests.rs +++ b/examples/abitest/tests/src/tests.rs @@ -14,7 +14,7 @@ // limitations under the License. // -use abitest_0_frontend::proto::abitest::{ABITestRequest, ABITestResponse}; +use abitest_0_frontend::proto::{AbiTestRequest, AbiTestResponse}; use assert_matches::assert_matches; use log::{error, info}; use maplit::hashmap; @@ -56,10 +56,10 @@ fn test_abi() { .expect("unable to configure runtime with test wasm"); // TODO(#540): reinstate storage and gRPC client tests when Rust runtime supports them. - let mut req = ABITestRequest::new(); + let mut req = AbiTestRequest::default(); req.exclude = "(Storage|GrpcClient)".to_string(); - let result: grpc::Result = oak_tests::grpc_request( + let result: grpc::Result = oak_tests::grpc_request( &runtime, entry_channel, "/oak.examples.abitest.OakABITestService/RunTests", @@ -70,7 +70,7 @@ fn test_abi() { runtime.stop(); let mut disabled = 0; - for result in result.unwrap().get_results() { + for result in result.unwrap().results { if result.disabled { disabled += 1; continue; diff --git a/examples/aggregator/backend/Cargo.toml b/examples/aggregator/backend/Cargo.toml index aebb1d6d29c..29d7e111a40 100644 --- a/examples/aggregator/backend/Cargo.toml +++ b/examples/aggregator/backend/Cargo.toml @@ -10,7 +10,6 @@ futures-core = "*" futures-util = "*" log = "*" prost = "*" -protobuf = "*" tokio = { version = "*", features = ["fs", "macros", "sync", "stream"] } tonic = { version = "*", features = ["tls"] } diff --git a/examples/aggregator/module/rust/Cargo.toml b/examples/aggregator/module/rust/Cargo.toml index 161f1d9b261..0d02bec8faf 100644 --- a/examples/aggregator/module/rust/Cargo.toml +++ b/examples/aggregator/module/rust/Cargo.toml @@ -12,7 +12,7 @@ aggregator_common = { path = "../../common" } itertools = "*" log = "*" oak = "=0.1.0" -protobuf = "*" +prost = "*" [dev-dependencies] assert_matches = "*" @@ -23,4 +23,3 @@ simple_logger = "*" [build-dependencies] oak_utils = "*" -protoc-rust-grpc = { path = "../../../../third_party/grpc-rust/protoc-rust-grpc" } diff --git a/examples/aggregator/module/rust/build.rs b/examples/aggregator/module/rust/build.rs index d7bd17e12b3..71c9390f869 100644 --- a/examples/aggregator/module/rust/build.rs +++ b/examples/aggregator/module/rust/build.rs @@ -15,12 +15,5 @@ // fn main() { - oak_utils::run_protoc_rust_grpc(protoc_rust_grpc::Args { - out_dir: "src/proto", - input: &["../../proto/aggregator.proto"], - includes: &["../../proto"], - rust_protobuf: true, // also generate protobuf messages, not just services - ..Default::default() - }) - .expect("protoc-rust-grpc"); + oak_utils::compile_protos(&["../../proto/aggregator.proto"], &["../../proto"]); } diff --git a/examples/aggregator/module/rust/src/data.rs b/examples/aggregator/module/rust/src/data.rs index 2175d583d26..e7974e2fa5f 100644 --- a/examples/aggregator/module/rust/src/data.rs +++ b/examples/aggregator/module/rust/src/data.rs @@ -14,7 +14,7 @@ // limitations under the License. // -use crate::proto::aggregator::SerializedSparseVector; +use crate::proto::SerializedSparseVector; use aggregator_common::Monoid; use std::collections::HashMap; use std::convert::{From, TryFrom}; @@ -66,7 +66,7 @@ impl From for SerializedSparseVector { fn from(src: SparseVector) -> Self { src.entries .iter() - .fold(SerializedSparseVector::new(), |mut vec, (&i, &v)| { + .fold(SerializedSparseVector::default(), |mut vec, (&i, &v)| { vec.indices.push(i); vec.values.push(v); vec diff --git a/examples/aggregator/module/rust/src/lib.rs b/examples/aggregator/module/rust/src/lib.rs index 84f26a391ee..3afbfd174dd 100644 --- a/examples/aggregator/module/rust/src/lib.rs +++ b/examples/aggregator/module/rust/src/lib.rs @@ -23,7 +23,10 @@ //! and a Sparse Vector - a dictionary with integer keys. mod data; -mod proto; +mod proto { + include!(concat!(env!("OUT_DIR"), "/oak.examples.aggregator.rs")); +} + #[cfg(test)] mod tests; @@ -31,9 +34,7 @@ use aggregator_common::ThresholdAggregator; use data::SparseVector; use log::{debug, error}; use oak::grpc; -use proto::aggregator::Sample; -use proto::aggregator_grpc::{Aggregator, AggregatorClient, Dispatcher}; -use protobuf::well_known_types::Empty; +use proto::{Aggregator, AggregatorClient, AggregatorDispatcher, Sample}; use std::collections::HashMap; use std::convert::TryFrom; @@ -96,8 +97,7 @@ impl AggregatorNode { Some(grpc_client) => { let res = grpc_client.submit_sample(Sample { bucket, - data: ::protobuf::SingularPtrField::some(svec.into()), - ..Default::default() + data: Some(svec.into()), }); match res { Ok(_) => Ok(()), @@ -111,8 +111,8 @@ impl AggregatorNode { /// A gRPC service implementation for the Aggregator example. impl Aggregator for AggregatorNode { - fn submit_sample(&mut self, sample: Sample) -> grpc::Result { - match sample.data.into_option() { + fn submit_sample(&mut self, sample: Sample) -> grpc::Result<()> { + match sample.data { Some(data) => match SparseVector::try_from(&data) { Ok(svec) => { debug!( @@ -120,21 +120,21 @@ impl Aggregator for AggregatorNode { sample.bucket, svec ); match self.submit(sample.bucket, &svec) { - Ok(_) => Ok(Empty::new()), + Ok(_) => Ok(()), Err(err) => { let err = format!("Submit sample error: {}", err); - Err(grpc::build_status(grpc::Code::INVALID_ARGUMENT, &err)) + Err(grpc::build_status(grpc::Code::InvalidArgument, &err)) } } } Err(err) => { let err = format!("Data deserialization error: {}", err); - Err(grpc::build_status(grpc::Code::INVALID_ARGUMENT, &err)) + Err(grpc::build_status(grpc::Code::InvalidArgument, &err)) } }, None => { let err = "No data specified"; - Err(grpc::build_status(grpc::Code::INVALID_ARGUMENT, &err)) + Err(grpc::build_status(grpc::Code::InvalidArgument, &err)) } } } @@ -143,5 +143,5 @@ impl Aggregator for AggregatorNode { oak::entrypoint!(oak_main => { oak::logger::init_default(); let node = AggregatorNode::new(); - Dispatcher::new(node) + AggregatorDispatcher::new(node) }); diff --git a/examples/aggregator/module/rust/src/proto/aggregator.rs b/examples/aggregator/module/rust/src/proto/aggregator.rs deleted file mode 100644 index 98db1ed2b2d..00000000000 --- a/examples/aggregator/module/rust/src/proto/aggregator.rs +++ /dev/null @@ -1,487 +0,0 @@ -// This file is generated by rust-protobuf 2.10.1. Do not edit -// @generated - -// https://github.com/rust-lang/rust-clippy/issues/702 -#![allow(unknown_lints)] -#![allow(clippy::all)] - -#![cfg_attr(rustfmt, rustfmt_skip)] - -#![allow(box_pointers)] -#![allow(dead_code)] -#![allow(missing_docs)] -#![allow(non_camel_case_types)] -#![allow(non_snake_case)] -#![allow(non_upper_case_globals)] -#![allow(trivial_casts)] -#![allow(unsafe_code)] -#![allow(unused_imports)] -#![allow(unused_results)] -//! Generated file from `aggregator.proto` - -use protobuf::Message as Message_imported_for_functions; -use protobuf::ProtobufEnum as ProtobufEnum_imported_for_functions; - -/// Generated files are compatible only with the same version -/// of protobuf runtime. -// const _PROTOBUF_VERSION_CHECK: () = ::protobuf::VERSION_2_10_1; - -#[derive(PartialEq,Clone,Default)] -pub struct SerializedSparseVector { - // message fields - pub indices: ::std::vec::Vec, - pub values: ::std::vec::Vec, - // special fields - pub unknown_fields: ::protobuf::UnknownFields, - pub cached_size: ::protobuf::CachedSize, -} - -impl<'a> ::std::default::Default for &'a SerializedSparseVector { - fn default() -> &'a SerializedSparseVector { - ::default_instance() - } -} - -impl SerializedSparseVector { - pub fn new() -> SerializedSparseVector { - ::std::default::Default::default() - } - - // repeated uint32 indices = 1; - - - pub fn get_indices(&self) -> &[u32] { - &self.indices - } - pub fn clear_indices(&mut self) { - self.indices.clear(); - } - - // Param is passed by value, moved - pub fn set_indices(&mut self, v: ::std::vec::Vec) { - self.indices = v; - } - - // Mutable pointer to the field. - pub fn mut_indices(&mut self) -> &mut ::std::vec::Vec { - &mut self.indices - } - - // Take field - pub fn take_indices(&mut self) -> ::std::vec::Vec { - ::std::mem::replace(&mut self.indices, ::std::vec::Vec::new()) - } - - // repeated float values = 2; - - - pub fn get_values(&self) -> &[f32] { - &self.values - } - pub fn clear_values(&mut self) { - self.values.clear(); - } - - // Param is passed by value, moved - pub fn set_values(&mut self, v: ::std::vec::Vec) { - self.values = v; - } - - // Mutable pointer to the field. - pub fn mut_values(&mut self) -> &mut ::std::vec::Vec { - &mut self.values - } - - // Take field - pub fn take_values(&mut self) -> ::std::vec::Vec { - ::std::mem::replace(&mut self.values, ::std::vec::Vec::new()) - } -} - -impl ::protobuf::Message for SerializedSparseVector { - fn is_initialized(&self) -> bool { - true - } - - fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> { - while !is.eof()? { - let (field_number, wire_type) = is.read_tag_unpack()?; - match field_number { - 1 => { - ::protobuf::rt::read_repeated_uint32_into(wire_type, is, &mut self.indices)?; - }, - 2 => { - ::protobuf::rt::read_repeated_float_into(wire_type, is, &mut self.values)?; - }, - _ => { - ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; - }, - }; - } - ::std::result::Result::Ok(()) - } - - // Compute sizes of nested messages - #[allow(unused_variables)] - fn compute_size(&self) -> u32 { - let mut my_size = 0; - for value in &self.indices { - my_size += ::protobuf::rt::value_size(1, *value, ::protobuf::wire_format::WireTypeVarint); - }; - my_size += 5 * self.values.len() as u32; - my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); - self.cached_size.set(my_size); - my_size - } - - fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { - for v in &self.indices { - os.write_uint32(1, *v)?; - }; - for v in &self.values { - os.write_float(2, *v)?; - }; - os.write_unknown_fields(self.get_unknown_fields())?; - ::std::result::Result::Ok(()) - } - - fn get_cached_size(&self) -> u32 { - self.cached_size.get() - } - - fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { - &self.unknown_fields - } - - fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { - &mut self.unknown_fields - } - - fn as_any(&self) -> &dyn (::std::any::Any) { - self as &dyn (::std::any::Any) - } - fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { - self as &mut dyn (::std::any::Any) - } - fn into_any(self: Box) -> ::std::boxed::Box { - self - } - - fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { - Self::descriptor_static() - } - - fn new() -> SerializedSparseVector { - SerializedSparseVector::new() - } - - fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor { - static mut descriptor: ::protobuf::lazy::Lazy<::protobuf::reflect::MessageDescriptor> = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const ::protobuf::reflect::MessageDescriptor, - }; - unsafe { - descriptor.get(|| { - let mut fields = ::std::vec::Vec::new(); - fields.push(::protobuf::reflect::accessor::make_vec_accessor::<_, ::protobuf::types::ProtobufTypeUint32>( - "indices", - |m: &SerializedSparseVector| { &m.indices }, - |m: &mut SerializedSparseVector| { &mut m.indices }, - )); - fields.push(::protobuf::reflect::accessor::make_vec_accessor::<_, ::protobuf::types::ProtobufTypeFloat>( - "values", - |m: &SerializedSparseVector| { &m.values }, - |m: &mut SerializedSparseVector| { &mut m.values }, - )); - ::protobuf::reflect::MessageDescriptor::new::( - "SerializedSparseVector", - fields, - file_descriptor_proto() - ) - }) - } - } - - fn default_instance() -> &'static SerializedSparseVector { - static mut instance: ::protobuf::lazy::Lazy = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const SerializedSparseVector, - }; - unsafe { - instance.get(SerializedSparseVector::new) - } - } -} - -impl ::protobuf::Clear for SerializedSparseVector { - fn clear(&mut self) { - self.indices.clear(); - self.values.clear(); - self.unknown_fields.clear(); - } -} - -impl ::std::fmt::Debug for SerializedSparseVector { - fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { - ::protobuf::text_format::fmt(self, f) - } -} - -impl ::protobuf::reflect::ProtobufValue for SerializedSparseVector { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { - ::protobuf::reflect::ProtobufValueRef::Message(self) - } -} - -#[derive(PartialEq,Clone,Default)] -pub struct Sample { - // message fields - pub bucket: ::std::string::String, - pub data: ::protobuf::SingularPtrField, - // special fields - pub unknown_fields: ::protobuf::UnknownFields, - pub cached_size: ::protobuf::CachedSize, -} - -impl<'a> ::std::default::Default for &'a Sample { - fn default() -> &'a Sample { - ::default_instance() - } -} - -impl Sample { - pub fn new() -> Sample { - ::std::default::Default::default() - } - - // string bucket = 1; - - - pub fn get_bucket(&self) -> &str { - &self.bucket - } - pub fn clear_bucket(&mut self) { - self.bucket.clear(); - } - - // Param is passed by value, moved - pub fn set_bucket(&mut self, v: ::std::string::String) { - self.bucket = v; - } - - // Mutable pointer to the field. - // If field is not initialized, it is initialized with default value first. - pub fn mut_bucket(&mut self) -> &mut ::std::string::String { - &mut self.bucket - } - - // Take field - pub fn take_bucket(&mut self) -> ::std::string::String { - ::std::mem::replace(&mut self.bucket, ::std::string::String::new()) - } - - // .oak.examples.aggregator.SerializedSparseVector data = 2; - - - pub fn get_data(&self) -> &SerializedSparseVector { - self.data.as_ref().unwrap_or_else(|| SerializedSparseVector::default_instance()) - } - pub fn clear_data(&mut self) { - self.data.clear(); - } - - pub fn has_data(&self) -> bool { - self.data.is_some() - } - - // Param is passed by value, moved - pub fn set_data(&mut self, v: SerializedSparseVector) { - self.data = ::protobuf::SingularPtrField::some(v); - } - - // Mutable pointer to the field. - // If field is not initialized, it is initialized with default value first. - pub fn mut_data(&mut self) -> &mut SerializedSparseVector { - if self.data.is_none() { - self.data.set_default(); - } - self.data.as_mut().unwrap() - } - - // Take field - pub fn take_data(&mut self) -> SerializedSparseVector { - self.data.take().unwrap_or_else(|| SerializedSparseVector::new()) - } -} - -impl ::protobuf::Message for Sample { - fn is_initialized(&self) -> bool { - for v in &self.data { - if !v.is_initialized() { - return false; - } - }; - true - } - - fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> { - while !is.eof()? { - let (field_number, wire_type) = is.read_tag_unpack()?; - match field_number { - 1 => { - ::protobuf::rt::read_singular_proto3_string_into(wire_type, is, &mut self.bucket)?; - }, - 2 => { - ::protobuf::rt::read_singular_message_into(wire_type, is, &mut self.data)?; - }, - _ => { - ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; - }, - }; - } - ::std::result::Result::Ok(()) - } - - // Compute sizes of nested messages - #[allow(unused_variables)] - fn compute_size(&self) -> u32 { - let mut my_size = 0; - if !self.bucket.is_empty() { - my_size += ::protobuf::rt::string_size(1, &self.bucket); - } - if let Some(ref v) = self.data.as_ref() { - let len = v.compute_size(); - my_size += 1 + ::protobuf::rt::compute_raw_varint32_size(len) + len; - } - my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); - self.cached_size.set(my_size); - my_size - } - - fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { - if !self.bucket.is_empty() { - os.write_string(1, &self.bucket)?; - } - if let Some(ref v) = self.data.as_ref() { - os.write_tag(2, ::protobuf::wire_format::WireTypeLengthDelimited)?; - os.write_raw_varint32(v.get_cached_size())?; - v.write_to_with_cached_sizes(os)?; - } - os.write_unknown_fields(self.get_unknown_fields())?; - ::std::result::Result::Ok(()) - } - - fn get_cached_size(&self) -> u32 { - self.cached_size.get() - } - - fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { - &self.unknown_fields - } - - fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { - &mut self.unknown_fields - } - - fn as_any(&self) -> &dyn (::std::any::Any) { - self as &dyn (::std::any::Any) - } - fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { - self as &mut dyn (::std::any::Any) - } - fn into_any(self: Box) -> ::std::boxed::Box { - self - } - - fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { - Self::descriptor_static() - } - - fn new() -> Sample { - Sample::new() - } - - fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor { - static mut descriptor: ::protobuf::lazy::Lazy<::protobuf::reflect::MessageDescriptor> = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const ::protobuf::reflect::MessageDescriptor, - }; - unsafe { - descriptor.get(|| { - let mut fields = ::std::vec::Vec::new(); - fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeString>( - "bucket", - |m: &Sample| { &m.bucket }, - |m: &mut Sample| { &mut m.bucket }, - )); - fields.push(::protobuf::reflect::accessor::make_singular_ptr_field_accessor::<_, ::protobuf::types::ProtobufTypeMessage>( - "data", - |m: &Sample| { &m.data }, - |m: &mut Sample| { &mut m.data }, - )); - ::protobuf::reflect::MessageDescriptor::new::( - "Sample", - fields, - file_descriptor_proto() - ) - }) - } - } - - fn default_instance() -> &'static Sample { - static mut instance: ::protobuf::lazy::Lazy = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const Sample, - }; - unsafe { - instance.get(Sample::new) - } - } -} - -impl ::protobuf::Clear for Sample { - fn clear(&mut self) { - self.bucket.clear(); - self.data.clear(); - self.unknown_fields.clear(); - } -} - -impl ::std::fmt::Debug for Sample { - fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { - ::protobuf::text_format::fmt(self, f) - } -} - -impl ::protobuf::reflect::ProtobufValue for Sample { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { - ::protobuf::reflect::ProtobufValueRef::Message(self) - } -} - -static file_descriptor_proto_data: &'static [u8] = b"\ - \n\x10aggregator.proto\x12\x17oak.examples.aggregator\x1a\x1bgoogle/prot\ - obuf/empty.proto\"J\n\x16SerializedSparseVector\x12\x18\n\x07indices\x18\ - \x01\x20\x03(\rR\x07indices\x12\x16\n\x06values\x18\x02\x20\x03(\x02R\ - \x06values\"e\n\x06Sample\x12\x16\n\x06bucket\x18\x01\x20\x01(\tR\x06buc\ - ket\x12C\n\x04data\x18\x02\x20\x01(\x0b2/.oak.examples.aggregator.Serial\ - izedSparseVectorR\x04data2U\n\nAggregator\x12G\n\x0cSubmitSample\x12\x1f\ - .oak.examples.aggregator.Sample\x1a\x16.google.protobuf.Emptyb\x06proto3\ -"; - -static mut file_descriptor_proto_lazy: ::protobuf::lazy::Lazy<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const ::protobuf::descriptor::FileDescriptorProto, -}; - -fn parse_descriptor_proto() -> ::protobuf::descriptor::FileDescriptorProto { - ::protobuf::parse_from_bytes(file_descriptor_proto_data).unwrap() -} - -pub fn file_descriptor_proto() -> &'static ::protobuf::descriptor::FileDescriptorProto { - unsafe { - file_descriptor_proto_lazy.get(|| { - parse_descriptor_proto() - }) - } -} diff --git a/examples/aggregator/module/rust/src/proto/aggregator_grpc.rs b/examples/aggregator/module/rust/src/proto/aggregator_grpc.rs deleted file mode 100644 index 5051a232cd8..00000000000 --- a/examples/aggregator/module/rust/src/proto/aggregator_grpc.rs +++ /dev/null @@ -1,59 +0,0 @@ -// This file is generated. Do not edit -// @generated - -// https://github.com/rust-lang/rust-clippy/issues/702 -#![allow(unknown_lints)] -#![allow(clippy::all)] - -#![cfg_attr(rustfmt, rustfmt_skip)] - -#![allow(box_pointers)] -#![allow(dead_code)] -#![allow(missing_docs)] -#![allow(non_camel_case_types)] -#![allow(non_snake_case)] -#![allow(non_upper_case_globals)] -#![allow(trivial_casts)] -#![allow(unsafe_code)] -#![allow(unused_imports)] -#![allow(unused_results)] - - -use oak::grpc; -use protobuf::Message; -use std::io::Write; -use log::error; - -// Oak Node server interface -pub trait Aggregator { - fn submit_sample(&mut self, req: super::aggregator::Sample) -> grpc::Result; -} - -// Oak Node gRPC method dispatcher -pub struct Dispatcher(T); - -impl Dispatcher { - pub fn new(node: T) -> Dispatcher { - Dispatcher(node) - } -} - -impl grpc::ServerNode for Dispatcher { - fn invoke(&mut self, method: &str, req: &[u8], writer: grpc::ChannelResponseWriter) { - match method { - "/oak.examples.aggregator.Aggregator/SubmitSample" => grpc::handle_req_rsp(|r| self.0.submit_sample(r), req, writer), - _ => { - error!("unknown method name: {}", method); - } - }; - } -} - -// Client interface -pub struct AggregatorClient(pub oak::grpc::client::Client); - -impl AggregatorClient { - pub fn submit_sample(&self, req: super::aggregator::Sample) -> grpc::Result { - oak::grpc::invoke_grpc_method("/oak.examples.aggregator.Aggregator/SubmitSample", &req, Some("type.googleapis.com/oak.examples.aggregator.Sample"), &self.0.invocation_sender) - } -} diff --git a/examples/aggregator/module/rust/src/proto/mod.rs b/examples/aggregator/module/rust/src/proto/mod.rs deleted file mode 100644 index 92d11ee09d2..00000000000 --- a/examples/aggregator/module/rust/src/proto/mod.rs +++ /dev/null @@ -1,18 +0,0 @@ -// -// Copyright 2019 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. -// - -pub mod aggregator; -pub mod aggregator_grpc; diff --git a/examples/aggregator/module/rust/src/tests.rs b/examples/aggregator/module/rust/src/tests.rs index ceccfd38d88..70e68b9b619 100644 --- a/examples/aggregator/module/rust/src/tests.rs +++ b/examples/aggregator/module/rust/src/tests.rs @@ -15,13 +15,12 @@ // use crate::data::SparseVector; -use crate::proto::aggregator::{Sample, SerializedSparseVector}; +use crate::proto::{Sample, SerializedSparseVector}; use crate::SAMPLE_THRESHOLD; use aggregator_common::Monoid; use assert_matches::assert_matches; use maplit::hashmap; use oak::grpc; -use protobuf::well_known_types::Empty; use std::collections::HashMap; use std::convert::{From, TryFrom}; @@ -33,15 +32,10 @@ fn submit_sample( bucket: &str, indices: Vec, values: Vec, -) -> grpc::Result { +) -> grpc::Result<()> { let req = Sample { bucket: bucket.to_string(), - data: ::protobuf::SingularPtrField::some(SerializedSparseVector { - indices, - values, - ..Default::default() - }), - ..Default::default() + data: Some(SerializedSparseVector { indices, values }), }; oak_tests::grpc_request( &runtime, @@ -130,14 +124,12 @@ fn test_serialize() { SerializedSparseVector { indices: vec![1], values: vec![10.0], - ..Default::default() } ); assert_eq!( SparseVector::try_from(&SerializedSparseVector { indices: vec![1, 2], values: vec![10.0, 20.0], - ..Default::default() }), Ok(SparseVector::new(hashmap! {1 => 10.0, 2 => 20.0})) ); @@ -145,7 +137,6 @@ fn test_serialize() { SparseVector::try_from(&SerializedSparseVector { indices: vec![1, 1], // Duplicated indices are not allowed. values: vec![10.0, 20.0], - ..Default::default() }), Err(_) ); @@ -153,7 +144,6 @@ fn test_serialize() { SparseVector::try_from(&SerializedSparseVector { indices: vec![1], values: vec![10.0, 20.0], - ..Default::default() }), Err(_) ); @@ -161,7 +151,6 @@ fn test_serialize() { SparseVector::try_from(&SerializedSparseVector { indices: vec![1, 2], values: vec![10.0], - ..Default::default() }), Err(_) ); diff --git a/examples/chat/module/rust/Cargo.toml b/examples/chat/module/rust/Cargo.toml index 765fa92ceb9..07e3277de77 100644 --- a/examples/chat/module/rust/Cargo.toml +++ b/examples/chat/module/rust/Cargo.toml @@ -11,11 +11,10 @@ crate-type = ["cdylib"] bincode = "*" log = "*" oak = "=0.1.0" -protobuf = "*" +prost = "*" rand_core = "*" rand = "*" serde = { version = "*", features = ["derive"] } [build-dependencies] oak_utils = "*" -protoc-rust-grpc = { path = "../../../../third_party/grpc-rust/protoc-rust-grpc" } diff --git a/examples/chat/module/rust/build.rs b/examples/chat/module/rust/build.rs index 5819008087f..9a0135101a8 100644 --- a/examples/chat/module/rust/build.rs +++ b/examples/chat/module/rust/build.rs @@ -15,12 +15,8 @@ // fn main() { - oak_utils::run_protoc_rust_grpc(protoc_rust_grpc::Args { - out_dir: "src/proto", - input: &["../../proto/chat.proto"], - includes: &["../../proto", "../../third_party"], - rust_protobuf: true, // also generate protobuf messages, not just services - ..Default::default() - }) - .expect("protoc-rust-grpc"); + oak_utils::compile_protos( + &["../../proto/chat.proto"], + &["../../proto", "../../third_party"], + ); } diff --git a/examples/chat/module/rust/src/backend.rs b/examples/chat/module/rust/src/backend.rs index 42715555ec7..3517ee28ef2 100644 --- a/examples/chat/module/rust/src/backend.rs +++ b/examples/chat/module/rust/src/backend.rs @@ -15,9 +15,10 @@ // use crate::command::Command; -use crate::proto::chat::Message; +use crate::proto::Message; use log::info; use oak::Node; +use prost::Message as _; oak::entrypoint!(backend_oak_main => { oak::logger::init_default(); @@ -40,7 +41,7 @@ impl Node for Room { Ok(()) } Command::SendMessage(message_bytes) => { - let message: Message = protobuf::parse_from_bytes(&message_bytes) + let message = Message::decode(message_bytes.as_slice()) .expect("could not parse message from bytes"); self.messages.push(message.clone()); info!("fan out message to {} clients", self.clients.len()); diff --git a/examples/chat/module/rust/src/lib.rs b/examples/chat/module/rust/src/lib.rs index eb531ae983d..0c19c0cc676 100644 --- a/examples/chat/module/rust/src/lib.rs +++ b/examples/chat/module/rust/src/lib.rs @@ -17,16 +17,19 @@ use command::Command; use log::info; use oak::grpc; -use proto::chat::{CreateRoomRequest, DestroyRoomRequest, SendMessageRequest, SubscribeRequest}; -use proto::chat_grpc::{Chat, Dispatcher}; -use protobuf::well_known_types::Empty; -use protobuf::Message; +use prost::Message; +use proto::{ + Chat, ChatDispatcher, CreateRoomRequest, DestroyRoomRequest, SendMessageRequest, + SubscribeRequest, +}; use std::collections::hash_map::Entry; use std::collections::HashMap; mod backend; mod command; -mod proto; +mod proto { + include!(concat!(env!("OUT_DIR"), "/oak.examples.chat.rs")); +} type RoomId = Vec; type AdminToken = Vec; @@ -38,7 +41,7 @@ struct Node { oak::entrypoint!(oak_main => { oak::logger::init_default(); - Dispatcher::new(Node::default()) + ChatDispatcher::new(Node::default()) }); struct Room { @@ -59,18 +62,18 @@ impl Room { } fn room_id_not_found_err() -> grpc::Result { - Err(grpc::build_status(grpc::Code::NOT_FOUND, "room not found")) + Err(grpc::build_status(grpc::Code::NotFound, "room not found")) } fn room_id_duplicate_err() -> grpc::Result { Err(grpc::build_status( - grpc::Code::ALREADY_EXISTS, + grpc::Code::AlreadyExists, "room already exists", )) } impl Chat for Node { - fn create_room(&mut self, req: CreateRoomRequest) -> grpc::Result { + fn create_room(&mut self, req: CreateRoomRequest) -> grpc::Result<()> { info!("creating room"); if self.rooms.contains_key(&req.room_id) { return room_id_duplicate_err(); @@ -80,10 +83,10 @@ impl Chat for Node { // map. self.rooms.insert(req.room_id, Room::new(req.admin_token)); - Ok(Empty::new()) + Ok(()) } - fn destroy_room(&mut self, req: DestroyRoomRequest) -> grpc::Result { + fn destroy_room(&mut self, req: DestroyRoomRequest) -> grpc::Result<()> { info!("destroying room"); match self.rooms.entry(req.room_id) { Entry::Occupied(e) => { @@ -92,10 +95,10 @@ impl Chat for Node { // will trigger it to terminate. e.get().sender.close().expect("could not close channel"); e.remove(); - Ok(Empty::new()) + Ok(()) } else { Err(grpc::build_status( - grpc::Code::PERMISSION_DENIED, + grpc::Code::PermissionDenied, "invalid admin token", )) } @@ -122,21 +125,22 @@ impl Chat for Node { }; } - fn send_message(&mut self, req: SendMessageRequest) -> grpc::Result { + fn send_message(&mut self, req: SendMessageRequest) -> grpc::Result<()> { info!("sending message to room"); match self.rooms.get(&req.room_id) { None => room_id_not_found_err(), Some(room) => { info!("new message to room {:?}", req.room_id); - let message_bytes = req - .get_message() - .write_to_bytes() + let mut message_bytes = Vec::new(); + req.message + .unwrap_or_default() + .encode(&mut message_bytes) .expect("could not convert message to bytes"); let command = Command::SendMessage(message_bytes); room.sender .send(&command) .expect("could not send command to room Node"); - Ok(Empty::new()) + Ok(()) } } } diff --git a/examples/chat/module/rust/src/proto/chat.rs b/examples/chat/module/rust/src/proto/chat.rs deleted file mode 100644 index c0b085f7d17..00000000000 --- a/examples/chat/module/rust/src/proto/chat.rs +++ /dev/null @@ -1,1091 +0,0 @@ -// This file is generated by rust-protobuf 2.10.1. Do not edit -// @generated - -// https://github.com/rust-lang/rust-clippy/issues/702 -#![allow(unknown_lints)] -#![allow(clippy::all)] - -#![cfg_attr(rustfmt, rustfmt_skip)] - -#![allow(box_pointers)] -#![allow(dead_code)] -#![allow(missing_docs)] -#![allow(non_camel_case_types)] -#![allow(non_snake_case)] -#![allow(non_upper_case_globals)] -#![allow(trivial_casts)] -#![allow(unsafe_code)] -#![allow(unused_imports)] -#![allow(unused_results)] -//! Generated file from `chat.proto` - -use protobuf::Message as Message_imported_for_functions; -use protobuf::ProtobufEnum as ProtobufEnum_imported_for_functions; - -/// Generated files are compatible only with the same version -/// of protobuf runtime. -// const _PROTOBUF_VERSION_CHECK: () = ::protobuf::VERSION_2_10_1; - -#[derive(PartialEq,Clone,Default)] -pub struct CreateRoomRequest { - // message fields - pub room_id: ::std::vec::Vec, - pub admin_token: ::std::vec::Vec, - // special fields - pub unknown_fields: ::protobuf::UnknownFields, - pub cached_size: ::protobuf::CachedSize, -} - -impl<'a> ::std::default::Default for &'a CreateRoomRequest { - fn default() -> &'a CreateRoomRequest { - ::default_instance() - } -} - -impl CreateRoomRequest { - pub fn new() -> CreateRoomRequest { - ::std::default::Default::default() - } - - // bytes room_id = 1; - - - pub fn get_room_id(&self) -> &[u8] { - &self.room_id - } - pub fn clear_room_id(&mut self) { - self.room_id.clear(); - } - - // Param is passed by value, moved - pub fn set_room_id(&mut self, v: ::std::vec::Vec) { - self.room_id = v; - } - - // Mutable pointer to the field. - // If field is not initialized, it is initialized with default value first. - pub fn mut_room_id(&mut self) -> &mut ::std::vec::Vec { - &mut self.room_id - } - - // Take field - pub fn take_room_id(&mut self) -> ::std::vec::Vec { - ::std::mem::replace(&mut self.room_id, ::std::vec::Vec::new()) - } - - // bytes admin_token = 2; - - - pub fn get_admin_token(&self) -> &[u8] { - &self.admin_token - } - pub fn clear_admin_token(&mut self) { - self.admin_token.clear(); - } - - // Param is passed by value, moved - pub fn set_admin_token(&mut self, v: ::std::vec::Vec) { - self.admin_token = v; - } - - // Mutable pointer to the field. - // If field is not initialized, it is initialized with default value first. - pub fn mut_admin_token(&mut self) -> &mut ::std::vec::Vec { - &mut self.admin_token - } - - // Take field - pub fn take_admin_token(&mut self) -> ::std::vec::Vec { - ::std::mem::replace(&mut self.admin_token, ::std::vec::Vec::new()) - } -} - -impl ::protobuf::Message for CreateRoomRequest { - fn is_initialized(&self) -> bool { - true - } - - fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> { - while !is.eof()? { - let (field_number, wire_type) = is.read_tag_unpack()?; - match field_number { - 1 => { - ::protobuf::rt::read_singular_proto3_bytes_into(wire_type, is, &mut self.room_id)?; - }, - 2 => { - ::protobuf::rt::read_singular_proto3_bytes_into(wire_type, is, &mut self.admin_token)?; - }, - _ => { - ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; - }, - }; - } - ::std::result::Result::Ok(()) - } - - // Compute sizes of nested messages - #[allow(unused_variables)] - fn compute_size(&self) -> u32 { - let mut my_size = 0; - if !self.room_id.is_empty() { - my_size += ::protobuf::rt::bytes_size(1, &self.room_id); - } - if !self.admin_token.is_empty() { - my_size += ::protobuf::rt::bytes_size(2, &self.admin_token); - } - my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); - self.cached_size.set(my_size); - my_size - } - - fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { - if !self.room_id.is_empty() { - os.write_bytes(1, &self.room_id)?; - } - if !self.admin_token.is_empty() { - os.write_bytes(2, &self.admin_token)?; - } - os.write_unknown_fields(self.get_unknown_fields())?; - ::std::result::Result::Ok(()) - } - - fn get_cached_size(&self) -> u32 { - self.cached_size.get() - } - - fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { - &self.unknown_fields - } - - fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { - &mut self.unknown_fields - } - - fn as_any(&self) -> &dyn (::std::any::Any) { - self as &dyn (::std::any::Any) - } - fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { - self as &mut dyn (::std::any::Any) - } - fn into_any(self: Box) -> ::std::boxed::Box { - self - } - - fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { - Self::descriptor_static() - } - - fn new() -> CreateRoomRequest { - CreateRoomRequest::new() - } - - fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor { - static mut descriptor: ::protobuf::lazy::Lazy<::protobuf::reflect::MessageDescriptor> = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const ::protobuf::reflect::MessageDescriptor, - }; - unsafe { - descriptor.get(|| { - let mut fields = ::std::vec::Vec::new(); - fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeBytes>( - "room_id", - |m: &CreateRoomRequest| { &m.room_id }, - |m: &mut CreateRoomRequest| { &mut m.room_id }, - )); - fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeBytes>( - "admin_token", - |m: &CreateRoomRequest| { &m.admin_token }, - |m: &mut CreateRoomRequest| { &mut m.admin_token }, - )); - ::protobuf::reflect::MessageDescriptor::new::( - "CreateRoomRequest", - fields, - file_descriptor_proto() - ) - }) - } - } - - fn default_instance() -> &'static CreateRoomRequest { - static mut instance: ::protobuf::lazy::Lazy = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const CreateRoomRequest, - }; - unsafe { - instance.get(CreateRoomRequest::new) - } - } -} - -impl ::protobuf::Clear for CreateRoomRequest { - fn clear(&mut self) { - self.room_id.clear(); - self.admin_token.clear(); - self.unknown_fields.clear(); - } -} - -impl ::std::fmt::Debug for CreateRoomRequest { - fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { - ::protobuf::text_format::fmt(self, f) - } -} - -impl ::protobuf::reflect::ProtobufValue for CreateRoomRequest { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { - ::protobuf::reflect::ProtobufValueRef::Message(self) - } -} - -#[derive(PartialEq,Clone,Default)] -pub struct DestroyRoomRequest { - // message fields - pub room_id: ::std::vec::Vec, - pub admin_token: ::std::vec::Vec, - // special fields - pub unknown_fields: ::protobuf::UnknownFields, - pub cached_size: ::protobuf::CachedSize, -} - -impl<'a> ::std::default::Default for &'a DestroyRoomRequest { - fn default() -> &'a DestroyRoomRequest { - ::default_instance() - } -} - -impl DestroyRoomRequest { - pub fn new() -> DestroyRoomRequest { - ::std::default::Default::default() - } - - // bytes room_id = 1; - - - pub fn get_room_id(&self) -> &[u8] { - &self.room_id - } - pub fn clear_room_id(&mut self) { - self.room_id.clear(); - } - - // Param is passed by value, moved - pub fn set_room_id(&mut self, v: ::std::vec::Vec) { - self.room_id = v; - } - - // Mutable pointer to the field. - // If field is not initialized, it is initialized with default value first. - pub fn mut_room_id(&mut self) -> &mut ::std::vec::Vec { - &mut self.room_id - } - - // Take field - pub fn take_room_id(&mut self) -> ::std::vec::Vec { - ::std::mem::replace(&mut self.room_id, ::std::vec::Vec::new()) - } - - // bytes admin_token = 2; - - - pub fn get_admin_token(&self) -> &[u8] { - &self.admin_token - } - pub fn clear_admin_token(&mut self) { - self.admin_token.clear(); - } - - // Param is passed by value, moved - pub fn set_admin_token(&mut self, v: ::std::vec::Vec) { - self.admin_token = v; - } - - // Mutable pointer to the field. - // If field is not initialized, it is initialized with default value first. - pub fn mut_admin_token(&mut self) -> &mut ::std::vec::Vec { - &mut self.admin_token - } - - // Take field - pub fn take_admin_token(&mut self) -> ::std::vec::Vec { - ::std::mem::replace(&mut self.admin_token, ::std::vec::Vec::new()) - } -} - -impl ::protobuf::Message for DestroyRoomRequest { - fn is_initialized(&self) -> bool { - true - } - - fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> { - while !is.eof()? { - let (field_number, wire_type) = is.read_tag_unpack()?; - match field_number { - 1 => { - ::protobuf::rt::read_singular_proto3_bytes_into(wire_type, is, &mut self.room_id)?; - }, - 2 => { - ::protobuf::rt::read_singular_proto3_bytes_into(wire_type, is, &mut self.admin_token)?; - }, - _ => { - ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; - }, - }; - } - ::std::result::Result::Ok(()) - } - - // Compute sizes of nested messages - #[allow(unused_variables)] - fn compute_size(&self) -> u32 { - let mut my_size = 0; - if !self.room_id.is_empty() { - my_size += ::protobuf::rt::bytes_size(1, &self.room_id); - } - if !self.admin_token.is_empty() { - my_size += ::protobuf::rt::bytes_size(2, &self.admin_token); - } - my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); - self.cached_size.set(my_size); - my_size - } - - fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { - if !self.room_id.is_empty() { - os.write_bytes(1, &self.room_id)?; - } - if !self.admin_token.is_empty() { - os.write_bytes(2, &self.admin_token)?; - } - os.write_unknown_fields(self.get_unknown_fields())?; - ::std::result::Result::Ok(()) - } - - fn get_cached_size(&self) -> u32 { - self.cached_size.get() - } - - fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { - &self.unknown_fields - } - - fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { - &mut self.unknown_fields - } - - fn as_any(&self) -> &dyn (::std::any::Any) { - self as &dyn (::std::any::Any) - } - fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { - self as &mut dyn (::std::any::Any) - } - fn into_any(self: Box) -> ::std::boxed::Box { - self - } - - fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { - Self::descriptor_static() - } - - fn new() -> DestroyRoomRequest { - DestroyRoomRequest::new() - } - - fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor { - static mut descriptor: ::protobuf::lazy::Lazy<::protobuf::reflect::MessageDescriptor> = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const ::protobuf::reflect::MessageDescriptor, - }; - unsafe { - descriptor.get(|| { - let mut fields = ::std::vec::Vec::new(); - fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeBytes>( - "room_id", - |m: &DestroyRoomRequest| { &m.room_id }, - |m: &mut DestroyRoomRequest| { &mut m.room_id }, - )); - fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeBytes>( - "admin_token", - |m: &DestroyRoomRequest| { &m.admin_token }, - |m: &mut DestroyRoomRequest| { &mut m.admin_token }, - )); - ::protobuf::reflect::MessageDescriptor::new::( - "DestroyRoomRequest", - fields, - file_descriptor_proto() - ) - }) - } - } - - fn default_instance() -> &'static DestroyRoomRequest { - static mut instance: ::protobuf::lazy::Lazy = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const DestroyRoomRequest, - }; - unsafe { - instance.get(DestroyRoomRequest::new) - } - } -} - -impl ::protobuf::Clear for DestroyRoomRequest { - fn clear(&mut self) { - self.room_id.clear(); - self.admin_token.clear(); - self.unknown_fields.clear(); - } -} - -impl ::std::fmt::Debug for DestroyRoomRequest { - fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { - ::protobuf::text_format::fmt(self, f) - } -} - -impl ::protobuf::reflect::ProtobufValue for DestroyRoomRequest { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { - ::protobuf::reflect::ProtobufValueRef::Message(self) - } -} - -#[derive(PartialEq,Clone,Default)] -pub struct SubscribeRequest { - // message fields - pub room_id: ::std::vec::Vec, - // special fields - pub unknown_fields: ::protobuf::UnknownFields, - pub cached_size: ::protobuf::CachedSize, -} - -impl<'a> ::std::default::Default for &'a SubscribeRequest { - fn default() -> &'a SubscribeRequest { - ::default_instance() - } -} - -impl SubscribeRequest { - pub fn new() -> SubscribeRequest { - ::std::default::Default::default() - } - - // bytes room_id = 1; - - - pub fn get_room_id(&self) -> &[u8] { - &self.room_id - } - pub fn clear_room_id(&mut self) { - self.room_id.clear(); - } - - // Param is passed by value, moved - pub fn set_room_id(&mut self, v: ::std::vec::Vec) { - self.room_id = v; - } - - // Mutable pointer to the field. - // If field is not initialized, it is initialized with default value first. - pub fn mut_room_id(&mut self) -> &mut ::std::vec::Vec { - &mut self.room_id - } - - // Take field - pub fn take_room_id(&mut self) -> ::std::vec::Vec { - ::std::mem::replace(&mut self.room_id, ::std::vec::Vec::new()) - } -} - -impl ::protobuf::Message for SubscribeRequest { - fn is_initialized(&self) -> bool { - true - } - - fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> { - while !is.eof()? { - let (field_number, wire_type) = is.read_tag_unpack()?; - match field_number { - 1 => { - ::protobuf::rt::read_singular_proto3_bytes_into(wire_type, is, &mut self.room_id)?; - }, - _ => { - ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; - }, - }; - } - ::std::result::Result::Ok(()) - } - - // Compute sizes of nested messages - #[allow(unused_variables)] - fn compute_size(&self) -> u32 { - let mut my_size = 0; - if !self.room_id.is_empty() { - my_size += ::protobuf::rt::bytes_size(1, &self.room_id); - } - my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); - self.cached_size.set(my_size); - my_size - } - - fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { - if !self.room_id.is_empty() { - os.write_bytes(1, &self.room_id)?; - } - os.write_unknown_fields(self.get_unknown_fields())?; - ::std::result::Result::Ok(()) - } - - fn get_cached_size(&self) -> u32 { - self.cached_size.get() - } - - fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { - &self.unknown_fields - } - - fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { - &mut self.unknown_fields - } - - fn as_any(&self) -> &dyn (::std::any::Any) { - self as &dyn (::std::any::Any) - } - fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { - self as &mut dyn (::std::any::Any) - } - fn into_any(self: Box) -> ::std::boxed::Box { - self - } - - fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { - Self::descriptor_static() - } - - fn new() -> SubscribeRequest { - SubscribeRequest::new() - } - - fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor { - static mut descriptor: ::protobuf::lazy::Lazy<::protobuf::reflect::MessageDescriptor> = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const ::protobuf::reflect::MessageDescriptor, - }; - unsafe { - descriptor.get(|| { - let mut fields = ::std::vec::Vec::new(); - fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeBytes>( - "room_id", - |m: &SubscribeRequest| { &m.room_id }, - |m: &mut SubscribeRequest| { &mut m.room_id }, - )); - ::protobuf::reflect::MessageDescriptor::new::( - "SubscribeRequest", - fields, - file_descriptor_proto() - ) - }) - } - } - - fn default_instance() -> &'static SubscribeRequest { - static mut instance: ::protobuf::lazy::Lazy = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const SubscribeRequest, - }; - unsafe { - instance.get(SubscribeRequest::new) - } - } -} - -impl ::protobuf::Clear for SubscribeRequest { - fn clear(&mut self) { - self.room_id.clear(); - self.unknown_fields.clear(); - } -} - -impl ::std::fmt::Debug for SubscribeRequest { - fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { - ::protobuf::text_format::fmt(self, f) - } -} - -impl ::protobuf::reflect::ProtobufValue for SubscribeRequest { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { - ::protobuf::reflect::ProtobufValueRef::Message(self) - } -} - -#[derive(PartialEq,Clone,Default)] -pub struct Message { - // message fields - pub user_handle: ::std::string::String, - pub text: ::std::string::String, - // special fields - pub unknown_fields: ::protobuf::UnknownFields, - pub cached_size: ::protobuf::CachedSize, -} - -impl<'a> ::std::default::Default for &'a Message { - fn default() -> &'a Message { - ::default_instance() - } -} - -impl Message { - pub fn new() -> Message { - ::std::default::Default::default() - } - - // string user_handle = 2; - - - pub fn get_user_handle(&self) -> &str { - &self.user_handle - } - pub fn clear_user_handle(&mut self) { - self.user_handle.clear(); - } - - // Param is passed by value, moved - pub fn set_user_handle(&mut self, v: ::std::string::String) { - self.user_handle = v; - } - - // Mutable pointer to the field. - // If field is not initialized, it is initialized with default value first. - pub fn mut_user_handle(&mut self) -> &mut ::std::string::String { - &mut self.user_handle - } - - // Take field - pub fn take_user_handle(&mut self) -> ::std::string::String { - ::std::mem::replace(&mut self.user_handle, ::std::string::String::new()) - } - - // string text = 1; - - - pub fn get_text(&self) -> &str { - &self.text - } - pub fn clear_text(&mut self) { - self.text.clear(); - } - - // Param is passed by value, moved - pub fn set_text(&mut self, v: ::std::string::String) { - self.text = v; - } - - // Mutable pointer to the field. - // If field is not initialized, it is initialized with default value first. - pub fn mut_text(&mut self) -> &mut ::std::string::String { - &mut self.text - } - - // Take field - pub fn take_text(&mut self) -> ::std::string::String { - ::std::mem::replace(&mut self.text, ::std::string::String::new()) - } -} - -impl ::protobuf::Message for Message { - fn is_initialized(&self) -> bool { - true - } - - fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> { - while !is.eof()? { - let (field_number, wire_type) = is.read_tag_unpack()?; - match field_number { - 2 => { - ::protobuf::rt::read_singular_proto3_string_into(wire_type, is, &mut self.user_handle)?; - }, - 1 => { - ::protobuf::rt::read_singular_proto3_string_into(wire_type, is, &mut self.text)?; - }, - _ => { - ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; - }, - }; - } - ::std::result::Result::Ok(()) - } - - // Compute sizes of nested messages - #[allow(unused_variables)] - fn compute_size(&self) -> u32 { - let mut my_size = 0; - if !self.user_handle.is_empty() { - my_size += ::protobuf::rt::string_size(2, &self.user_handle); - } - if !self.text.is_empty() { - my_size += ::protobuf::rt::string_size(1, &self.text); - } - my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); - self.cached_size.set(my_size); - my_size - } - - fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { - if !self.user_handle.is_empty() { - os.write_string(2, &self.user_handle)?; - } - if !self.text.is_empty() { - os.write_string(1, &self.text)?; - } - os.write_unknown_fields(self.get_unknown_fields())?; - ::std::result::Result::Ok(()) - } - - fn get_cached_size(&self) -> u32 { - self.cached_size.get() - } - - fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { - &self.unknown_fields - } - - fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { - &mut self.unknown_fields - } - - fn as_any(&self) -> &dyn (::std::any::Any) { - self as &dyn (::std::any::Any) - } - fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { - self as &mut dyn (::std::any::Any) - } - fn into_any(self: Box) -> ::std::boxed::Box { - self - } - - fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { - Self::descriptor_static() - } - - fn new() -> Message { - Message::new() - } - - fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor { - static mut descriptor: ::protobuf::lazy::Lazy<::protobuf::reflect::MessageDescriptor> = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const ::protobuf::reflect::MessageDescriptor, - }; - unsafe { - descriptor.get(|| { - let mut fields = ::std::vec::Vec::new(); - fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeString>( - "user_handle", - |m: &Message| { &m.user_handle }, - |m: &mut Message| { &mut m.user_handle }, - )); - fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeString>( - "text", - |m: &Message| { &m.text }, - |m: &mut Message| { &mut m.text }, - )); - ::protobuf::reflect::MessageDescriptor::new::( - "Message", - fields, - file_descriptor_proto() - ) - }) - } - } - - fn default_instance() -> &'static Message { - static mut instance: ::protobuf::lazy::Lazy = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const Message, - }; - unsafe { - instance.get(Message::new) - } - } -} - -impl ::protobuf::Clear for Message { - fn clear(&mut self) { - self.user_handle.clear(); - self.text.clear(); - self.unknown_fields.clear(); - } -} - -impl ::std::fmt::Debug for Message { - fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { - ::protobuf::text_format::fmt(self, f) - } -} - -impl ::protobuf::reflect::ProtobufValue for Message { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { - ::protobuf::reflect::ProtobufValueRef::Message(self) - } -} - -#[derive(PartialEq,Clone,Default)] -pub struct SendMessageRequest { - // message fields - pub room_id: ::std::vec::Vec, - pub message: ::protobuf::SingularPtrField, - // special fields - pub unknown_fields: ::protobuf::UnknownFields, - pub cached_size: ::protobuf::CachedSize, -} - -impl<'a> ::std::default::Default for &'a SendMessageRequest { - fn default() -> &'a SendMessageRequest { - ::default_instance() - } -} - -impl SendMessageRequest { - pub fn new() -> SendMessageRequest { - ::std::default::Default::default() - } - - // bytes room_id = 1; - - - pub fn get_room_id(&self) -> &[u8] { - &self.room_id - } - pub fn clear_room_id(&mut self) { - self.room_id.clear(); - } - - // Param is passed by value, moved - pub fn set_room_id(&mut self, v: ::std::vec::Vec) { - self.room_id = v; - } - - // Mutable pointer to the field. - // If field is not initialized, it is initialized with default value first. - pub fn mut_room_id(&mut self) -> &mut ::std::vec::Vec { - &mut self.room_id - } - - // Take field - pub fn take_room_id(&mut self) -> ::std::vec::Vec { - ::std::mem::replace(&mut self.room_id, ::std::vec::Vec::new()) - } - - // .oak.examples.chat.Message message = 3; - - - pub fn get_message(&self) -> &Message { - self.message.as_ref().unwrap_or_else(|| Message::default_instance()) - } - pub fn clear_message(&mut self) { - self.message.clear(); - } - - pub fn has_message(&self) -> bool { - self.message.is_some() - } - - // Param is passed by value, moved - pub fn set_message(&mut self, v: Message) { - self.message = ::protobuf::SingularPtrField::some(v); - } - - // Mutable pointer to the field. - // If field is not initialized, it is initialized with default value first. - pub fn mut_message(&mut self) -> &mut Message { - if self.message.is_none() { - self.message.set_default(); - } - self.message.as_mut().unwrap() - } - - // Take field - pub fn take_message(&mut self) -> Message { - self.message.take().unwrap_or_else(|| Message::new()) - } -} - -impl ::protobuf::Message for SendMessageRequest { - fn is_initialized(&self) -> bool { - for v in &self.message { - if !v.is_initialized() { - return false; - } - }; - true - } - - fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> { - while !is.eof()? { - let (field_number, wire_type) = is.read_tag_unpack()?; - match field_number { - 1 => { - ::protobuf::rt::read_singular_proto3_bytes_into(wire_type, is, &mut self.room_id)?; - }, - 3 => { - ::protobuf::rt::read_singular_message_into(wire_type, is, &mut self.message)?; - }, - _ => { - ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; - }, - }; - } - ::std::result::Result::Ok(()) - } - - // Compute sizes of nested messages - #[allow(unused_variables)] - fn compute_size(&self) -> u32 { - let mut my_size = 0; - if !self.room_id.is_empty() { - my_size += ::protobuf::rt::bytes_size(1, &self.room_id); - } - if let Some(ref v) = self.message.as_ref() { - let len = v.compute_size(); - my_size += 1 + ::protobuf::rt::compute_raw_varint32_size(len) + len; - } - my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); - self.cached_size.set(my_size); - my_size - } - - fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { - if !self.room_id.is_empty() { - os.write_bytes(1, &self.room_id)?; - } - if let Some(ref v) = self.message.as_ref() { - os.write_tag(3, ::protobuf::wire_format::WireTypeLengthDelimited)?; - os.write_raw_varint32(v.get_cached_size())?; - v.write_to_with_cached_sizes(os)?; - } - os.write_unknown_fields(self.get_unknown_fields())?; - ::std::result::Result::Ok(()) - } - - fn get_cached_size(&self) -> u32 { - self.cached_size.get() - } - - fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { - &self.unknown_fields - } - - fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { - &mut self.unknown_fields - } - - fn as_any(&self) -> &dyn (::std::any::Any) { - self as &dyn (::std::any::Any) - } - fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { - self as &mut dyn (::std::any::Any) - } - fn into_any(self: Box) -> ::std::boxed::Box { - self - } - - fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { - Self::descriptor_static() - } - - fn new() -> SendMessageRequest { - SendMessageRequest::new() - } - - fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor { - static mut descriptor: ::protobuf::lazy::Lazy<::protobuf::reflect::MessageDescriptor> = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const ::protobuf::reflect::MessageDescriptor, - }; - unsafe { - descriptor.get(|| { - let mut fields = ::std::vec::Vec::new(); - fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeBytes>( - "room_id", - |m: &SendMessageRequest| { &m.room_id }, - |m: &mut SendMessageRequest| { &mut m.room_id }, - )); - fields.push(::protobuf::reflect::accessor::make_singular_ptr_field_accessor::<_, ::protobuf::types::ProtobufTypeMessage>( - "message", - |m: &SendMessageRequest| { &m.message }, - |m: &mut SendMessageRequest| { &mut m.message }, - )); - ::protobuf::reflect::MessageDescriptor::new::( - "SendMessageRequest", - fields, - file_descriptor_proto() - ) - }) - } - } - - fn default_instance() -> &'static SendMessageRequest { - static mut instance: ::protobuf::lazy::Lazy = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const SendMessageRequest, - }; - unsafe { - instance.get(SendMessageRequest::new) - } - } -} - -impl ::protobuf::Clear for SendMessageRequest { - fn clear(&mut self) { - self.room_id.clear(); - self.message.clear(); - self.unknown_fields.clear(); - } -} - -impl ::std::fmt::Debug for SendMessageRequest { - fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { - ::protobuf::text_format::fmt(self, f) - } -} - -impl ::protobuf::reflect::ProtobufValue for SendMessageRequest { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { - ::protobuf::reflect::ProtobufValueRef::Message(self) - } -} - -static file_descriptor_proto_data: &'static [u8] = b"\ - \n\nchat.proto\x12\x11oak.examples.chat\x1a\x1bgoogle/protobuf/empty.pro\ - to\"M\n\x11CreateRoomRequest\x12\x17\n\x07room_id\x18\x01\x20\x01(\x0cR\ - \x06roomId\x12\x1f\n\x0badmin_token\x18\x02\x20\x01(\x0cR\nadminToken\"N\ - \n\x12DestroyRoomRequest\x12\x17\n\x07room_id\x18\x01\x20\x01(\x0cR\x06r\ - oomId\x12\x1f\n\x0badmin_token\x18\x02\x20\x01(\x0cR\nadminToken\"+\n\ - \x10SubscribeRequest\x12\x17\n\x07room_id\x18\x01\x20\x01(\x0cR\x06roomI\ - d\">\n\x07Message\x12\x1f\n\x0buser_handle\x18\x02\x20\x01(\tR\nuserHand\ - le\x12\x12\n\x04text\x18\x01\x20\x01(\tR\x04text\"c\n\x12SendMessageRequ\ - est\x12\x17\n\x07room_id\x18\x01\x20\x01(\x0cR\x06roomId\x124\n\x07messa\ - ge\x18\x03\x20\x01(\x0b2\x1a.oak.examples.chat.MessageR\x07message2\xbe\ - \x02\n\x04Chat\x12J\n\nCreateRoom\x12$.oak.examples.chat.CreateRoomReque\ - st\x1a\x16.google.protobuf.Empty\x12L\n\x0bDestroyRoom\x12%.oak.examples\ - .chat.DestroyRoomRequest\x1a\x16.google.protobuf.Empty\x12N\n\tSubscribe\ - \x12#.oak.examples.chat.SubscribeRequest\x1a\x1a.oak.examples.chat.Messa\ - ge0\x01\x12L\n\x0bSendMessage\x12%.oak.examples.chat.SendMessageRequest\ - \x1a\x16.google.protobuf.Emptyb\x06proto3\ -"; - -static mut file_descriptor_proto_lazy: ::protobuf::lazy::Lazy<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const ::protobuf::descriptor::FileDescriptorProto, -}; - -fn parse_descriptor_proto() -> ::protobuf::descriptor::FileDescriptorProto { - ::protobuf::parse_from_bytes(file_descriptor_proto_data).unwrap() -} - -pub fn file_descriptor_proto() -> &'static ::protobuf::descriptor::FileDescriptorProto { - unsafe { - file_descriptor_proto_lazy.get(|| { - parse_descriptor_proto() - }) - } -} diff --git a/examples/chat/module/rust/src/proto/chat_grpc.rs b/examples/chat/module/rust/src/proto/chat_grpc.rs deleted file mode 100644 index 3d2c6a14422..00000000000 --- a/examples/chat/module/rust/src/proto/chat_grpc.rs +++ /dev/null @@ -1,74 +0,0 @@ -// This file is generated. Do not edit -// @generated - -// https://github.com/rust-lang/rust-clippy/issues/702 -#![allow(unknown_lints)] -#![allow(clippy::all)] - -#![cfg_attr(rustfmt, rustfmt_skip)] - -#![allow(box_pointers)] -#![allow(dead_code)] -#![allow(missing_docs)] -#![allow(non_camel_case_types)] -#![allow(non_snake_case)] -#![allow(non_upper_case_globals)] -#![allow(trivial_casts)] -#![allow(unsafe_code)] -#![allow(unused_imports)] -#![allow(unused_results)] - - -use oak::grpc; -use protobuf::Message; -use std::io::Write; -use log::error; - -// Oak Node server interface -pub trait Chat { - fn create_room(&mut self, req: super::chat::CreateRoomRequest) -> grpc::Result; - fn destroy_room(&mut self, req: super::chat::DestroyRoomRequest) -> grpc::Result; - fn subscribe(&mut self, req: super::chat::SubscribeRequest, writer: grpc::ChannelResponseWriter); - fn send_message(&mut self, req: super::chat::SendMessageRequest) -> grpc::Result; -} - -// Oak Node gRPC method dispatcher -pub struct Dispatcher(T); - -impl Dispatcher { - pub fn new(node: T) -> Dispatcher { - Dispatcher(node) - } -} - -impl grpc::ServerNode for Dispatcher { - fn invoke(&mut self, method: &str, req: &[u8], writer: grpc::ChannelResponseWriter) { - match method { - "/oak.examples.chat.Chat/CreateRoom" => grpc::handle_req_rsp(|r| self.0.create_room(r), req, writer), - "/oak.examples.chat.Chat/DestroyRoom" => grpc::handle_req_rsp(|r| self.0.destroy_room(r), req, writer), - "/oak.examples.chat.Chat/Subscribe" => grpc::handle_req_stream(|r, w| self.0.subscribe(r, w), req, writer), - "/oak.examples.chat.Chat/SendMessage" => grpc::handle_req_rsp(|r| self.0.send_message(r), req, writer), - _ => { - error!("unknown method name: {}", method); - } - }; - } -} - -// Client interface -pub struct ChatClient(pub oak::grpc::client::Client); - -impl ChatClient { - pub fn create_room(&self, req: super::chat::CreateRoomRequest) -> grpc::Result { - oak::grpc::invoke_grpc_method("/oak.examples.chat.Chat/CreateRoom", &req, Some("type.googleapis.com/oak.examples.chat.CreateRoomRequest"), &self.0.invocation_sender) - } - pub fn destroy_room(&self, req: super::chat::DestroyRoomRequest) -> grpc::Result { - oak::grpc::invoke_grpc_method("/oak.examples.chat.Chat/DestroyRoom", &req, Some("type.googleapis.com/oak.examples.chat.DestroyRoomRequest"), &self.0.invocation_sender) - } - pub fn subscribe(&self, req: super::chat::SubscribeRequest) -> grpc::Result> { - oak::grpc::invoke_grpc_method_stream("/oak.examples.chat.Chat/Subscribe", &req, Some("type.googleapis.com/oak.examples.chat.SubscribeRequest"), &self.0.invocation_sender) - } - pub fn send_message(&self, req: super::chat::SendMessageRequest) -> grpc::Result { - oak::grpc::invoke_grpc_method("/oak.examples.chat.Chat/SendMessage", &req, Some("type.googleapis.com/oak.examples.chat.SendMessageRequest"), &self.0.invocation_sender) - } -} diff --git a/examples/chat/module/rust/src/proto/mod.rs b/examples/chat/module/rust/src/proto/mod.rs deleted file mode 100644 index d5e1635b08c..00000000000 --- a/examples/chat/module/rust/src/proto/mod.rs +++ /dev/null @@ -1,18 +0,0 @@ -// -// Copyright 2019 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. -// - -pub mod chat; -pub mod chat_grpc; diff --git a/examples/hello_world/module/rust/Cargo.toml b/examples/hello_world/module/rust/Cargo.toml index ea623866fe1..ea289360d0d 100644 --- a/examples/hello_world/module/rust/Cargo.toml +++ b/examples/hello_world/module/rust/Cargo.toml @@ -10,7 +10,7 @@ crate-type = ["cdylib"] [dependencies] log = "*" oak = "=0.1.0" -protobuf = "*" +prost = "*" translator_common = "=0.1.0" [dev-dependencies] @@ -21,4 +21,3 @@ simple_logger = "*" [build-dependencies] oak_utils = "*" -protoc-rust-grpc = { path = "../../../../third_party/grpc-rust/protoc-rust-grpc" } diff --git a/examples/hello_world/module/rust/build.rs b/examples/hello_world/module/rust/build.rs index b88493aa336..4ef9d5cc763 100644 --- a/examples/hello_world/module/rust/build.rs +++ b/examples/hello_world/module/rust/build.rs @@ -15,12 +15,8 @@ // fn main() { - oak_utils::run_protoc_rust_grpc(protoc_rust_grpc::Args { - out_dir: "src/proto", - input: &["../../proto/hello_world.proto"], - includes: &["../../proto", "../../../../third_party"], - rust_protobuf: true, // also generate protobuf messages, not just services - ..Default::default() - }) - .expect("protoc-rust-grpc"); + oak_utils::compile_protos( + &["../../proto/hello_world.proto"], + &["../../proto", "../../../../third_party"], + ); } diff --git a/examples/hello_world/module/rust/src/lib.rs b/examples/hello_world/module/rust/src/lib.rs index 3d00bb978f6..ed1d369531b 100644 --- a/examples/hello_world/module/rust/src/lib.rs +++ b/examples/hello_world/module/rust/src/lib.rs @@ -14,14 +14,15 @@ // limitations under the License. // -mod proto; +mod proto { + include!(concat!(env!("OUT_DIR"), "/oak.examples.hello_world.rs")); +} #[cfg(test)] mod tests; use log::info; use oak::grpc; -use proto::hello_world::{HelloRequest, HelloResponse}; -use proto::hello_world_grpc::{Dispatcher, HelloWorld}; +use proto::{HelloRequest, HelloResponse, HelloWorld, HelloWorldDispatcher}; oak::entrypoint!(oak_main => { oak::logger::init_default(); @@ -29,7 +30,7 @@ oak::entrypoint!(oak_main => { translator: grpc::client::Client::new("translator", "oak_main") .map(translator_common::TranslatorClient), }; - Dispatcher::new(node) + HelloWorldDispatcher::new(node) }); struct Node { @@ -46,14 +47,14 @@ impl Node { impl HelloWorld for Node { fn say_hello(&mut self, req: HelloRequest) -> grpc::Result { info!("Say hello to {}", req.greeting); - let mut res = HelloResponse::new(); + let mut res = HelloResponse::default(); res.reply = format!("HELLO {}!", req.greeting); Ok(res) } fn lots_of_replies(&mut self, req: HelloRequest, mut writer: grpc::ChannelResponseWriter) { info!("Say hello to {}", req.greeting); - let mut res1 = HelloResponse::new(); + let mut res1 = HelloResponse::default(); res1.reply = format!("HELLO {}!", req.greeting); writer .write(&res1, grpc::WriteMode::KeepOpen) @@ -62,7 +63,7 @@ impl HelloWorld for Node { // Attempt to also generate a translated response. if let Some(salutation) = self.translate(&req.greeting, "en", "fr") { info!("Say bonjour to {}", salutation); - let mut res = HelloResponse::new(); + let mut res = HelloResponse::default(); res.reply = format!("BONJOUR {}!", salutation); writer .write(&res, grpc::WriteMode::KeepOpen) @@ -70,7 +71,7 @@ impl HelloWorld for Node { } info!("Say hello again to {}", req.greeting); - let mut res2 = HelloResponse::new(); + let mut res2 = HelloResponse::default(); res2.reply = format!("HELLO AGAIN {}!", req.greeting); writer .write(&res2, grpc::WriteMode::Close) @@ -82,7 +83,7 @@ impl HelloWorld for Node { let mut msg = String::new(); msg.push_str("Hello "); msg.push_str(&recipients(&reqs)); - let mut res = HelloResponse::new(); + let mut res = HelloResponse::default(); res.reply = msg; Ok(res) } @@ -90,12 +91,12 @@ impl HelloWorld for Node { fn bidi_hello(&mut self, reqs: Vec, mut writer: grpc::ChannelResponseWriter) { info!("Say hello"); let msg = recipients(&reqs); - let mut res1 = HelloResponse::new(); + let mut res1 = HelloResponse::default(); res1.reply = format!("HELLO {}!", msg); writer .write(&res1, grpc::WriteMode::KeepOpen) .expect("Failed to write response"); - let mut res2 = HelloResponse::new(); + let mut res2 = HelloResponse::default(); res2.reply = format!("BONJOUR {}!", msg); writer .write(&res2, grpc::WriteMode::Close) diff --git a/examples/hello_world/module/rust/src/proto/hello_world.rs b/examples/hello_world/module/rust/src/proto/hello_world.rs deleted file mode 100644 index 3a760288130..00000000000 --- a/examples/hello_world/module/rust/src/proto/hello_world.rs +++ /dev/null @@ -1,395 +0,0 @@ -// This file is generated by rust-protobuf 2.10.1. Do not edit -// @generated - -// https://github.com/rust-lang/rust-clippy/issues/702 -#![allow(unknown_lints)] -#![allow(clippy::all)] - -#![cfg_attr(rustfmt, rustfmt_skip)] - -#![allow(box_pointers)] -#![allow(dead_code)] -#![allow(missing_docs)] -#![allow(non_camel_case_types)] -#![allow(non_snake_case)] -#![allow(non_upper_case_globals)] -#![allow(trivial_casts)] -#![allow(unsafe_code)] -#![allow(unused_imports)] -#![allow(unused_results)] -//! Generated file from `hello_world.proto` - -use protobuf::Message as Message_imported_for_functions; -use protobuf::ProtobufEnum as ProtobufEnum_imported_for_functions; - -/// Generated files are compatible only with the same version -/// of protobuf runtime. -// const _PROTOBUF_VERSION_CHECK: () = ::protobuf::VERSION_2_10_1; - -#[derive(PartialEq,Clone,Default)] -pub struct HelloRequest { - // message fields - pub greeting: ::std::string::String, - // special fields - pub unknown_fields: ::protobuf::UnknownFields, - pub cached_size: ::protobuf::CachedSize, -} - -impl<'a> ::std::default::Default for &'a HelloRequest { - fn default() -> &'a HelloRequest { - ::default_instance() - } -} - -impl HelloRequest { - pub fn new() -> HelloRequest { - ::std::default::Default::default() - } - - // string greeting = 1; - - - pub fn get_greeting(&self) -> &str { - &self.greeting - } - pub fn clear_greeting(&mut self) { - self.greeting.clear(); - } - - // Param is passed by value, moved - pub fn set_greeting(&mut self, v: ::std::string::String) { - self.greeting = v; - } - - // Mutable pointer to the field. - // If field is not initialized, it is initialized with default value first. - pub fn mut_greeting(&mut self) -> &mut ::std::string::String { - &mut self.greeting - } - - // Take field - pub fn take_greeting(&mut self) -> ::std::string::String { - ::std::mem::replace(&mut self.greeting, ::std::string::String::new()) - } -} - -impl ::protobuf::Message for HelloRequest { - fn is_initialized(&self) -> bool { - true - } - - fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> { - while !is.eof()? { - let (field_number, wire_type) = is.read_tag_unpack()?; - match field_number { - 1 => { - ::protobuf::rt::read_singular_proto3_string_into(wire_type, is, &mut self.greeting)?; - }, - _ => { - ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; - }, - }; - } - ::std::result::Result::Ok(()) - } - - // Compute sizes of nested messages - #[allow(unused_variables)] - fn compute_size(&self) -> u32 { - let mut my_size = 0; - if !self.greeting.is_empty() { - my_size += ::protobuf::rt::string_size(1, &self.greeting); - } - my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); - self.cached_size.set(my_size); - my_size - } - - fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { - if !self.greeting.is_empty() { - os.write_string(1, &self.greeting)?; - } - os.write_unknown_fields(self.get_unknown_fields())?; - ::std::result::Result::Ok(()) - } - - fn get_cached_size(&self) -> u32 { - self.cached_size.get() - } - - fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { - &self.unknown_fields - } - - fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { - &mut self.unknown_fields - } - - fn as_any(&self) -> &dyn (::std::any::Any) { - self as &dyn (::std::any::Any) - } - fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { - self as &mut dyn (::std::any::Any) - } - fn into_any(self: Box) -> ::std::boxed::Box { - self - } - - fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { - Self::descriptor_static() - } - - fn new() -> HelloRequest { - HelloRequest::new() - } - - fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor { - static mut descriptor: ::protobuf::lazy::Lazy<::protobuf::reflect::MessageDescriptor> = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const ::protobuf::reflect::MessageDescriptor, - }; - unsafe { - descriptor.get(|| { - let mut fields = ::std::vec::Vec::new(); - fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeString>( - "greeting", - |m: &HelloRequest| { &m.greeting }, - |m: &mut HelloRequest| { &mut m.greeting }, - )); - ::protobuf::reflect::MessageDescriptor::new::( - "HelloRequest", - fields, - file_descriptor_proto() - ) - }) - } - } - - fn default_instance() -> &'static HelloRequest { - static mut instance: ::protobuf::lazy::Lazy = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const HelloRequest, - }; - unsafe { - instance.get(HelloRequest::new) - } - } -} - -impl ::protobuf::Clear for HelloRequest { - fn clear(&mut self) { - self.greeting.clear(); - self.unknown_fields.clear(); - } -} - -impl ::std::fmt::Debug for HelloRequest { - fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { - ::protobuf::text_format::fmt(self, f) - } -} - -impl ::protobuf::reflect::ProtobufValue for HelloRequest { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { - ::protobuf::reflect::ProtobufValueRef::Message(self) - } -} - -#[derive(PartialEq,Clone,Default)] -pub struct HelloResponse { - // message fields - pub reply: ::std::string::String, - // special fields - pub unknown_fields: ::protobuf::UnknownFields, - pub cached_size: ::protobuf::CachedSize, -} - -impl<'a> ::std::default::Default for &'a HelloResponse { - fn default() -> &'a HelloResponse { - ::default_instance() - } -} - -impl HelloResponse { - pub fn new() -> HelloResponse { - ::std::default::Default::default() - } - - // string reply = 1; - - - pub fn get_reply(&self) -> &str { - &self.reply - } - pub fn clear_reply(&mut self) { - self.reply.clear(); - } - - // Param is passed by value, moved - pub fn set_reply(&mut self, v: ::std::string::String) { - self.reply = v; - } - - // Mutable pointer to the field. - // If field is not initialized, it is initialized with default value first. - pub fn mut_reply(&mut self) -> &mut ::std::string::String { - &mut self.reply - } - - // Take field - pub fn take_reply(&mut self) -> ::std::string::String { - ::std::mem::replace(&mut self.reply, ::std::string::String::new()) - } -} - -impl ::protobuf::Message for HelloResponse { - fn is_initialized(&self) -> bool { - true - } - - fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> { - while !is.eof()? { - let (field_number, wire_type) = is.read_tag_unpack()?; - match field_number { - 1 => { - ::protobuf::rt::read_singular_proto3_string_into(wire_type, is, &mut self.reply)?; - }, - _ => { - ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; - }, - }; - } - ::std::result::Result::Ok(()) - } - - // Compute sizes of nested messages - #[allow(unused_variables)] - fn compute_size(&self) -> u32 { - let mut my_size = 0; - if !self.reply.is_empty() { - my_size += ::protobuf::rt::string_size(1, &self.reply); - } - my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); - self.cached_size.set(my_size); - my_size - } - - fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { - if !self.reply.is_empty() { - os.write_string(1, &self.reply)?; - } - os.write_unknown_fields(self.get_unknown_fields())?; - ::std::result::Result::Ok(()) - } - - fn get_cached_size(&self) -> u32 { - self.cached_size.get() - } - - fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { - &self.unknown_fields - } - - fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { - &mut self.unknown_fields - } - - fn as_any(&self) -> &dyn (::std::any::Any) { - self as &dyn (::std::any::Any) - } - fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { - self as &mut dyn (::std::any::Any) - } - fn into_any(self: Box) -> ::std::boxed::Box { - self - } - - fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { - Self::descriptor_static() - } - - fn new() -> HelloResponse { - HelloResponse::new() - } - - fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor { - static mut descriptor: ::protobuf::lazy::Lazy<::protobuf::reflect::MessageDescriptor> = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const ::protobuf::reflect::MessageDescriptor, - }; - unsafe { - descriptor.get(|| { - let mut fields = ::std::vec::Vec::new(); - fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeString>( - "reply", - |m: &HelloResponse| { &m.reply }, - |m: &mut HelloResponse| { &mut m.reply }, - )); - ::protobuf::reflect::MessageDescriptor::new::( - "HelloResponse", - fields, - file_descriptor_proto() - ) - }) - } - } - - fn default_instance() -> &'static HelloResponse { - static mut instance: ::protobuf::lazy::Lazy = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const HelloResponse, - }; - unsafe { - instance.get(HelloResponse::new) - } - } -} - -impl ::protobuf::Clear for HelloResponse { - fn clear(&mut self) { - self.reply.clear(); - self.unknown_fields.clear(); - } -} - -impl ::std::fmt::Debug for HelloResponse { - fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { - ::protobuf::text_format::fmt(self, f) - } -} - -impl ::protobuf::reflect::ProtobufValue for HelloResponse { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { - ::protobuf::reflect::ProtobufValueRef::Message(self) - } -} - -static file_descriptor_proto_data: &'static [u8] = b"\ - \n\x11hello_world.proto\x12\x18oak.examples.hello_world\"*\n\x0cHelloReq\ - uest\x12\x1a\n\x08greeting\x18\x01\x20\x01(\tR\x08greeting\"%\n\rHelloRe\ - sponse\x12\x14\n\x05reply\x18\x01\x20\x01(\tR\x05reply2\x95\x03\n\nHello\ - World\x12[\n\x08SayHello\x12&.oak.examples.hello_world.HelloRequest\x1a'\ - .oak.examples.hello_world.HelloResponse\x12b\n\rLotsOfReplies\x12&.oak.e\ - xamples.hello_world.HelloRequest\x1a'.oak.examples.hello_world.HelloResp\ - onse0\x01\x12d\n\x0fLotsOfGreetings\x12&.oak.examples.hello_world.HelloR\ - equest\x1a'.oak.examples.hello_world.HelloResponse(\x01\x12`\n\tBidiHell\ - o\x12&.oak.examples.hello_world.HelloRequest\x1a'.oak.examples.hello_wor\ - ld.HelloResponse(\x010\x01b\x06proto3\ -"; - -static mut file_descriptor_proto_lazy: ::protobuf::lazy::Lazy<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const ::protobuf::descriptor::FileDescriptorProto, -}; - -fn parse_descriptor_proto() -> ::protobuf::descriptor::FileDescriptorProto { - ::protobuf::parse_from_bytes(file_descriptor_proto_data).unwrap() -} - -pub fn file_descriptor_proto() -> &'static ::protobuf::descriptor::FileDescriptorProto { - unsafe { - file_descriptor_proto_lazy.get(|| { - parse_descriptor_proto() - }) - } -} diff --git a/examples/hello_world/module/rust/src/proto/hello_world_grpc.rs b/examples/hello_world/module/rust/src/proto/hello_world_grpc.rs deleted file mode 100644 index 2b0df85a3f5..00000000000 --- a/examples/hello_world/module/rust/src/proto/hello_world_grpc.rs +++ /dev/null @@ -1,68 +0,0 @@ -// This file is generated. Do not edit -// @generated - -// https://github.com/rust-lang/rust-clippy/issues/702 -#![allow(unknown_lints)] -#![allow(clippy::all)] - -#![cfg_attr(rustfmt, rustfmt_skip)] - -#![allow(box_pointers)] -#![allow(dead_code)] -#![allow(missing_docs)] -#![allow(non_camel_case_types)] -#![allow(non_snake_case)] -#![allow(non_upper_case_globals)] -#![allow(trivial_casts)] -#![allow(unsafe_code)] -#![allow(unused_imports)] -#![allow(unused_results)] - - -use oak::grpc; -use protobuf::Message; -use std::io::Write; -use log::error; - -// Oak Node server interface -pub trait HelloWorld { - fn say_hello(&mut self, req: super::hello_world::HelloRequest) -> grpc::Result; - fn lots_of_replies(&mut self, req: super::hello_world::HelloRequest, writer: grpc::ChannelResponseWriter); - fn lots_of_greetings(&mut self, reqs: Vec) -> grpc::Result; - fn bidi_hello(&mut self, reqs: Vec, writer: grpc::ChannelResponseWriter); -} - -// Oak Node gRPC method dispatcher -pub struct Dispatcher(T); - -impl Dispatcher { - pub fn new(node: T) -> Dispatcher { - Dispatcher(node) - } -} - -impl grpc::ServerNode for Dispatcher { - fn invoke(&mut self, method: &str, req: &[u8], writer: grpc::ChannelResponseWriter) { - match method { - "/oak.examples.hello_world.HelloWorld/SayHello" => grpc::handle_req_rsp(|r| self.0.say_hello(r), req, writer), - "/oak.examples.hello_world.HelloWorld/LotsOfReplies" => grpc::handle_req_stream(|r, w| self.0.lots_of_replies(r, w), req, writer), - "/oak.examples.hello_world.HelloWorld/LotsOfGreetings" => grpc::handle_stream_rsp(|rr| self.0.lots_of_greetings(rr), req, writer), - "/oak.examples.hello_world.HelloWorld/BidiHello" => grpc::handle_stream_stream(|rr, w| self.0.bidi_hello(rr, w), req, writer), - _ => { - error!("unknown method name: {}", method); - } - }; - } -} - -// Client interface -pub struct HelloWorldClient(pub oak::grpc::client::Client); - -impl HelloWorldClient { - pub fn say_hello(&self, req: super::hello_world::HelloRequest) -> grpc::Result { - oak::grpc::invoke_grpc_method("/oak.examples.hello_world.HelloWorld/SayHello", &req, Some("type.googleapis.com/oak.examples.hello_world.HelloRequest"), &self.0.invocation_sender) - } - pub fn lots_of_replies(&self, req: super::hello_world::HelloRequest) -> grpc::Result> { - oak::grpc::invoke_grpc_method_stream("/oak.examples.hello_world.HelloWorld/LotsOfReplies", &req, Some("type.googleapis.com/oak.examples.hello_world.HelloRequest"), &self.0.invocation_sender) - } -} diff --git a/examples/hello_world/module/rust/src/proto/mod.rs b/examples/hello_world/module/rust/src/proto/mod.rs deleted file mode 100644 index 3fa71ed9beb..00000000000 --- a/examples/hello_world/module/rust/src/proto/mod.rs +++ /dev/null @@ -1,18 +0,0 @@ -// -// Copyright 2019 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. -// - -pub mod hello_world; -pub mod hello_world_grpc; diff --git a/examples/hello_world/module/rust/src/tests.rs b/examples/hello_world/module/rust/src/tests.rs index 884d5cc4160..2ff68a27ecb 100644 --- a/examples/hello_world/module/rust/src/tests.rs +++ b/examples/hello_world/module/rust/src/tests.rs @@ -14,7 +14,7 @@ // limitations under the License. // -use crate::proto::hello_world::{HelloRequest, HelloResponse}; +use crate::proto::{HelloRequest, HelloResponse}; use assert_matches::assert_matches; use oak::grpc; @@ -30,7 +30,6 @@ fn test_say_hello() { let req = HelloRequest { greeting: "world".into(), - ..Default::default() }; let result: grpc::Result = oak_tests::grpc_request( &runtime, diff --git a/examples/machine_learning/module/rust/Cargo.toml b/examples/machine_learning/module/rust/Cargo.toml index a478ac868fc..d4517e2e2ac 100644 --- a/examples/machine_learning/module/rust/Cargo.toml +++ b/examples/machine_learning/module/rust/Cargo.toml @@ -13,4 +13,4 @@ rand = "*" rand_distr = "*" oak = "=0.1.0" log = "*" -protobuf = "*" +prost = "*" diff --git a/examples/private_set_intersection/module/rust/Cargo.toml b/examples/private_set_intersection/module/rust/Cargo.toml index 65c04f30a63..43424a5ac1a 100644 --- a/examples/private_set_intersection/module/rust/Cargo.toml +++ b/examples/private_set_intersection/module/rust/Cargo.toml @@ -10,7 +10,7 @@ crate-type = ["cdylib"] [dependencies] log = "*" oak = "=0.1.0" -protobuf = "*" +prost = "*" [dev-dependencies] assert_matches = "*" @@ -20,4 +20,3 @@ simple_logger = "*" [build-dependencies] oak_utils = "*" -protoc-rust-grpc = { path = "../../../../third_party/grpc-rust/protoc-rust-grpc" } diff --git a/examples/private_set_intersection/module/rust/build.rs b/examples/private_set_intersection/module/rust/build.rs index 04dc5f3025b..c47a14d833c 100644 --- a/examples/private_set_intersection/module/rust/build.rs +++ b/examples/private_set_intersection/module/rust/build.rs @@ -15,12 +15,8 @@ // fn main() { - oak_utils::run_protoc_rust_grpc(protoc_rust_grpc::Args { - out_dir: "src/proto", - input: &["../../proto/private_set_intersection.proto"], - includes: &["../../proto"], - rust_protobuf: true, // also generate protobuf messages, not just services - ..Default::default() - }) - .expect("protoc-rust-grpc"); + oak_utils::compile_protos( + &["../../proto/private_set_intersection.proto"], + &["../../proto"], + ); } diff --git a/examples/private_set_intersection/module/rust/src/lib.rs b/examples/private_set_intersection/module/rust/src/lib.rs index 530bb6176cc..ac9c2361ddd 100644 --- a/examples/private_set_intersection/module/rust/src/lib.rs +++ b/examples/private_set_intersection/module/rust/src/lib.rs @@ -25,17 +25,21 @@ //! TODO(#747): Consider stopping accepting contributions after the first client retrieves the //! intersection. -mod proto; +mod proto { + include!(concat!( + env!("OUT_DIR"), + "/oak.examples.private_set_intersection.rs" + )); +} #[cfg(test)] mod tests; use oak::grpc; -use proto::private_set_intersection::{GetIntersectionResponse, SubmitSetRequest}; -use proto::private_set_intersection_grpc::{Dispatcher, PrivateSetIntersection}; -use protobuf::well_known_types::Empty; +use proto::{GetIntersectionResponse, SubmitSetRequest}; +use proto::{PrivateSetIntersection, PrivateSetIntersectionDispatcher}; use std::collections::HashSet; -oak::entrypoint!(oak_main => Dispatcher::new(Node::default())); +oak::entrypoint!(oak_main => PrivateSetIntersectionDispatcher::new(Node::default())); #[derive(Default)] struct Node { @@ -43,18 +47,18 @@ struct Node { } impl PrivateSetIntersection for Node { - fn submit_set(&mut self, req: SubmitSetRequest) -> grpc::Result { + fn submit_set(&mut self, req: SubmitSetRequest) -> grpc::Result<()> { let set = req.values.iter().cloned().collect::>(); let next = match self.values { Some(ref previous) => previous.intersection(&set).cloned().collect(), None => set, }; self.values = Some(next); - Ok(Empty::new()) + Ok(()) } - fn get_intersection(&mut self, _req: Empty) -> grpc::Result { - let mut res = GetIntersectionResponse::new(); + fn get_intersection(&mut self, _req: ()) -> grpc::Result { + let mut res = GetIntersectionResponse::default(); if let Some(ref set) = self.values { res.values = set.iter().cloned().collect(); }; diff --git a/examples/private_set_intersection/module/rust/src/proto/mod.rs b/examples/private_set_intersection/module/rust/src/proto/mod.rs deleted file mode 100644 index a951f502f9c..00000000000 --- a/examples/private_set_intersection/module/rust/src/proto/mod.rs +++ /dev/null @@ -1,18 +0,0 @@ -// -// Copyright 2019 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. -// - -pub mod private_set_intersection; -pub mod private_set_intersection_grpc; diff --git a/examples/private_set_intersection/module/rust/src/proto/private_set_intersection.rs b/examples/private_set_intersection/module/rust/src/proto/private_set_intersection.rs deleted file mode 100644 index 81ce979af5b..00000000000 --- a/examples/private_set_intersection/module/rust/src/proto/private_set_intersection.rs +++ /dev/null @@ -1,391 +0,0 @@ -// This file is generated by rust-protobuf 2.10.1. Do not edit -// @generated - -// https://github.com/rust-lang/rust-clippy/issues/702 -#![allow(unknown_lints)] -#![allow(clippy::all)] - -#![cfg_attr(rustfmt, rustfmt_skip)] - -#![allow(box_pointers)] -#![allow(dead_code)] -#![allow(missing_docs)] -#![allow(non_camel_case_types)] -#![allow(non_snake_case)] -#![allow(non_upper_case_globals)] -#![allow(trivial_casts)] -#![allow(unsafe_code)] -#![allow(unused_imports)] -#![allow(unused_results)] -//! Generated file from `private_set_intersection.proto` - -use protobuf::Message as Message_imported_for_functions; -use protobuf::ProtobufEnum as ProtobufEnum_imported_for_functions; - -/// Generated files are compatible only with the same version -/// of protobuf runtime. -// const _PROTOBUF_VERSION_CHECK: () = ::protobuf::VERSION_2_10_1; - -#[derive(PartialEq,Clone,Default)] -pub struct SubmitSetRequest { - // message fields - pub values: ::protobuf::RepeatedField<::std::string::String>, - // special fields - pub unknown_fields: ::protobuf::UnknownFields, - pub cached_size: ::protobuf::CachedSize, -} - -impl<'a> ::std::default::Default for &'a SubmitSetRequest { - fn default() -> &'a SubmitSetRequest { - ::default_instance() - } -} - -impl SubmitSetRequest { - pub fn new() -> SubmitSetRequest { - ::std::default::Default::default() - } - - // repeated string values = 1; - - - pub fn get_values(&self) -> &[::std::string::String] { - &self.values - } - pub fn clear_values(&mut self) { - self.values.clear(); - } - - // Param is passed by value, moved - pub fn set_values(&mut self, v: ::protobuf::RepeatedField<::std::string::String>) { - self.values = v; - } - - // Mutable pointer to the field. - pub fn mut_values(&mut self) -> &mut ::protobuf::RepeatedField<::std::string::String> { - &mut self.values - } - - // Take field - pub fn take_values(&mut self) -> ::protobuf::RepeatedField<::std::string::String> { - ::std::mem::replace(&mut self.values, ::protobuf::RepeatedField::new()) - } -} - -impl ::protobuf::Message for SubmitSetRequest { - fn is_initialized(&self) -> bool { - true - } - - fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> { - while !is.eof()? { - let (field_number, wire_type) = is.read_tag_unpack()?; - match field_number { - 1 => { - ::protobuf::rt::read_repeated_string_into(wire_type, is, &mut self.values)?; - }, - _ => { - ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; - }, - }; - } - ::std::result::Result::Ok(()) - } - - // Compute sizes of nested messages - #[allow(unused_variables)] - fn compute_size(&self) -> u32 { - let mut my_size = 0; - for value in &self.values { - my_size += ::protobuf::rt::string_size(1, &value); - }; - my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); - self.cached_size.set(my_size); - my_size - } - - fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { - for v in &self.values { - os.write_string(1, &v)?; - }; - os.write_unknown_fields(self.get_unknown_fields())?; - ::std::result::Result::Ok(()) - } - - fn get_cached_size(&self) -> u32 { - self.cached_size.get() - } - - fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { - &self.unknown_fields - } - - fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { - &mut self.unknown_fields - } - - fn as_any(&self) -> &dyn (::std::any::Any) { - self as &dyn (::std::any::Any) - } - fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { - self as &mut dyn (::std::any::Any) - } - fn into_any(self: Box) -> ::std::boxed::Box { - self - } - - fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { - Self::descriptor_static() - } - - fn new() -> SubmitSetRequest { - SubmitSetRequest::new() - } - - fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor { - static mut descriptor: ::protobuf::lazy::Lazy<::protobuf::reflect::MessageDescriptor> = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const ::protobuf::reflect::MessageDescriptor, - }; - unsafe { - descriptor.get(|| { - let mut fields = ::std::vec::Vec::new(); - fields.push(::protobuf::reflect::accessor::make_repeated_field_accessor::<_, ::protobuf::types::ProtobufTypeString>( - "values", - |m: &SubmitSetRequest| { &m.values }, - |m: &mut SubmitSetRequest| { &mut m.values }, - )); - ::protobuf::reflect::MessageDescriptor::new::( - "SubmitSetRequest", - fields, - file_descriptor_proto() - ) - }) - } - } - - fn default_instance() -> &'static SubmitSetRequest { - static mut instance: ::protobuf::lazy::Lazy = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const SubmitSetRequest, - }; - unsafe { - instance.get(SubmitSetRequest::new) - } - } -} - -impl ::protobuf::Clear for SubmitSetRequest { - fn clear(&mut self) { - self.values.clear(); - self.unknown_fields.clear(); - } -} - -impl ::std::fmt::Debug for SubmitSetRequest { - fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { - ::protobuf::text_format::fmt(self, f) - } -} - -impl ::protobuf::reflect::ProtobufValue for SubmitSetRequest { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { - ::protobuf::reflect::ProtobufValueRef::Message(self) - } -} - -#[derive(PartialEq,Clone,Default)] -pub struct GetIntersectionResponse { - // message fields - pub values: ::protobuf::RepeatedField<::std::string::String>, - // special fields - pub unknown_fields: ::protobuf::UnknownFields, - pub cached_size: ::protobuf::CachedSize, -} - -impl<'a> ::std::default::Default for &'a GetIntersectionResponse { - fn default() -> &'a GetIntersectionResponse { - ::default_instance() - } -} - -impl GetIntersectionResponse { - pub fn new() -> GetIntersectionResponse { - ::std::default::Default::default() - } - - // repeated string values = 1; - - - pub fn get_values(&self) -> &[::std::string::String] { - &self.values - } - pub fn clear_values(&mut self) { - self.values.clear(); - } - - // Param is passed by value, moved - pub fn set_values(&mut self, v: ::protobuf::RepeatedField<::std::string::String>) { - self.values = v; - } - - // Mutable pointer to the field. - pub fn mut_values(&mut self) -> &mut ::protobuf::RepeatedField<::std::string::String> { - &mut self.values - } - - // Take field - pub fn take_values(&mut self) -> ::protobuf::RepeatedField<::std::string::String> { - ::std::mem::replace(&mut self.values, ::protobuf::RepeatedField::new()) - } -} - -impl ::protobuf::Message for GetIntersectionResponse { - fn is_initialized(&self) -> bool { - true - } - - fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> { - while !is.eof()? { - let (field_number, wire_type) = is.read_tag_unpack()?; - match field_number { - 1 => { - ::protobuf::rt::read_repeated_string_into(wire_type, is, &mut self.values)?; - }, - _ => { - ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; - }, - }; - } - ::std::result::Result::Ok(()) - } - - // Compute sizes of nested messages - #[allow(unused_variables)] - fn compute_size(&self) -> u32 { - let mut my_size = 0; - for value in &self.values { - my_size += ::protobuf::rt::string_size(1, &value); - }; - my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); - self.cached_size.set(my_size); - my_size - } - - fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { - for v in &self.values { - os.write_string(1, &v)?; - }; - os.write_unknown_fields(self.get_unknown_fields())?; - ::std::result::Result::Ok(()) - } - - fn get_cached_size(&self) -> u32 { - self.cached_size.get() - } - - fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { - &self.unknown_fields - } - - fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { - &mut self.unknown_fields - } - - fn as_any(&self) -> &dyn (::std::any::Any) { - self as &dyn (::std::any::Any) - } - fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { - self as &mut dyn (::std::any::Any) - } - fn into_any(self: Box) -> ::std::boxed::Box { - self - } - - fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { - Self::descriptor_static() - } - - fn new() -> GetIntersectionResponse { - GetIntersectionResponse::new() - } - - fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor { - static mut descriptor: ::protobuf::lazy::Lazy<::protobuf::reflect::MessageDescriptor> = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const ::protobuf::reflect::MessageDescriptor, - }; - unsafe { - descriptor.get(|| { - let mut fields = ::std::vec::Vec::new(); - fields.push(::protobuf::reflect::accessor::make_repeated_field_accessor::<_, ::protobuf::types::ProtobufTypeString>( - "values", - |m: &GetIntersectionResponse| { &m.values }, - |m: &mut GetIntersectionResponse| { &mut m.values }, - )); - ::protobuf::reflect::MessageDescriptor::new::( - "GetIntersectionResponse", - fields, - file_descriptor_proto() - ) - }) - } - } - - fn default_instance() -> &'static GetIntersectionResponse { - static mut instance: ::protobuf::lazy::Lazy = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const GetIntersectionResponse, - }; - unsafe { - instance.get(GetIntersectionResponse::new) - } - } -} - -impl ::protobuf::Clear for GetIntersectionResponse { - fn clear(&mut self) { - self.values.clear(); - self.unknown_fields.clear(); - } -} - -impl ::std::fmt::Debug for GetIntersectionResponse { - fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { - ::protobuf::text_format::fmt(self, f) - } -} - -impl ::protobuf::reflect::ProtobufValue for GetIntersectionResponse { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { - ::protobuf::reflect::ProtobufValueRef::Message(self) - } -} - -static file_descriptor_proto_data: &'static [u8] = b"\ - \n\x1eprivate_set_intersection.proto\x12%oak.examples.private_set_inters\ - ection\x1a\x1bgoogle/protobuf/empty.proto\"*\n\x10SubmitSetRequest\x12\ - \x16\n\x06values\x18\x01\x20\x03(\tR\x06values\"1\n\x17GetIntersectionRe\ - sponse\x12\x16\n\x06values\x18\x01\x20\x03(\tR\x06values2\xe1\x01\n\x16P\ - rivateSetIntersection\x12\\\n\tSubmitSet\x127.oak.examples.private_set_i\ - ntersection.SubmitSetRequest\x1a\x16.google.protobuf.Empty\x12i\n\x0fGet\ - Intersection\x12\x16.google.protobuf.Empty\x1a>.oak.examples.private_set\ - _intersection.GetIntersectionResponseb\x06proto3\ -"; - -static mut file_descriptor_proto_lazy: ::protobuf::lazy::Lazy<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const ::protobuf::descriptor::FileDescriptorProto, -}; - -fn parse_descriptor_proto() -> ::protobuf::descriptor::FileDescriptorProto { - ::protobuf::parse_from_bytes(file_descriptor_proto_data).unwrap() -} - -pub fn file_descriptor_proto() -> &'static ::protobuf::descriptor::FileDescriptorProto { - unsafe { - file_descriptor_proto_lazy.get(|| { - parse_descriptor_proto() - }) - } -} diff --git a/examples/private_set_intersection/module/rust/src/proto/private_set_intersection_grpc.rs b/examples/private_set_intersection/module/rust/src/proto/private_set_intersection_grpc.rs deleted file mode 100644 index 7b4063aefda..00000000000 --- a/examples/private_set_intersection/module/rust/src/proto/private_set_intersection_grpc.rs +++ /dev/null @@ -1,64 +0,0 @@ -// This file is generated. Do not edit -// @generated - -// https://github.com/rust-lang/rust-clippy/issues/702 -#![allow(unknown_lints)] -#![allow(clippy::all)] - -#![cfg_attr(rustfmt, rustfmt_skip)] - -#![allow(box_pointers)] -#![allow(dead_code)] -#![allow(missing_docs)] -#![allow(non_camel_case_types)] -#![allow(non_snake_case)] -#![allow(non_upper_case_globals)] -#![allow(trivial_casts)] -#![allow(unsafe_code)] -#![allow(unused_imports)] -#![allow(unused_results)] - - -use oak::grpc; -use protobuf::Message; -use std::io::Write; -use log::error; - -// Oak Node server interface -pub trait PrivateSetIntersection { - fn submit_set(&mut self, req: super::private_set_intersection::SubmitSetRequest) -> grpc::Result; - fn get_intersection(&mut self, req: protobuf::well_known_types::Empty) -> grpc::Result; -} - -// Oak Node gRPC method dispatcher -pub struct Dispatcher(T); - -impl Dispatcher { - pub fn new(node: T) -> Dispatcher { - Dispatcher(node) - } -} - -impl grpc::ServerNode for Dispatcher { - fn invoke(&mut self, method: &str, req: &[u8], writer: grpc::ChannelResponseWriter) { - match method { - "/oak.examples.private_set_intersection.PrivateSetIntersection/SubmitSet" => grpc::handle_req_rsp(|r| self.0.submit_set(r), req, writer), - "/oak.examples.private_set_intersection.PrivateSetIntersection/GetIntersection" => grpc::handle_req_rsp(|r| self.0.get_intersection(r), req, writer), - _ => { - error!("unknown method name: {}", method); - } - }; - } -} - -// Client interface -pub struct PrivateSetIntersectionClient(pub oak::grpc::client::Client); - -impl PrivateSetIntersectionClient { - pub fn submit_set(&self, req: super::private_set_intersection::SubmitSetRequest) -> grpc::Result { - oak::grpc::invoke_grpc_method("/oak.examples.private_set_intersection.PrivateSetIntersection/SubmitSet", &req, Some("type.googleapis.com/oak.examples.private_set_intersection.SubmitSetRequest"), &self.0.invocation_sender) - } - pub fn get_intersection(&self, req: protobuf::well_known_types::Empty) -> grpc::Result { - oak::grpc::invoke_grpc_method("/oak.examples.private_set_intersection.PrivateSetIntersection/GetIntersection", &req, Some("type.googleapis.com/google.protobuf.Empty"), &self.0.invocation_sender) - } -} diff --git a/examples/private_set_intersection/module/rust/src/tests.rs b/examples/private_set_intersection/module/rust/src/tests.rs index 8b4110d3e9b..4ac71b7f0fe 100644 --- a/examples/private_set_intersection/module/rust/src/tests.rs +++ b/examples/private_set_intersection/module/rust/src/tests.rs @@ -14,10 +14,9 @@ // limitations under the License. // -use crate::proto::private_set_intersection::{GetIntersectionResponse, SubmitSetRequest}; +use crate::proto::{GetIntersectionResponse, SubmitSetRequest}; use assert_matches::assert_matches; use oak::grpc; -use protobuf::well_known_types::Empty; use std::collections::HashSet; use std::iter::FromIterator; @@ -31,10 +30,9 @@ fn test_set_intersection() { .expect("Unable to configure runtime with test wasm!"); let req = SubmitSetRequest { - values: vec!["a".to_string(), "b".to_string(), "c".to_string()].into(), - ..Default::default() + values: vec!["a".to_string(), "b".to_string(), "c".to_string()], }; - let result: grpc::Result = oak_tests::grpc_request( + let result: grpc::Result<()> = oak_tests::grpc_request( &runtime, entry_channel, "/oak.examples.private_set_intersection.PrivateSetIntersection/SubmitSet", @@ -43,10 +41,9 @@ fn test_set_intersection() { assert_matches!(result, Ok(_)); let req = SubmitSetRequest { - values: vec!["b".to_string(), "c".to_string(), "d".to_string()].into(), - ..Default::default() + values: vec!["b".to_string(), "c".to_string(), "d".to_string()], }; - let result: grpc::Result = oak_tests::grpc_request( + let result: grpc::Result<()> = oak_tests::grpc_request( &runtime, entry_channel, "/oak.examples.private_set_intersection.PrivateSetIntersection/SubmitSet", @@ -54,12 +51,11 @@ fn test_set_intersection() { ); assert_matches!(result, Ok(_)); - let req = Empty::new(); let result: grpc::Result = oak_tests::grpc_request( &runtime, entry_channel, "/oak.examples.private_set_intersection.PrivateSetIntersection/GetIntersection", - &req, + &(), ); assert_matches!(result, Ok(_)); let got = HashSet::::from_iter(result.unwrap().values.to_vec()); diff --git a/examples/running_average/module/rust/Cargo.toml b/examples/running_average/module/rust/Cargo.toml index a69d5a70e0e..3b1042a20b3 100644 --- a/examples/running_average/module/rust/Cargo.toml +++ b/examples/running_average/module/rust/Cargo.toml @@ -10,7 +10,7 @@ crate-type = ["cdylib"] [dependencies] log = "*" oak = "=0.1.0" -protobuf = "*" +prost = "*" [dev-dependencies] assert_matches = "*" @@ -20,4 +20,3 @@ simple_logger = "*" [build-dependencies] oak_utils = "*" -protoc-rust-grpc = { path = "../../../../third_party/grpc-rust/protoc-rust-grpc" } diff --git a/examples/running_average/module/rust/build.rs b/examples/running_average/module/rust/build.rs index 645d97e6716..ce4b38739fe 100644 --- a/examples/running_average/module/rust/build.rs +++ b/examples/running_average/module/rust/build.rs @@ -15,12 +15,5 @@ // fn main() { - oak_utils::run_protoc_rust_grpc(protoc_rust_grpc::Args { - out_dir: "src/proto", - input: &["../../proto/running_average.proto"], - includes: &["../../proto"], - rust_protobuf: true, // also generate protobuf messages, not just services - ..Default::default() - }) - .expect("protoc-rust-grpc"); + oak_utils::compile_protos(&["../../proto/running_average.proto"], &["../../proto"]); } diff --git a/examples/running_average/module/rust/src/lib.rs b/examples/running_average/module/rust/src/lib.rs index 003e8891f93..42b106a16c4 100644 --- a/examples/running_average/module/rust/src/lib.rs +++ b/examples/running_average/module/rust/src/lib.rs @@ -22,16 +22,16 @@ //! expressed in base 10, and get back a string representation of the accumulated average value up //! to and including the value provided in the request. -mod proto; +mod proto { + include!(concat!(env!("OUT_DIR"), "/oak.examples.running_average.rs")); +} #[cfg(test)] mod tests; use oak::grpc; -use proto::running_average::{GetAverageResponse, SubmitSampleRequest}; -use proto::running_average_grpc::{Dispatcher, RunningAverage}; -use protobuf::well_known_types::Empty; +use proto::{GetAverageResponse, RunningAverage, RunningAverageDispatcher, SubmitSampleRequest}; -oak::entrypoint!(oak_main => Dispatcher::new(Node::default())); +oak::entrypoint!(oak_main => RunningAverageDispatcher::new(Node::default())); #[derive(Default)] struct Node { @@ -40,14 +40,14 @@ struct Node { } impl RunningAverage for Node { - fn submit_sample(&mut self, req: SubmitSampleRequest) -> grpc::Result { + fn submit_sample(&mut self, req: SubmitSampleRequest) -> grpc::Result<()> { self.sum += req.value; self.count += 1; - Ok(Empty::new()) + Ok(()) } - fn get_average(&mut self, _req: Empty) -> grpc::Result { - let mut res = GetAverageResponse::new(); + fn get_average(&mut self, _req: ()) -> grpc::Result { + let mut res = GetAverageResponse::default(); res.average = self.sum / self.count; Ok(res) } diff --git a/examples/running_average/module/rust/src/proto/mod.rs b/examples/running_average/module/rust/src/proto/mod.rs deleted file mode 100644 index 0dd4b1d46cf..00000000000 --- a/examples/running_average/module/rust/src/proto/mod.rs +++ /dev/null @@ -1,18 +0,0 @@ -// -// Copyright 2019 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. -// - -pub mod running_average; -pub mod running_average_grpc; diff --git a/examples/running_average/module/rust/src/proto/running_average.rs b/examples/running_average/module/rust/src/proto/running_average.rs deleted file mode 100644 index 43918c35380..00000000000 --- a/examples/running_average/module/rust/src/proto/running_average.rs +++ /dev/null @@ -1,379 +0,0 @@ -// This file is generated by rust-protobuf 2.10.1. Do not edit -// @generated - -// https://github.com/rust-lang/rust-clippy/issues/702 -#![allow(unknown_lints)] -#![allow(clippy::all)] - -#![cfg_attr(rustfmt, rustfmt_skip)] - -#![allow(box_pointers)] -#![allow(dead_code)] -#![allow(missing_docs)] -#![allow(non_camel_case_types)] -#![allow(non_snake_case)] -#![allow(non_upper_case_globals)] -#![allow(trivial_casts)] -#![allow(unsafe_code)] -#![allow(unused_imports)] -#![allow(unused_results)] -//! Generated file from `running_average.proto` - -use protobuf::Message as Message_imported_for_functions; -use protobuf::ProtobufEnum as ProtobufEnum_imported_for_functions; - -/// Generated files are compatible only with the same version -/// of protobuf runtime. -// const _PROTOBUF_VERSION_CHECK: () = ::protobuf::VERSION_2_10_1; - -#[derive(PartialEq,Clone,Default)] -pub struct SubmitSampleRequest { - // message fields - pub value: u64, - // special fields - pub unknown_fields: ::protobuf::UnknownFields, - pub cached_size: ::protobuf::CachedSize, -} - -impl<'a> ::std::default::Default for &'a SubmitSampleRequest { - fn default() -> &'a SubmitSampleRequest { - ::default_instance() - } -} - -impl SubmitSampleRequest { - pub fn new() -> SubmitSampleRequest { - ::std::default::Default::default() - } - - // uint64 value = 1; - - - pub fn get_value(&self) -> u64 { - self.value - } - pub fn clear_value(&mut self) { - self.value = 0; - } - - // Param is passed by value, moved - pub fn set_value(&mut self, v: u64) { - self.value = v; - } -} - -impl ::protobuf::Message for SubmitSampleRequest { - fn is_initialized(&self) -> bool { - true - } - - fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> { - while !is.eof()? { - let (field_number, wire_type) = is.read_tag_unpack()?; - match field_number { - 1 => { - if wire_type != ::protobuf::wire_format::WireTypeVarint { - return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); - } - let tmp = is.read_uint64()?; - self.value = tmp; - }, - _ => { - ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; - }, - }; - } - ::std::result::Result::Ok(()) - } - - // Compute sizes of nested messages - #[allow(unused_variables)] - fn compute_size(&self) -> u32 { - let mut my_size = 0; - if self.value != 0 { - my_size += ::protobuf::rt::value_size(1, self.value, ::protobuf::wire_format::WireTypeVarint); - } - my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); - self.cached_size.set(my_size); - my_size - } - - fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { - if self.value != 0 { - os.write_uint64(1, self.value)?; - } - os.write_unknown_fields(self.get_unknown_fields())?; - ::std::result::Result::Ok(()) - } - - fn get_cached_size(&self) -> u32 { - self.cached_size.get() - } - - fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { - &self.unknown_fields - } - - fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { - &mut self.unknown_fields - } - - fn as_any(&self) -> &dyn (::std::any::Any) { - self as &dyn (::std::any::Any) - } - fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { - self as &mut dyn (::std::any::Any) - } - fn into_any(self: Box) -> ::std::boxed::Box { - self - } - - fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { - Self::descriptor_static() - } - - fn new() -> SubmitSampleRequest { - SubmitSampleRequest::new() - } - - fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor { - static mut descriptor: ::protobuf::lazy::Lazy<::protobuf::reflect::MessageDescriptor> = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const ::protobuf::reflect::MessageDescriptor, - }; - unsafe { - descriptor.get(|| { - let mut fields = ::std::vec::Vec::new(); - fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeUint64>( - "value", - |m: &SubmitSampleRequest| { &m.value }, - |m: &mut SubmitSampleRequest| { &mut m.value }, - )); - ::protobuf::reflect::MessageDescriptor::new::( - "SubmitSampleRequest", - fields, - file_descriptor_proto() - ) - }) - } - } - - fn default_instance() -> &'static SubmitSampleRequest { - static mut instance: ::protobuf::lazy::Lazy = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const SubmitSampleRequest, - }; - unsafe { - instance.get(SubmitSampleRequest::new) - } - } -} - -impl ::protobuf::Clear for SubmitSampleRequest { - fn clear(&mut self) { - self.value = 0; - self.unknown_fields.clear(); - } -} - -impl ::std::fmt::Debug for SubmitSampleRequest { - fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { - ::protobuf::text_format::fmt(self, f) - } -} - -impl ::protobuf::reflect::ProtobufValue for SubmitSampleRequest { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { - ::protobuf::reflect::ProtobufValueRef::Message(self) - } -} - -#[derive(PartialEq,Clone,Default)] -pub struct GetAverageResponse { - // message fields - pub average: u64, - // special fields - pub unknown_fields: ::protobuf::UnknownFields, - pub cached_size: ::protobuf::CachedSize, -} - -impl<'a> ::std::default::Default for &'a GetAverageResponse { - fn default() -> &'a GetAverageResponse { - ::default_instance() - } -} - -impl GetAverageResponse { - pub fn new() -> GetAverageResponse { - ::std::default::Default::default() - } - - // uint64 average = 1; - - - pub fn get_average(&self) -> u64 { - self.average - } - pub fn clear_average(&mut self) { - self.average = 0; - } - - // Param is passed by value, moved - pub fn set_average(&mut self, v: u64) { - self.average = v; - } -} - -impl ::protobuf::Message for GetAverageResponse { - fn is_initialized(&self) -> bool { - true - } - - fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> { - while !is.eof()? { - let (field_number, wire_type) = is.read_tag_unpack()?; - match field_number { - 1 => { - if wire_type != ::protobuf::wire_format::WireTypeVarint { - return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); - } - let tmp = is.read_uint64()?; - self.average = tmp; - }, - _ => { - ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; - }, - }; - } - ::std::result::Result::Ok(()) - } - - // Compute sizes of nested messages - #[allow(unused_variables)] - fn compute_size(&self) -> u32 { - let mut my_size = 0; - if self.average != 0 { - my_size += ::protobuf::rt::value_size(1, self.average, ::protobuf::wire_format::WireTypeVarint); - } - my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); - self.cached_size.set(my_size); - my_size - } - - fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { - if self.average != 0 { - os.write_uint64(1, self.average)?; - } - os.write_unknown_fields(self.get_unknown_fields())?; - ::std::result::Result::Ok(()) - } - - fn get_cached_size(&self) -> u32 { - self.cached_size.get() - } - - fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { - &self.unknown_fields - } - - fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { - &mut self.unknown_fields - } - - fn as_any(&self) -> &dyn (::std::any::Any) { - self as &dyn (::std::any::Any) - } - fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { - self as &mut dyn (::std::any::Any) - } - fn into_any(self: Box) -> ::std::boxed::Box { - self - } - - fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { - Self::descriptor_static() - } - - fn new() -> GetAverageResponse { - GetAverageResponse::new() - } - - fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor { - static mut descriptor: ::protobuf::lazy::Lazy<::protobuf::reflect::MessageDescriptor> = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const ::protobuf::reflect::MessageDescriptor, - }; - unsafe { - descriptor.get(|| { - let mut fields = ::std::vec::Vec::new(); - fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeUint64>( - "average", - |m: &GetAverageResponse| { &m.average }, - |m: &mut GetAverageResponse| { &mut m.average }, - )); - ::protobuf::reflect::MessageDescriptor::new::( - "GetAverageResponse", - fields, - file_descriptor_proto() - ) - }) - } - } - - fn default_instance() -> &'static GetAverageResponse { - static mut instance: ::protobuf::lazy::Lazy = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const GetAverageResponse, - }; - unsafe { - instance.get(GetAverageResponse::new) - } - } -} - -impl ::protobuf::Clear for GetAverageResponse { - fn clear(&mut self) { - self.average = 0; - self.unknown_fields.clear(); - } -} - -impl ::std::fmt::Debug for GetAverageResponse { - fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { - ::protobuf::text_format::fmt(self, f) - } -} - -impl ::protobuf::reflect::ProtobufValue for GetAverageResponse { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { - ::protobuf::reflect::ProtobufValueRef::Message(self) - } -} - -static file_descriptor_proto_data: &'static [u8] = b"\ - \n\x15running_average.proto\x12\x1coak.examples.running_average\x1a\x1bg\ - oogle/protobuf/empty.proto\"+\n\x13SubmitSampleRequest\x12\x14\n\x05valu\ - e\x18\x01\x20\x01(\x04R\x05value\".\n\x12GetAverageResponse\x12\x18\n\ - \x07average\x18\x01\x20\x01(\x04R\x07average2\xc3\x01\n\x0eRunningAverag\ - e\x12Y\n\x0cSubmitSample\x121.oak.examples.running_average.SubmitSampleR\ - equest\x1a\x16.google.protobuf.Empty\x12V\n\nGetAverage\x12\x16.google.p\ - rotobuf.Empty\x1a0.oak.examples.running_average.GetAverageResponseb\x06p\ - roto3\ -"; - -static mut file_descriptor_proto_lazy: ::protobuf::lazy::Lazy<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const ::protobuf::descriptor::FileDescriptorProto, -}; - -fn parse_descriptor_proto() -> ::protobuf::descriptor::FileDescriptorProto { - ::protobuf::parse_from_bytes(file_descriptor_proto_data).unwrap() -} - -pub fn file_descriptor_proto() -> &'static ::protobuf::descriptor::FileDescriptorProto { - unsafe { - file_descriptor_proto_lazy.get(|| { - parse_descriptor_proto() - }) - } -} diff --git a/examples/running_average/module/rust/src/proto/running_average_grpc.rs b/examples/running_average/module/rust/src/proto/running_average_grpc.rs deleted file mode 100644 index f0dbadc18f2..00000000000 --- a/examples/running_average/module/rust/src/proto/running_average_grpc.rs +++ /dev/null @@ -1,64 +0,0 @@ -// This file is generated. Do not edit -// @generated - -// https://github.com/rust-lang/rust-clippy/issues/702 -#![allow(unknown_lints)] -#![allow(clippy::all)] - -#![cfg_attr(rustfmt, rustfmt_skip)] - -#![allow(box_pointers)] -#![allow(dead_code)] -#![allow(missing_docs)] -#![allow(non_camel_case_types)] -#![allow(non_snake_case)] -#![allow(non_upper_case_globals)] -#![allow(trivial_casts)] -#![allow(unsafe_code)] -#![allow(unused_imports)] -#![allow(unused_results)] - - -use oak::grpc; -use protobuf::Message; -use std::io::Write; -use log::error; - -// Oak Node server interface -pub trait RunningAverage { - fn submit_sample(&mut self, req: super::running_average::SubmitSampleRequest) -> grpc::Result; - fn get_average(&mut self, req: protobuf::well_known_types::Empty) -> grpc::Result; -} - -// Oak Node gRPC method dispatcher -pub struct Dispatcher(T); - -impl Dispatcher { - pub fn new(node: T) -> Dispatcher { - Dispatcher(node) - } -} - -impl grpc::ServerNode for Dispatcher { - fn invoke(&mut self, method: &str, req: &[u8], writer: grpc::ChannelResponseWriter) { - match method { - "/oak.examples.running_average.RunningAverage/SubmitSample" => grpc::handle_req_rsp(|r| self.0.submit_sample(r), req, writer), - "/oak.examples.running_average.RunningAverage/GetAverage" => grpc::handle_req_rsp(|r| self.0.get_average(r), req, writer), - _ => { - error!("unknown method name: {}", method); - } - }; - } -} - -// Client interface -pub struct RunningAverageClient(pub oak::grpc::client::Client); - -impl RunningAverageClient { - pub fn submit_sample(&self, req: super::running_average::SubmitSampleRequest) -> grpc::Result { - oak::grpc::invoke_grpc_method("/oak.examples.running_average.RunningAverage/SubmitSample", &req, Some("type.googleapis.com/oak.examples.running_average.SubmitSampleRequest"), &self.0.invocation_sender) - } - pub fn get_average(&self, req: protobuf::well_known_types::Empty) -> grpc::Result { - oak::grpc::invoke_grpc_method("/oak.examples.running_average.RunningAverage/GetAverage", &req, Some("type.googleapis.com/google.protobuf.Empty"), &self.0.invocation_sender) - } -} diff --git a/examples/running_average/module/rust/src/tests.rs b/examples/running_average/module/rust/src/tests.rs index 5e9ad79f311..e1db1480b2e 100644 --- a/examples/running_average/module/rust/src/tests.rs +++ b/examples/running_average/module/rust/src/tests.rs @@ -14,19 +14,15 @@ // limitations under the License. // -use crate::proto::running_average::{GetAverageResponse, SubmitSampleRequest}; +use crate::proto::{GetAverageResponse, SubmitSampleRequest}; use assert_matches::assert_matches; use oak::grpc; -use protobuf::well_known_types::Empty; const MODULE_CONFIG_NAME: &str = "running_average"; fn submit_sample(runtime: &oak_runtime::Runtime, entry_channel: oak_runtime::Handle, value: u64) { - let req = SubmitSampleRequest { - value, - ..Default::default() - }; - let result: grpc::Result = oak_tests::grpc_request( + let req = SubmitSampleRequest { value }; + let result: grpc::Result<()> = oak_tests::grpc_request( &runtime, entry_channel, "/oak.examples.running_average.RunningAverage/SubmitSample", @@ -45,12 +41,11 @@ fn test_running_average() { submit_sample(&runtime, entry_channel, 100); submit_sample(&runtime, entry_channel, 200); - let req = Empty::new(); let result: grpc::Result = oak_tests::grpc_request( &runtime, entry_channel, "/oak.examples.running_average.RunningAverage/GetAverage", - &req, + &(), ); assert_matches!(result, Ok(_)); assert_eq!(150, result.unwrap().average); diff --git a/examples/rustfmt/module/rust/Cargo.toml b/examples/rustfmt/module/rust/Cargo.toml index bd988835d47..27ab88be5b7 100644 --- a/examples/rustfmt/module/rust/Cargo.toml +++ b/examples/rustfmt/module/rust/Cargo.toml @@ -10,9 +10,8 @@ crate-type = ["cdylib"] [dependencies] log = "*" oak = "=0.1.0" -protobuf = "*" +prost = "*" rustfmt-nightly = "*" [build-dependencies] oak_utils = "*" -protoc-rust-grpc = { path = "../../../../third_party/grpc-rust/protoc-rust-grpc" } diff --git a/examples/rustfmt/module/rust/build.rs b/examples/rustfmt/module/rust/build.rs index 02bd26f5748..9a2ed9229cb 100644 --- a/examples/rustfmt/module/rust/build.rs +++ b/examples/rustfmt/module/rust/build.rs @@ -15,12 +15,5 @@ // fn main() { - oak_utils::run_protoc_rust_grpc(protoc_rust_grpc::Args { - out_dir: "src/proto", - input: &["../../proto/rustfmt.proto"], - includes: &["../../proto"], - rust_protobuf: true, // also generate protobuf messages, not just services - ..Default::default() - }) - .expect("protoc-rust-grpc"); + oak_utils::compile_protos(&["../../proto/rustfmt.proto"], &["../../proto"]); } diff --git a/examples/rustfmt/module/rust/src/lib.rs b/examples/rustfmt/module/rust/src/lib.rs index 91d2cf02c64..431e68bbfbc 100644 --- a/examples/rustfmt/module/rust/src/lib.rs +++ b/examples/rustfmt/module/rust/src/lib.rs @@ -14,15 +14,17 @@ // limitations under the License. // -mod proto; +mod proto { + include!(concat!(env!("OUT_DIR"), "/oak.examples.rustfmt.rs")); +} use oak::grpc; -use proto::rustfmt::{FormatRequest, FormatResponse}; -use proto::rustfmt_grpc::{Dispatcher, FormatService}; +use proto::{FormatRequest, FormatResponse}; +use proto::{FormatService, FormatServiceDispatcher}; oak::entrypoint!(oak_main => { oak::logger::init_default(); - Dispatcher::new(Node) + FormatServiceDispatcher::new(Node) }); struct Node; @@ -37,7 +39,7 @@ impl FormatService for Node { let input = rustfmt_nightly::Input::Text(req.code); session.format(input).expect("could not format input"); } - let mut res = FormatResponse::new(); + let mut res = FormatResponse::default(); res.code = String::from_utf8(output).expect("could not parse UTF8"); Ok(res) } diff --git a/examples/rustfmt/module/rust/src/proto/mod.rs b/examples/rustfmt/module/rust/src/proto/mod.rs deleted file mode 100644 index 14ad34adc5b..00000000000 --- a/examples/rustfmt/module/rust/src/proto/mod.rs +++ /dev/null @@ -1,18 +0,0 @@ -// -// Copyright 2019 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. -// - -pub mod rustfmt; -pub mod rustfmt_grpc; diff --git a/examples/rustfmt/module/rust/src/proto/rustfmt.rs b/examples/rustfmt/module/rust/src/proto/rustfmt.rs deleted file mode 100644 index 205363939f2..00000000000 --- a/examples/rustfmt/module/rust/src/proto/rustfmt.rs +++ /dev/null @@ -1,390 +0,0 @@ -// This file is generated by rust-protobuf 2.10.1. Do not edit -// @generated - -// https://github.com/rust-lang/rust-clippy/issues/702 -#![allow(unknown_lints)] -#![allow(clippy::all)] - -#![cfg_attr(rustfmt, rustfmt_skip)] - -#![allow(box_pointers)] -#![allow(dead_code)] -#![allow(missing_docs)] -#![allow(non_camel_case_types)] -#![allow(non_snake_case)] -#![allow(non_upper_case_globals)] -#![allow(trivial_casts)] -#![allow(unsafe_code)] -#![allow(unused_imports)] -#![allow(unused_results)] -//! Generated file from `rustfmt.proto` - -use protobuf::Message as Message_imported_for_functions; -use protobuf::ProtobufEnum as ProtobufEnum_imported_for_functions; - -/// Generated files are compatible only with the same version -/// of protobuf runtime. -// const _PROTOBUF_VERSION_CHECK: () = ::protobuf::VERSION_2_10_1; - -#[derive(PartialEq,Clone,Default)] -pub struct FormatRequest { - // message fields - pub code: ::std::string::String, - // special fields - pub unknown_fields: ::protobuf::UnknownFields, - pub cached_size: ::protobuf::CachedSize, -} - -impl<'a> ::std::default::Default for &'a FormatRequest { - fn default() -> &'a FormatRequest { - ::default_instance() - } -} - -impl FormatRequest { - pub fn new() -> FormatRequest { - ::std::default::Default::default() - } - - // string code = 1; - - - pub fn get_code(&self) -> &str { - &self.code - } - pub fn clear_code(&mut self) { - self.code.clear(); - } - - // Param is passed by value, moved - pub fn set_code(&mut self, v: ::std::string::String) { - self.code = v; - } - - // Mutable pointer to the field. - // If field is not initialized, it is initialized with default value first. - pub fn mut_code(&mut self) -> &mut ::std::string::String { - &mut self.code - } - - // Take field - pub fn take_code(&mut self) -> ::std::string::String { - ::std::mem::replace(&mut self.code, ::std::string::String::new()) - } -} - -impl ::protobuf::Message for FormatRequest { - fn is_initialized(&self) -> bool { - true - } - - fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> { - while !is.eof()? { - let (field_number, wire_type) = is.read_tag_unpack()?; - match field_number { - 1 => { - ::protobuf::rt::read_singular_proto3_string_into(wire_type, is, &mut self.code)?; - }, - _ => { - ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; - }, - }; - } - ::std::result::Result::Ok(()) - } - - // Compute sizes of nested messages - #[allow(unused_variables)] - fn compute_size(&self) -> u32 { - let mut my_size = 0; - if !self.code.is_empty() { - my_size += ::protobuf::rt::string_size(1, &self.code); - } - my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); - self.cached_size.set(my_size); - my_size - } - - fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { - if !self.code.is_empty() { - os.write_string(1, &self.code)?; - } - os.write_unknown_fields(self.get_unknown_fields())?; - ::std::result::Result::Ok(()) - } - - fn get_cached_size(&self) -> u32 { - self.cached_size.get() - } - - fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { - &self.unknown_fields - } - - fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { - &mut self.unknown_fields - } - - fn as_any(&self) -> &dyn (::std::any::Any) { - self as &dyn (::std::any::Any) - } - fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { - self as &mut dyn (::std::any::Any) - } - fn into_any(self: Box) -> ::std::boxed::Box { - self - } - - fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { - Self::descriptor_static() - } - - fn new() -> FormatRequest { - FormatRequest::new() - } - - fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor { - static mut descriptor: ::protobuf::lazy::Lazy<::protobuf::reflect::MessageDescriptor> = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const ::protobuf::reflect::MessageDescriptor, - }; - unsafe { - descriptor.get(|| { - let mut fields = ::std::vec::Vec::new(); - fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeString>( - "code", - |m: &FormatRequest| { &m.code }, - |m: &mut FormatRequest| { &mut m.code }, - )); - ::protobuf::reflect::MessageDescriptor::new::( - "FormatRequest", - fields, - file_descriptor_proto() - ) - }) - } - } - - fn default_instance() -> &'static FormatRequest { - static mut instance: ::protobuf::lazy::Lazy = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const FormatRequest, - }; - unsafe { - instance.get(FormatRequest::new) - } - } -} - -impl ::protobuf::Clear for FormatRequest { - fn clear(&mut self) { - self.code.clear(); - self.unknown_fields.clear(); - } -} - -impl ::std::fmt::Debug for FormatRequest { - fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { - ::protobuf::text_format::fmt(self, f) - } -} - -impl ::protobuf::reflect::ProtobufValue for FormatRequest { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { - ::protobuf::reflect::ProtobufValueRef::Message(self) - } -} - -#[derive(PartialEq,Clone,Default)] -pub struct FormatResponse { - // message fields - pub code: ::std::string::String, - // special fields - pub unknown_fields: ::protobuf::UnknownFields, - pub cached_size: ::protobuf::CachedSize, -} - -impl<'a> ::std::default::Default for &'a FormatResponse { - fn default() -> &'a FormatResponse { - ::default_instance() - } -} - -impl FormatResponse { - pub fn new() -> FormatResponse { - ::std::default::Default::default() - } - - // string code = 1; - - - pub fn get_code(&self) -> &str { - &self.code - } - pub fn clear_code(&mut self) { - self.code.clear(); - } - - // Param is passed by value, moved - pub fn set_code(&mut self, v: ::std::string::String) { - self.code = v; - } - - // Mutable pointer to the field. - // If field is not initialized, it is initialized with default value first. - pub fn mut_code(&mut self) -> &mut ::std::string::String { - &mut self.code - } - - // Take field - pub fn take_code(&mut self) -> ::std::string::String { - ::std::mem::replace(&mut self.code, ::std::string::String::new()) - } -} - -impl ::protobuf::Message for FormatResponse { - fn is_initialized(&self) -> bool { - true - } - - fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> { - while !is.eof()? { - let (field_number, wire_type) = is.read_tag_unpack()?; - match field_number { - 1 => { - ::protobuf::rt::read_singular_proto3_string_into(wire_type, is, &mut self.code)?; - }, - _ => { - ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; - }, - }; - } - ::std::result::Result::Ok(()) - } - - // Compute sizes of nested messages - #[allow(unused_variables)] - fn compute_size(&self) -> u32 { - let mut my_size = 0; - if !self.code.is_empty() { - my_size += ::protobuf::rt::string_size(1, &self.code); - } - my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); - self.cached_size.set(my_size); - my_size - } - - fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { - if !self.code.is_empty() { - os.write_string(1, &self.code)?; - } - os.write_unknown_fields(self.get_unknown_fields())?; - ::std::result::Result::Ok(()) - } - - fn get_cached_size(&self) -> u32 { - self.cached_size.get() - } - - fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { - &self.unknown_fields - } - - fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { - &mut self.unknown_fields - } - - fn as_any(&self) -> &dyn (::std::any::Any) { - self as &dyn (::std::any::Any) - } - fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { - self as &mut dyn (::std::any::Any) - } - fn into_any(self: Box) -> ::std::boxed::Box { - self - } - - fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { - Self::descriptor_static() - } - - fn new() -> FormatResponse { - FormatResponse::new() - } - - fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor { - static mut descriptor: ::protobuf::lazy::Lazy<::protobuf::reflect::MessageDescriptor> = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const ::protobuf::reflect::MessageDescriptor, - }; - unsafe { - descriptor.get(|| { - let mut fields = ::std::vec::Vec::new(); - fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeString>( - "code", - |m: &FormatResponse| { &m.code }, - |m: &mut FormatResponse| { &mut m.code }, - )); - ::protobuf::reflect::MessageDescriptor::new::( - "FormatResponse", - fields, - file_descriptor_proto() - ) - }) - } - } - - fn default_instance() -> &'static FormatResponse { - static mut instance: ::protobuf::lazy::Lazy = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const FormatResponse, - }; - unsafe { - instance.get(FormatResponse::new) - } - } -} - -impl ::protobuf::Clear for FormatResponse { - fn clear(&mut self) { - self.code.clear(); - self.unknown_fields.clear(); - } -} - -impl ::std::fmt::Debug for FormatResponse { - fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { - ::protobuf::text_format::fmt(self, f) - } -} - -impl ::protobuf::reflect::ProtobufValue for FormatResponse { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { - ::protobuf::reflect::ProtobufValueRef::Message(self) - } -} - -static file_descriptor_proto_data: &'static [u8] = b"\ - \n\rrustfmt.proto\x12\x14oak.examples.rustfmt\"#\n\rFormatRequest\x12\ - \x12\n\x04code\x18\x01\x20\x01(\tR\x04code\"$\n\x0eFormatResponse\x12\ - \x12\n\x04code\x18\x01\x20\x01(\tR\x04code2d\n\rFormatService\x12S\n\x06\ - Format\x12#.oak.examples.rustfmt.FormatRequest\x1a$.oak.examples.rustfmt\ - .FormatResponseb\x06proto3\ -"; - -static mut file_descriptor_proto_lazy: ::protobuf::lazy::Lazy<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const ::protobuf::descriptor::FileDescriptorProto, -}; - -fn parse_descriptor_proto() -> ::protobuf::descriptor::FileDescriptorProto { - ::protobuf::parse_from_bytes(file_descriptor_proto_data).unwrap() -} - -pub fn file_descriptor_proto() -> &'static ::protobuf::descriptor::FileDescriptorProto { - unsafe { - file_descriptor_proto_lazy.get(|| { - parse_descriptor_proto() - }) - } -} diff --git a/examples/rustfmt/module/rust/src/proto/rustfmt_grpc.rs b/examples/rustfmt/module/rust/src/proto/rustfmt_grpc.rs deleted file mode 100644 index 5e73aec1ec1..00000000000 --- a/examples/rustfmt/module/rust/src/proto/rustfmt_grpc.rs +++ /dev/null @@ -1,59 +0,0 @@ -// This file is generated. Do not edit -// @generated - -// https://github.com/rust-lang/rust-clippy/issues/702 -#![allow(unknown_lints)] -#![allow(clippy::all)] - -#![cfg_attr(rustfmt, rustfmt_skip)] - -#![allow(box_pointers)] -#![allow(dead_code)] -#![allow(missing_docs)] -#![allow(non_camel_case_types)] -#![allow(non_snake_case)] -#![allow(non_upper_case_globals)] -#![allow(trivial_casts)] -#![allow(unsafe_code)] -#![allow(unused_imports)] -#![allow(unused_results)] - - -use oak::grpc; -use protobuf::Message; -use std::io::Write; -use log::error; - -// Oak Node server interface -pub trait FormatService { - fn format(&mut self, req: super::rustfmt::FormatRequest) -> grpc::Result; -} - -// Oak Node gRPC method dispatcher -pub struct Dispatcher(T); - -impl Dispatcher { - pub fn new(node: T) -> Dispatcher { - Dispatcher(node) - } -} - -impl grpc::ServerNode for Dispatcher { - fn invoke(&mut self, method: &str, req: &[u8], writer: grpc::ChannelResponseWriter) { - match method { - "/oak.examples.rustfmt.FormatService/Format" => grpc::handle_req_rsp(|r| self.0.format(r), req, writer), - _ => { - error!("unknown method name: {}", method); - } - }; - } -} - -// Client interface -pub struct FormatServiceClient(pub oak::grpc::client::Client); - -impl FormatServiceClient { - pub fn format(&self, req: super::rustfmt::FormatRequest) -> grpc::Result { - oak::grpc::invoke_grpc_method("/oak.examples.rustfmt.FormatService/Format", &req, Some("type.googleapis.com/oak.examples.rustfmt.FormatRequest"), &self.0.invocation_sender) - } -} diff --git a/examples/translator/common/Cargo.toml b/examples/translator/common/Cargo.toml index dfab3edbbc4..53588629812 100644 --- a/examples/translator/common/Cargo.toml +++ b/examples/translator/common/Cargo.toml @@ -7,8 +7,7 @@ edition = "2018" [dependencies] log = "*" oak = "=0.1.0" -protobuf = "*" +prost = "*" [build-dependencies] oak_utils = "*" -protoc-rust-grpc = { path = "../../../third_party/grpc-rust/protoc-rust-grpc" } diff --git a/examples/translator/common/build.rs b/examples/translator/common/build.rs index 51973064fc3..016c2bdad60 100644 --- a/examples/translator/common/build.rs +++ b/examples/translator/common/build.rs @@ -15,12 +15,8 @@ // fn main() { - oak_utils::run_protoc_rust_grpc(protoc_rust_grpc::Args { - out_dir: "src/proto", - input: &["../proto/translator.proto"], - includes: &["../proto", "../third_party"], - rust_protobuf: true, // also generate protobuf messages, not just services - ..Default::default() - }) - .expect("protoc-rust-grpc"); + oak_utils::compile_protos( + &["../proto/translator.proto"], + &["../proto", "../third_party"], + ); } diff --git a/examples/translator/common/src/lib.rs b/examples/translator/common/src/lib.rs index ba79615e123..ae793821d3a 100644 --- a/examples/translator/common/src/lib.rs +++ b/examples/translator/common/src/lib.rs @@ -14,11 +14,13 @@ // limitations under the License. // -pub mod proto; +pub mod proto { + include!(concat!(env!("OUT_DIR"), "/oak.examples.translator.rs")); +} use log::{info, warn}; -use proto::translator::TranslateRequest; -pub use proto::translator_grpc::TranslatorClient; +use proto::TranslateRequest; +pub use proto::TranslatorClient; pub fn translate( client: &TranslatorClient, @@ -30,7 +32,7 @@ pub fn translate( "attempt to translate '{}' from {} to {}", text, from_lang, to_lang ); - let mut req = TranslateRequest::new(); + let mut req = TranslateRequest::default(); req.text = text.to_string(); req.from_lang = from_lang.to_string(); req.to_lang = to_lang.to_string(); diff --git a/examples/translator/common/src/proto/mod.rs b/examples/translator/common/src/proto/mod.rs deleted file mode 100644 index ca884f2382d..00000000000 --- a/examples/translator/common/src/proto/mod.rs +++ /dev/null @@ -1,18 +0,0 @@ -// -// Copyright 2019 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. -// - -pub mod translator; -pub mod translator_grpc; diff --git a/examples/translator/common/src/proto/translator.rs b/examples/translator/common/src/proto/translator.rs deleted file mode 100644 index 95c5378d12e..00000000000 --- a/examples/translator/common/src/proto/translator.rs +++ /dev/null @@ -1,477 +0,0 @@ -// This file is generated by rust-protobuf 2.10.1. Do not edit -// @generated - -// https://github.com/rust-lang/rust-clippy/issues/702 -#![allow(unknown_lints)] -#![allow(clippy::all)] - -#![cfg_attr(rustfmt, rustfmt_skip)] - -#![allow(box_pointers)] -#![allow(dead_code)] -#![allow(missing_docs)] -#![allow(non_camel_case_types)] -#![allow(non_snake_case)] -#![allow(non_upper_case_globals)] -#![allow(trivial_casts)] -#![allow(unsafe_code)] -#![allow(unused_imports)] -#![allow(unused_results)] -//! Generated file from `translator.proto` - -use protobuf::Message as Message_imported_for_functions; -use protobuf::ProtobufEnum as ProtobufEnum_imported_for_functions; - -/// Generated files are compatible only with the same version -/// of protobuf runtime. -// const _PROTOBUF_VERSION_CHECK: () = ::protobuf::VERSION_2_10_1; - -#[derive(PartialEq,Clone,Default)] -pub struct TranslateRequest { - // message fields - pub text: ::std::string::String, - pub from_lang: ::std::string::String, - pub to_lang: ::std::string::String, - // special fields - pub unknown_fields: ::protobuf::UnknownFields, - pub cached_size: ::protobuf::CachedSize, -} - -impl<'a> ::std::default::Default for &'a TranslateRequest { - fn default() -> &'a TranslateRequest { - ::default_instance() - } -} - -impl TranslateRequest { - pub fn new() -> TranslateRequest { - ::std::default::Default::default() - } - - // string text = 1; - - - pub fn get_text(&self) -> &str { - &self.text - } - pub fn clear_text(&mut self) { - self.text.clear(); - } - - // Param is passed by value, moved - pub fn set_text(&mut self, v: ::std::string::String) { - self.text = v; - } - - // Mutable pointer to the field. - // If field is not initialized, it is initialized with default value first. - pub fn mut_text(&mut self) -> &mut ::std::string::String { - &mut self.text - } - - // Take field - pub fn take_text(&mut self) -> ::std::string::String { - ::std::mem::replace(&mut self.text, ::std::string::String::new()) - } - - // string from_lang = 2; - - - pub fn get_from_lang(&self) -> &str { - &self.from_lang - } - pub fn clear_from_lang(&mut self) { - self.from_lang.clear(); - } - - // Param is passed by value, moved - pub fn set_from_lang(&mut self, v: ::std::string::String) { - self.from_lang = v; - } - - // Mutable pointer to the field. - // If field is not initialized, it is initialized with default value first. - pub fn mut_from_lang(&mut self) -> &mut ::std::string::String { - &mut self.from_lang - } - - // Take field - pub fn take_from_lang(&mut self) -> ::std::string::String { - ::std::mem::replace(&mut self.from_lang, ::std::string::String::new()) - } - - // string to_lang = 3; - - - pub fn get_to_lang(&self) -> &str { - &self.to_lang - } - pub fn clear_to_lang(&mut self) { - self.to_lang.clear(); - } - - // Param is passed by value, moved - pub fn set_to_lang(&mut self, v: ::std::string::String) { - self.to_lang = v; - } - - // Mutable pointer to the field. - // If field is not initialized, it is initialized with default value first. - pub fn mut_to_lang(&mut self) -> &mut ::std::string::String { - &mut self.to_lang - } - - // Take field - pub fn take_to_lang(&mut self) -> ::std::string::String { - ::std::mem::replace(&mut self.to_lang, ::std::string::String::new()) - } -} - -impl ::protobuf::Message for TranslateRequest { - fn is_initialized(&self) -> bool { - true - } - - fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> { - while !is.eof()? { - let (field_number, wire_type) = is.read_tag_unpack()?; - match field_number { - 1 => { - ::protobuf::rt::read_singular_proto3_string_into(wire_type, is, &mut self.text)?; - }, - 2 => { - ::protobuf::rt::read_singular_proto3_string_into(wire_type, is, &mut self.from_lang)?; - }, - 3 => { - ::protobuf::rt::read_singular_proto3_string_into(wire_type, is, &mut self.to_lang)?; - }, - _ => { - ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; - }, - }; - } - ::std::result::Result::Ok(()) - } - - // Compute sizes of nested messages - #[allow(unused_variables)] - fn compute_size(&self) -> u32 { - let mut my_size = 0; - if !self.text.is_empty() { - my_size += ::protobuf::rt::string_size(1, &self.text); - } - if !self.from_lang.is_empty() { - my_size += ::protobuf::rt::string_size(2, &self.from_lang); - } - if !self.to_lang.is_empty() { - my_size += ::protobuf::rt::string_size(3, &self.to_lang); - } - my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); - self.cached_size.set(my_size); - my_size - } - - fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { - if !self.text.is_empty() { - os.write_string(1, &self.text)?; - } - if !self.from_lang.is_empty() { - os.write_string(2, &self.from_lang)?; - } - if !self.to_lang.is_empty() { - os.write_string(3, &self.to_lang)?; - } - os.write_unknown_fields(self.get_unknown_fields())?; - ::std::result::Result::Ok(()) - } - - fn get_cached_size(&self) -> u32 { - self.cached_size.get() - } - - fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { - &self.unknown_fields - } - - fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { - &mut self.unknown_fields - } - - fn as_any(&self) -> &dyn (::std::any::Any) { - self as &dyn (::std::any::Any) - } - fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { - self as &mut dyn (::std::any::Any) - } - fn into_any(self: Box) -> ::std::boxed::Box { - self - } - - fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { - Self::descriptor_static() - } - - fn new() -> TranslateRequest { - TranslateRequest::new() - } - - fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor { - static mut descriptor: ::protobuf::lazy::Lazy<::protobuf::reflect::MessageDescriptor> = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const ::protobuf::reflect::MessageDescriptor, - }; - unsafe { - descriptor.get(|| { - let mut fields = ::std::vec::Vec::new(); - fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeString>( - "text", - |m: &TranslateRequest| { &m.text }, - |m: &mut TranslateRequest| { &mut m.text }, - )); - fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeString>( - "from_lang", - |m: &TranslateRequest| { &m.from_lang }, - |m: &mut TranslateRequest| { &mut m.from_lang }, - )); - fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeString>( - "to_lang", - |m: &TranslateRequest| { &m.to_lang }, - |m: &mut TranslateRequest| { &mut m.to_lang }, - )); - ::protobuf::reflect::MessageDescriptor::new::( - "TranslateRequest", - fields, - file_descriptor_proto() - ) - }) - } - } - - fn default_instance() -> &'static TranslateRequest { - static mut instance: ::protobuf::lazy::Lazy = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const TranslateRequest, - }; - unsafe { - instance.get(TranslateRequest::new) - } - } -} - -impl ::protobuf::Clear for TranslateRequest { - fn clear(&mut self) { - self.text.clear(); - self.from_lang.clear(); - self.to_lang.clear(); - self.unknown_fields.clear(); - } -} - -impl ::std::fmt::Debug for TranslateRequest { - fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { - ::protobuf::text_format::fmt(self, f) - } -} - -impl ::protobuf::reflect::ProtobufValue for TranslateRequest { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { - ::protobuf::reflect::ProtobufValueRef::Message(self) - } -} - -#[derive(PartialEq,Clone,Default)] -pub struct TranslateResponse { - // message fields - pub translated_text: ::std::string::String, - // special fields - pub unknown_fields: ::protobuf::UnknownFields, - pub cached_size: ::protobuf::CachedSize, -} - -impl<'a> ::std::default::Default for &'a TranslateResponse { - fn default() -> &'a TranslateResponse { - ::default_instance() - } -} - -impl TranslateResponse { - pub fn new() -> TranslateResponse { - ::std::default::Default::default() - } - - // string translated_text = 1; - - - pub fn get_translated_text(&self) -> &str { - &self.translated_text - } - pub fn clear_translated_text(&mut self) { - self.translated_text.clear(); - } - - // Param is passed by value, moved - pub fn set_translated_text(&mut self, v: ::std::string::String) { - self.translated_text = v; - } - - // Mutable pointer to the field. - // If field is not initialized, it is initialized with default value first. - pub fn mut_translated_text(&mut self) -> &mut ::std::string::String { - &mut self.translated_text - } - - // Take field - pub fn take_translated_text(&mut self) -> ::std::string::String { - ::std::mem::replace(&mut self.translated_text, ::std::string::String::new()) - } -} - -impl ::protobuf::Message for TranslateResponse { - fn is_initialized(&self) -> bool { - true - } - - fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> { - while !is.eof()? { - let (field_number, wire_type) = is.read_tag_unpack()?; - match field_number { - 1 => { - ::protobuf::rt::read_singular_proto3_string_into(wire_type, is, &mut self.translated_text)?; - }, - _ => { - ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; - }, - }; - } - ::std::result::Result::Ok(()) - } - - // Compute sizes of nested messages - #[allow(unused_variables)] - fn compute_size(&self) -> u32 { - let mut my_size = 0; - if !self.translated_text.is_empty() { - my_size += ::protobuf::rt::string_size(1, &self.translated_text); - } - my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); - self.cached_size.set(my_size); - my_size - } - - fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { - if !self.translated_text.is_empty() { - os.write_string(1, &self.translated_text)?; - } - os.write_unknown_fields(self.get_unknown_fields())?; - ::std::result::Result::Ok(()) - } - - fn get_cached_size(&self) -> u32 { - self.cached_size.get() - } - - fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { - &self.unknown_fields - } - - fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { - &mut self.unknown_fields - } - - fn as_any(&self) -> &dyn (::std::any::Any) { - self as &dyn (::std::any::Any) - } - fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { - self as &mut dyn (::std::any::Any) - } - fn into_any(self: Box) -> ::std::boxed::Box { - self - } - - fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { - Self::descriptor_static() - } - - fn new() -> TranslateResponse { - TranslateResponse::new() - } - - fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor { - static mut descriptor: ::protobuf::lazy::Lazy<::protobuf::reflect::MessageDescriptor> = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const ::protobuf::reflect::MessageDescriptor, - }; - unsafe { - descriptor.get(|| { - let mut fields = ::std::vec::Vec::new(); - fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeString>( - "translated_text", - |m: &TranslateResponse| { &m.translated_text }, - |m: &mut TranslateResponse| { &mut m.translated_text }, - )); - ::protobuf::reflect::MessageDescriptor::new::( - "TranslateResponse", - fields, - file_descriptor_proto() - ) - }) - } - } - - fn default_instance() -> &'static TranslateResponse { - static mut instance: ::protobuf::lazy::Lazy = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const TranslateResponse, - }; - unsafe { - instance.get(TranslateResponse::new) - } - } -} - -impl ::protobuf::Clear for TranslateResponse { - fn clear(&mut self) { - self.translated_text.clear(); - self.unknown_fields.clear(); - } -} - -impl ::std::fmt::Debug for TranslateResponse { - fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { - ::protobuf::text_format::fmt(self, f) - } -} - -impl ::protobuf::reflect::ProtobufValue for TranslateResponse { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { - ::protobuf::reflect::ProtobufValueRef::Message(self) - } -} - -static file_descriptor_proto_data: &'static [u8] = b"\ - \n\x10translator.proto\x12\x17oak.examples.translator\"\\\n\x10Translate\ - Request\x12\x12\n\x04text\x18\x01\x20\x01(\tR\x04text\x12\x1b\n\tfrom_la\ - ng\x18\x02\x20\x01(\tR\x08fromLang\x12\x17\n\x07to_lang\x18\x03\x20\x01(\ - \tR\x06toLang\"<\n\x11TranslateResponse\x12'\n\x0ftranslated_text\x18\ - \x01\x20\x01(\tR\x0etranslatedText2p\n\nTranslator\x12b\n\tTranslate\x12\ - ).oak.examples.translator.TranslateRequest\x1a*.oak.examples.translator.\ - TranslateResponseB6Z4github.com/project-oak/oak/examples/translator/prot\ - ob\x06proto3\ -"; - -static mut file_descriptor_proto_lazy: ::protobuf::lazy::Lazy<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const ::protobuf::descriptor::FileDescriptorProto, -}; - -fn parse_descriptor_proto() -> ::protobuf::descriptor::FileDescriptorProto { - ::protobuf::parse_from_bytes(file_descriptor_proto_data).unwrap() -} - -pub fn file_descriptor_proto() -> &'static ::protobuf::descriptor::FileDescriptorProto { - unsafe { - file_descriptor_proto_lazy.get(|| { - parse_descriptor_proto() - }) - } -} diff --git a/examples/translator/common/src/proto/translator_grpc.rs b/examples/translator/common/src/proto/translator_grpc.rs deleted file mode 100644 index d05902044c8..00000000000 --- a/examples/translator/common/src/proto/translator_grpc.rs +++ /dev/null @@ -1,59 +0,0 @@ -// This file is generated. Do not edit -// @generated - -// https://github.com/rust-lang/rust-clippy/issues/702 -#![allow(unknown_lints)] -#![allow(clippy::all)] - -#![cfg_attr(rustfmt, rustfmt_skip)] - -#![allow(box_pointers)] -#![allow(dead_code)] -#![allow(missing_docs)] -#![allow(non_camel_case_types)] -#![allow(non_snake_case)] -#![allow(non_upper_case_globals)] -#![allow(trivial_casts)] -#![allow(unsafe_code)] -#![allow(unused_imports)] -#![allow(unused_results)] - - -use oak::grpc; -use protobuf::Message; -use std::io::Write; -use log::error; - -// Oak Node server interface -pub trait Translator { - fn translate(&mut self, req: super::translator::TranslateRequest) -> grpc::Result; -} - -// Oak Node gRPC method dispatcher -pub struct Dispatcher(T); - -impl Dispatcher { - pub fn new(node: T) -> Dispatcher { - Dispatcher(node) - } -} - -impl grpc::ServerNode for Dispatcher { - fn invoke(&mut self, method: &str, req: &[u8], writer: grpc::ChannelResponseWriter) { - match method { - "/oak.examples.translator.Translator/Translate" => grpc::handle_req_rsp(|r| self.0.translate(r), req, writer), - _ => { - error!("unknown method name: {}", method); - } - }; - } -} - -// Client interface -pub struct TranslatorClient(pub oak::grpc::client::Client); - -impl TranslatorClient { - pub fn translate(&self, req: super::translator::TranslateRequest) -> grpc::Result { - oak::grpc::invoke_grpc_method("/oak.examples.translator.Translator/Translate", &req, Some("type.googleapis.com/oak.examples.translator.TranslateRequest"), &self.0.invocation_sender) - } -} diff --git a/examples/translator/module/rust/Cargo.toml b/examples/translator/module/rust/Cargo.toml index dd0476cf3e2..49e11ef47ee 100644 --- a/examples/translator/module/rust/Cargo.toml +++ b/examples/translator/module/rust/Cargo.toml @@ -16,5 +16,5 @@ simple_logger = "*" [dependencies] log = "*" oak = "=0.1.0" -protobuf = "*" +prost = "*" translator_common = "=0.1.0" diff --git a/examples/translator/module/rust/src/lib.rs b/examples/translator/module/rust/src/lib.rs index bcbd7da6e9e..4d89aabdae6 100644 --- a/examples/translator/module/rust/src/lib.rs +++ b/examples/translator/module/rust/src/lib.rs @@ -19,12 +19,13 @@ mod tests; use log::info; use oak::grpc; -use translator_common::proto::translator::{TranslateRequest, TranslateResponse}; -use translator_common::proto::translator_grpc::{Dispatcher, Translator}; +use translator_common::proto::{ + TranslateRequest, TranslateResponse, Translator, TranslatorDispatcher, +}; oak::entrypoint!(oak_main => { oak::logger::init_default(); - Dispatcher::new(Node) + TranslatorDispatcher::new(Node) }); struct Node; @@ -35,7 +36,7 @@ impl Translator for Node { "attempt to translate '{}' from {} to {}", req.text, req.from_lang, req.to_lang ); - let mut rsp = TranslateResponse::new(); + let mut rsp = TranslateResponse::default(); rsp.translated_text = match req.from_lang.as_str() { "en" => match req.text.as_str() { "WORLDS" => match req.to_lang.as_str() { @@ -44,7 +45,7 @@ impl Translator for Node { _ => { info!("output language {} not found", req.to_lang); return Err(grpc::build_status( - grpc::Code::NOT_FOUND, + grpc::Code::NotFound, "Output language not found", )); } @@ -55,7 +56,7 @@ impl Translator for Node { req.text, req.from_lang ); return Err(grpc::build_status( - grpc::Code::NOT_FOUND, + grpc::Code::NotFound, "Input text unrecognized", )); } @@ -63,7 +64,7 @@ impl Translator for Node { _ => { info!("input language '{}' not recognized", req.from_lang); return Err(grpc::build_status( - grpc::Code::NOT_FOUND, + grpc::Code::NotFound, "Input language unrecognized", )); } diff --git a/examples/translator/module/rust/src/tests.rs b/examples/translator/module/rust/src/tests.rs index e99c11b569c..74f8b400b36 100644 --- a/examples/translator/module/rust/src/tests.rs +++ b/examples/translator/module/rust/src/tests.rs @@ -16,7 +16,7 @@ use assert_matches::assert_matches; use oak::grpc; -use translator_common::proto::translator::{TranslateRequest, TranslateResponse}; +use translator_common::proto::{TranslateRequest, TranslateResponse}; const MODULE_CONFIG_NAME: &str = "translator"; @@ -31,7 +31,6 @@ fn test_translate() { text: "WORLDS".into(), from_lang: "en".into(), to_lang: "it".into(), - ..Default::default() }; let result: grpc::Result = oak_tests::grpc_request( &runtime, diff --git a/oak/server/rust/oak_abi/build.rs b/oak/server/rust/oak_abi/build.rs index dc86ed7ebbe..95d6718ae66 100644 --- a/oak/server/rust/oak_abi/build.rs +++ b/oak/server/rust/oak_abi/build.rs @@ -14,22 +14,12 @@ // limitations under the License. // -use std::path; - fn main() { - let proto_files = vec!["oak_abi.proto", "label.proto"]; - - let proto_dir = path::Path::new("../../../../oak/proto/").to_path_buf(); - let proto_paths: Vec = proto_files.iter().map(|f| proto_dir.join(f)).collect(); - - // Tell Cargo that if any of the given files change, to rerun this build script. - // https://doc.rust-lang.org/cargo/reference/build-scripts.html#rerun-if-changed - for path in &proto_paths { - println!("cargo:rerun-if-changed={}", path.to_str().unwrap()); - } - - prost_build::Config::new() - .type_attribute(".oak.label", "#[derive(Eq,Hash)]") - .compile_protos(&proto_paths, &[proto_dir]) - .unwrap(); + oak_utils::compile_protos( + &[ + "../../../../oak/proto/oak_abi.proto", + "../../../../oak/proto/label.proto", + ], + &["../../../../oak/proto"], + ); } diff --git a/oak/server/rust/oak_runtime/Cargo.toml b/oak/server/rust/oak_runtime/Cargo.toml index b20c5257b2e..8392901be1e 100644 --- a/oak/server/rust/oak_runtime/Cargo.toml +++ b/oak/server/rust/oak_runtime/Cargo.toml @@ -21,7 +21,7 @@ log = { version = "*" } oak = "0.1.0" oak_abi = "=0.1.0" prost = "*" -protobuf = "*" +prost-types = "*" rand = { version = "*", default-features = false, features = ["alloc"] } tokio = { version = "*", features = ["rt-core"] } wasmi = { version = "*", default-features = false, features = ["core"] } diff --git a/oak/server/rust/oak_runtime/build.rs b/oak/server/rust/oak_runtime/build.rs index 1a7ecf92f63..f3139b4667c 100644 --- a/oak/server/rust/oak_runtime/build.rs +++ b/oak/server/rust/oak_runtime/build.rs @@ -14,22 +14,12 @@ // limitations under the License. // -use std::path; - fn main() { - let proto_files = vec!["application.proto", "log.proto"]; - - let proto_dir = path::Path::new("../../../../oak/proto/").to_path_buf(); - let proto_paths: Vec = proto_files.iter().map(|f| proto_dir.join(f)).collect(); - - // Tell Cargo that if any of the given files change, to rerun this build script. - // https://doc.rust-lang.org/cargo/reference/build-scripts.html#rerun-if-changed - for path in &proto_paths { - println!("cargo:rerun-if-changed={}", path.to_str().unwrap()); - } - - prost_build::Config::new() - .type_attribute(".oak.label", "#[derive(Eq,Hash)]") - .compile_protos(&proto_paths, &[proto_dir]) - .unwrap(); + oak_utils::compile_protos( + &[ + "../../../../oak/proto/application.proto", + "../../../../oak/proto/log.proto", + ], + &["../../../../oak/proto"], + ); } diff --git a/oak/server/rust/oak_runtime/src/node/grpc_server.rs b/oak/server/rust/oak_runtime/src/node/grpc_server.rs index 7ba319ab0dd..7d6e4e4cc32 100644 --- a/oak/server/rust/oak_runtime/src/node/grpc_server.rs +++ b/oak/server/rust/oak_runtime/src/node/grpc_server.rs @@ -15,7 +15,8 @@ // use log::{error, info, warn}; -use protobuf::{well_known_types::Any, Message}; +use prost::Message; +use prost_types::Any; use std::{ fmt::{self, Display, Formatter}, net::SocketAddr, @@ -184,12 +185,11 @@ impl GrpcServerNode { http_request_path: &str, http_request_body: &dyn hyper::body::Buf, ) -> Result { - // Parse an HTTP request body as a [`protobuf::well_known_types::Any`] message. - let grpc_request_body = protobuf::parse_from_bytes::(http_request_body.bytes()) - .map_err(|error| { - error!("Failed to parse Protobuf message {}", error); - GrpcServerError::BadProtobufMessage - })?; + // Parse an HTTP request body as an [`Any`] message. + let grpc_request_body = Any::decode(http_request_body.bytes()).map_err(|error| { + error!("Failed to parse Protobuf message {}", error); + GrpcServerError::BadProtobufMessage + })?; // Create a gRPC request. encap_request(&grpc_request_body, None, http_request_path).ok_or_else(|| { @@ -229,12 +229,10 @@ impl GrpcServerNode { data: vec![], channels: vec![], }; - request - .write_to_writer(&mut message.data) - .map_err(|error| { - error!("Couldn't serialize a GrpcRequest message: {}", error); - GrpcServerError::RequestProcessingError - })?; + request.encode(&mut message.data).map_err(|error| { + error!("Couldn't serialize a GrpcRequest message: {}", error); + GrpcServerError::RequestProcessingError + })?; // Send a message to the temporary channel. self.runtime diff --git a/sdk/rust/oak/Cargo.toml b/sdk/rust/oak/Cargo.toml index f10ffb3baeb..6d14ef4587c 100644 --- a/sdk/rust/oak/Cargo.toml +++ b/sdk/rust/oak/Cargo.toml @@ -7,7 +7,8 @@ license = "Apache-2.0" [dependencies] oak_abi = "=0.1.0" -protobuf = "*" +prost = "*" +prost-types = "*" fmt = "*" log = { version = "*", features = ["std"] } byteorder = "*" @@ -16,7 +17,6 @@ serde = { version = "*", features = ["derive"] } [build-dependencies] oak_utils = "*" -protoc-rust = "*" [dev-dependencies] assert_matches = "*" diff --git a/sdk/rust/oak/build.rs b/sdk/rust/oak/build.rs index 0d73523ff3b..997f256c485 100644 --- a/sdk/rust/oak/build.rs +++ b/sdk/rust/oak/build.rs @@ -15,9 +15,8 @@ // fn main() { - oak_utils::run_protoc_rust(protoc_rust::Args { - out_dir: "src/proto", - input: &[ + oak_utils::compile_protos( + &[ "../../../third_party/google/rpc/code.proto", "../../../third_party/google/rpc/status.proto", "../../../oak/proto/grpc_encap.proto", @@ -26,8 +25,6 @@ fn main() { "../../../oak/proto/storage_channel.proto", "../../../oak/proto/log.proto", ], - includes: &["../../.."], - customize: protoc_rust::Customize::default(), - }) - .expect("protoc"); + &["../../.."], + ); } diff --git a/sdk/rust/oak/src/error.rs b/sdk/rust/oak/src/error.rs index a824200156d..a055d1baa08 100644 --- a/sdk/rust/oak/src/error.rs +++ b/sdk/rust/oak/src/error.rs @@ -17,7 +17,8 @@ /// Generic Oak error. #[derive(Debug)] pub enum OakError { - ProtobufError(protobuf::ProtobufError), + ProtobufDecodeError(Option), + ProtobufEncodeError(Option), OakStatus(crate::OakStatus), IoError(std::io::Error), } @@ -25,7 +26,8 @@ pub enum OakError { impl std::fmt::Display for OakError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { - OakError::ProtobufError(e) => write!(f, "protobuf error: {}", e), + OakError::ProtobufDecodeError(e) => write!(f, "protobuf decode error: {:?}", e), + OakError::ProtobufEncodeError(e) => write!(f, "protobuf encode error: {:?}", e), OakError::OakStatus(e) => write!(f, "Oak status value: {:?}", e), OakError::IoError(e) => write!(f, "I/O error: {}", e), } @@ -34,9 +36,15 @@ impl std::fmt::Display for OakError { impl std::error::Error for OakError {} -impl From for OakError { - fn from(err: protobuf::ProtobufError) -> Self { - OakError::ProtobufError(err) +impl From for OakError { + fn from(err: prost::DecodeError) -> Self { + OakError::ProtobufDecodeError(Some(err)) + } +} + +impl From for OakError { + fn from(err: prost::EncodeError) -> Self { + OakError::ProtobufEncodeError(Some(err)) } } diff --git a/sdk/rust/oak/src/grpc/invocation.rs b/sdk/rust/oak/src/grpc/invocation.rs index 8fa3aaa5130..8cb01aa2457 100644 --- a/sdk/rust/oak/src/grpc/invocation.rs +++ b/sdk/rust/oak/src/grpc/invocation.rs @@ -17,8 +17,8 @@ /// 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, - pub response_sender: crate::io::Sender, + pub request_receiver: crate::io::Receiver, + pub response_sender: crate::io::Sender, } // TODO(#389): Automatically generate this code. diff --git a/sdk/rust/oak/src/grpc/mod.rs b/sdk/rust/oak/src/grpc/mod.rs index fe4e14ac774..4cd67a404a6 100644 --- a/sdk/rust/oak/src/grpc/mod.rs +++ b/sdk/rust/oak/src/grpc/mod.rs @@ -16,25 +16,25 @@ //! Functionality to help Oak Nodes interact with gRPC. -pub use crate::proto::code::Code; +pub use crate::proto::google::rpc::Code; use crate::{proto, OakError, OakStatus}; use log::{error, warn}; -pub use proto::grpc_encap::{GrpcRequest, GrpcResponse}; -use protobuf::ProtobufEnum; +pub use proto::oak::{GrpcRequest, GrpcResponse}; pub mod client; mod invocation; pub use invocation::Invocation; /// Result type that uses a [`proto::status::Status`] type for error values. -pub type Result = std::result::Result; +pub type Result = std::result::Result; /// Helper to create a gRPC status object. -pub fn build_status(code: Code, msg: &str) -> proto::status::Status { - let mut status = proto::status::Status::new(); - status.set_code(code.value()); - status.set_message(msg.to_string()); - status +pub fn build_status(code: Code, msg: &str) -> proto::google::rpc::Status { + proto::google::rpc::Status { + code: code as i32, + message: msg.to_owned(), + details: vec![], + } } /// Channel-holding object that encapsulates response messages into @@ -64,21 +64,21 @@ impl ChannelResponseWriter { /// Write out a gRPC response and optionally close out the method /// invocation. Any errors from the channel are silently dropped. - pub fn write( + pub fn write( &mut self, rsp: &T, mode: WriteMode, ) -> std::result::Result<(), OakError> { // Put the serialized response into a GrpcResponse message wrapper and // serialize it into the channel. - let mut grpc_rsp = GrpcResponse::new(); - let mut any = protobuf::well_known_types::Any::new(); - rsp.write_to_writer(&mut any.value)?; - grpc_rsp.set_rsp_msg(any); - grpc_rsp.set_last(match mode { + let mut grpc_rsp = GrpcResponse::default(); + let mut any = prost_types::Any::default(); + rsp.encode(&mut any.value)?; + grpc_rsp.rsp_msg = Some(any); + grpc_rsp.last = match mode { WriteMode::KeepOpen => false, WriteMode::Close => true, - }); + }; self.sender.send(&grpc_rsp)?; if mode == WriteMode::Close { self.sender.close()?; @@ -89,12 +89,12 @@ impl ChannelResponseWriter { /// Write an empty gRPC response and optionally close out the method /// invocation. Any errors from the channel are silently dropped. pub fn write_empty(&mut self, mode: WriteMode) -> std::result::Result<(), OakError> { - let mut grpc_rsp = GrpcResponse::new(); - grpc_rsp.set_rsp_msg(protobuf::well_known_types::Any::new()); - grpc_rsp.set_last(match mode { + let mut grpc_rsp = GrpcResponse::default(); + grpc_rsp.rsp_msg = Some(prost_types::Any::default()); + grpc_rsp.last = match mode { WriteMode::KeepOpen => false, WriteMode::Close => true, - }); + }; self.sender.send(&grpc_rsp)?; if mode == WriteMode::Close { self.sender.close()?; @@ -106,10 +106,10 @@ impl ChannelResponseWriter { pub fn close(&mut self, result: Result<()>) -> std::result::Result<(), OakError> { // Build a final GrpcResponse message wrapper and serialize it into the // channel. - let mut grpc_rsp = GrpcResponse::new(); - grpc_rsp.set_last(true); + let mut grpc_rsp = GrpcResponse::default(); + grpc_rsp.last = true; if let Err(status) = result { - grpc_rsp.set_status(status); + grpc_rsp.status = Some(status); } self.sender.send(&grpc_rsp)?; self.sender.close()?; @@ -159,7 +159,10 @@ impl crate::Node for T { } self.invoke( &req.method_name, - req.get_req_msg().value.as_slice(), + req.req_msg + .map(|any| any.value) + .unwrap_or_default() + .as_slice(), ChannelResponseWriter::new(invocation.response_sender), ); Ok(()) @@ -168,41 +171,43 @@ impl crate::Node for T { /// Encapsulate a protocol buffer message in a GrpcRequest wrapper using the /// given method name. -pub fn encap_request( +pub fn encap_request( req: &T, req_type_url: Option<&str>, method_name: &str, ) -> Option { // Put the request in a GrpcRequest wrapper and serialize it. - let mut grpc_req = GrpcRequest::new(); - grpc_req.set_method_name(method_name.to_string()); - let mut any = protobuf::well_known_types::Any::new(); - if let Err(e) = req.write_to_writer(&mut any.value) { + let mut grpc_req = GrpcRequest::default(); + grpc_req.method_name = method_name.to_string(); + let mut any = prost_types::Any::default(); + if let Err(e) = req.encode(&mut any.value) { warn!("failed to serialize gRPC request: {}", e); return None; }; if let Some(type_url) = req_type_url { - any.set_type_url(type_url.to_string()); + any.type_url = type_url.to_string(); } - grpc_req.set_req_msg(any); - grpc_req.set_last(true); + grpc_req.req_msg = Some(any); + grpc_req.last = true; Some(grpc_req) } /// Extract a protocol buffer message from a GrpcResponse wrapper. /// Returns the message together with an indicator of whether this is the last /// response. -pub fn decap_response(mut grpc_rsp: GrpcResponse) -> Result<(T, bool)> { - if grpc_rsp.get_status().get_code() != Code::OK.value() { - return Err(grpc_rsp.take_status()); +pub fn decap_response(grpc_rsp: GrpcResponse) -> Result<(T, bool)> { + let status = grpc_rsp.status.unwrap_or_default(); + if status.code != Code::Ok as i32 { + return Err(status); } - let rsp = protobuf::parse_from_bytes(&grpc_rsp.get_rsp_msg().value).map_err(|proto_err| { + let bytes = grpc_rsp.rsp_msg.unwrap_or_default().value; + let rsp = T::decode(bytes.as_slice()).map_err(|proto_err| { build_status( - Code::INVALID_ARGUMENT, + Code::InvalidArgument, &format!("message parsing failed: {}", proto_err), ) })?; - Ok((rsp, grpc_rsp.get_last())) + Ok((rsp, grpc_rsp.last)) } /// Helper to inject a (single) gRPC request message via a notification channel, @@ -215,7 +220,7 @@ pub fn invoke_grpc_method_stream( invocation_channel: &crate::io::Sender, ) -> Result> where - R: protobuf::Message, + R: prost::Message, { // Create a new channel for request message delivery. let (req_sender, req_receiver) = @@ -257,8 +262,8 @@ pub fn invoke_grpc_method( invocation_channel: &crate::io::Sender, ) -> Result where - R: protobuf::Message, - Q: protobuf::Message, + R: prost::Message, + Q: prost::Message + Default, { let rsp_receiver = invoke_grpc_method_stream(method_name, req, req_type_url, invocation_channel)?; @@ -268,7 +273,7 @@ where let grpc_rsp = result.map_err(|status| { error!("failed to receive response: {:?}", status); build_status( - Code::INTERNAL, + Code::Internal, &format!("failed to receive gRPC response: {:?}", status), ) })?; @@ -285,10 +290,10 @@ where pub fn handle_req_rsp(mut node_fn: C, req: &[u8], mut writer: ChannelResponseWriter) where C: FnMut(R) -> Result, - R: protobuf::Message, - Q: protobuf::Message, + R: prost::Message + Default, + Q: prost::Message, { - let r: R = protobuf::parse_from_bytes(&req).expect("Failed to parse request protobuf message"); + let r = R::decode(req).expect("Failed to parse request protobuf message"); let result = match node_fn(r) { Ok(rsp) => writer.write(&rsp, WriteMode::Close), Err(status) => writer.close(Err(status)), @@ -306,9 +311,9 @@ where pub fn handle_req_stream(mut node_fn: C, req: &[u8], writer: ChannelResponseWriter) where C: FnMut(R, ChannelResponseWriter), - R: protobuf::Message, + R: prost::Message + Default, { - let r: R = protobuf::parse_from_bytes(&req).expect("Failed to parse request protobuf message"); + let r = R::decode(req).expect("Failed to parse request protobuf message"); node_fn(r, writer) } @@ -320,12 +325,11 @@ where pub fn handle_stream_rsp(mut node_fn: C, req: &[u8], mut writer: ChannelResponseWriter) where C: FnMut(Vec) -> Result, - R: protobuf::Message, - Q: protobuf::Message, + R: prost::Message + Default, + Q: prost::Message + Default, { // TODO(#97): better client-side streaming - let rr: Vec = - vec![protobuf::parse_from_bytes(&req).expect("Failed to parse request protobuf message")]; + let rr = vec![R::decode(req).expect("Failed to parse request protobuf message")]; let result = match node_fn(rr) { Ok(rsp) => writer.write(&rsp, WriteMode::Close), Err(status) => writer.close(Err(status)), @@ -343,11 +347,10 @@ where pub fn handle_stream_stream(mut node_fn: C, req: &[u8], writer: ChannelResponseWriter) where C: FnMut(Vec, ChannelResponseWriter), - R: protobuf::Message, + R: prost::Message + Default, { // TODO(#97): better client-side streaming - let rr: Vec = - vec![protobuf::parse_from_bytes(&req).expect("Failed to parse request protobuf message")]; + let rr = vec![R::decode(req).expect("Failed to parse request protobuf message")]; node_fn(rr, writer) } diff --git a/sdk/rust/oak/src/io/decodable.rs b/sdk/rust/oak/src/io/decodable.rs index c615de6ca14..c823d5111be 100644 --- a/sdk/rust/oak/src/io/decodable.rs +++ b/sdk/rust/oak/src/io/decodable.rs @@ -22,14 +22,12 @@ pub trait Decodable: Sized { fn decode(message: &Message) -> Result; } -impl Decodable for T { +impl Decodable for T { fn decode(message: &Message) -> Result { if !message.handles.is_empty() { - return Err( - protobuf::ProtobufError::WireError(protobuf::error::WireError::Other).into(), - ); + return Err(OakError::ProtobufDecodeError(None)); } - let value = protobuf::parse_from_bytes(&message.bytes)?; + let value = T::decode(message.bytes.as_slice())?; Ok(value) } } diff --git a/sdk/rust/oak/src/io/encodable.rs b/sdk/rust/oak/src/io/encodable.rs index b375d80cca2..fef8cdc4428 100644 --- a/sdk/rust/oak/src/io/encodable.rs +++ b/sdk/rust/oak/src/io/encodable.rs @@ -22,9 +22,10 @@ pub trait Encodable { fn encode(&self) -> Result; } -impl Encodable for T { +impl Encodable for T { fn encode(&self) -> Result { - let bytes = self.write_to_bytes()?; + let mut bytes = Vec::new(); + self.encode(&mut bytes)?; let handles = Vec::new(); Ok(crate::io::Message { bytes, handles }) } diff --git a/sdk/rust/oak/src/lib.rs b/sdk/rust/oak/src/lib.rs index 26c3d2cb0f7..9791e356b41 100644 --- a/sdk/rust/oak/src/lib.rs +++ b/sdk/rust/oak/src/lib.rs @@ -27,10 +27,29 @@ pub use error::OakError; pub mod grpc; pub mod io; pub mod logger; -pub mod proto; pub mod rand; pub mod storage; +pub mod proto { + pub mod google { + pub mod protobuf { + include!(concat!(env!("OUT_DIR"), "/google.protobuf.rs")); + } + pub mod rpc { + include!(concat!(env!("OUT_DIR"), "/google.rpc.rs")); + } + } + pub mod oak { + include!(concat!(env!("OUT_DIR"), "/oak.rs")); + pub mod label { + include!(concat!(env!("OUT_DIR"), "/oak.label.rs")); + } + pub mod log { + include!(concat!(env!("OUT_DIR"), "/oak.log.rs")); + } + } +} + // TODO(#544) /// Handle used to identify read or write channel halves. diff --git a/sdk/rust/oak/src/logger/mod.rs b/sdk/rust/oak/src/logger/mod.rs index 92e28027173..d2316654181 100644 --- a/sdk/rust/oak/src/logger/mod.rs +++ b/sdk/rust/oak/src/logger/mod.rs @@ -24,7 +24,7 @@ use log::{Level, Log, Metadata, Record, SetLoggerError}; struct OakChannelLogger { - channel: crate::io::Sender, + channel: crate::io::Sender, } impl Log for OakChannelLogger { @@ -35,12 +35,11 @@ impl Log for OakChannelLogger { if !self.enabled(record.metadata()) { return; } - let log_msg = crate::proto::log::LogMessage { + let log_msg = crate::proto::oak::log::LogMessage { file: record.file().unwrap_or("").to_string(), line: record.line().unwrap_or_default(), - level: map_level(record.level()), + level: map_level(record.level()) as i32, message: format!("{}", record.args()), - ..Default::default() }; match self.channel.send(&log_msg) { Ok(()) => (), @@ -51,13 +50,13 @@ impl Log for OakChannelLogger { fn flush(&self) {} } -fn map_level(level: Level) -> crate::proto::log::Level { +fn map_level(level: Level) -> crate::proto::oak::log::Level { match level { - Level::Error => crate::proto::log::Level::ERROR, - Level::Warn => crate::proto::log::Level::WARN, - Level::Info => crate::proto::log::Level::INFO, - Level::Debug => crate::proto::log::Level::DEBUG, - Level::Trace => crate::proto::log::Level::TRACE, + Level::Error => crate::proto::oak::log::Level::Error, + Level::Warn => crate::proto::oak::log::Level::Warn, + Level::Info => crate::proto::oak::log::Level::Info, + Level::Debug => crate::proto::oak::log::Level::Debug, + Level::Trace => crate::proto::oak::log::Level::Trace, } } diff --git a/sdk/rust/oak/src/proto/code.rs b/sdk/rust/oak/src/proto/code.rs deleted file mode 100644 index 010ddee9889..00000000000 --- a/sdk/rust/oak/src/proto/code.rs +++ /dev/null @@ -1,158 +0,0 @@ -// This file is generated by rust-protobuf 2.10.1. Do not edit -// @generated - -// https://github.com/rust-lang/rust-clippy/issues/702 -#![allow(unknown_lints)] -#![allow(clippy::all)] - -#![cfg_attr(rustfmt, rustfmt_skip)] - -#![allow(box_pointers)] -#![allow(dead_code)] -#![allow(missing_docs)] -#![allow(non_camel_case_types)] -#![allow(non_snake_case)] -#![allow(non_upper_case_globals)] -#![allow(trivial_casts)] -#![allow(unsafe_code)] -#![allow(unused_imports)] -#![allow(unused_results)] -//! Generated file from `third_party/google/rpc/code.proto` - -use protobuf::Message as Message_imported_for_functions; -use protobuf::ProtobufEnum as ProtobufEnum_imported_for_functions; - -/// Generated files are compatible only with the same version -/// of protobuf runtime. -// const _PROTOBUF_VERSION_CHECK: () = ::protobuf::VERSION_2_10_1; - -#[derive(Clone,PartialEq,Eq,Debug,Hash)] -pub enum Code { - OK = 0, - CANCELLED = 1, - UNKNOWN = 2, - INVALID_ARGUMENT = 3, - DEADLINE_EXCEEDED = 4, - NOT_FOUND = 5, - ALREADY_EXISTS = 6, - PERMISSION_DENIED = 7, - UNAUTHENTICATED = 16, - RESOURCE_EXHAUSTED = 8, - FAILED_PRECONDITION = 9, - ABORTED = 10, - OUT_OF_RANGE = 11, - UNIMPLEMENTED = 12, - INTERNAL = 13, - UNAVAILABLE = 14, - DATA_LOSS = 15, -} - -impl ::protobuf::ProtobufEnum for Code { - fn value(&self) -> i32 { - *self as i32 - } - - fn from_i32(value: i32) -> ::std::option::Option { - match value { - 0 => ::std::option::Option::Some(Code::OK), - 1 => ::std::option::Option::Some(Code::CANCELLED), - 2 => ::std::option::Option::Some(Code::UNKNOWN), - 3 => ::std::option::Option::Some(Code::INVALID_ARGUMENT), - 4 => ::std::option::Option::Some(Code::DEADLINE_EXCEEDED), - 5 => ::std::option::Option::Some(Code::NOT_FOUND), - 6 => ::std::option::Option::Some(Code::ALREADY_EXISTS), - 7 => ::std::option::Option::Some(Code::PERMISSION_DENIED), - 16 => ::std::option::Option::Some(Code::UNAUTHENTICATED), - 8 => ::std::option::Option::Some(Code::RESOURCE_EXHAUSTED), - 9 => ::std::option::Option::Some(Code::FAILED_PRECONDITION), - 10 => ::std::option::Option::Some(Code::ABORTED), - 11 => ::std::option::Option::Some(Code::OUT_OF_RANGE), - 12 => ::std::option::Option::Some(Code::UNIMPLEMENTED), - 13 => ::std::option::Option::Some(Code::INTERNAL), - 14 => ::std::option::Option::Some(Code::UNAVAILABLE), - 15 => ::std::option::Option::Some(Code::DATA_LOSS), - _ => ::std::option::Option::None - } - } - - fn values() -> &'static [Self] { - static values: &'static [Code] = &[ - Code::OK, - Code::CANCELLED, - Code::UNKNOWN, - Code::INVALID_ARGUMENT, - Code::DEADLINE_EXCEEDED, - Code::NOT_FOUND, - Code::ALREADY_EXISTS, - Code::PERMISSION_DENIED, - Code::UNAUTHENTICATED, - Code::RESOURCE_EXHAUSTED, - Code::FAILED_PRECONDITION, - Code::ABORTED, - Code::OUT_OF_RANGE, - Code::UNIMPLEMENTED, - Code::INTERNAL, - Code::UNAVAILABLE, - Code::DATA_LOSS, - ]; - values - } - - fn enum_descriptor_static() -> &'static ::protobuf::reflect::EnumDescriptor { - static mut descriptor: ::protobuf::lazy::Lazy<::protobuf::reflect::EnumDescriptor> = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const ::protobuf::reflect::EnumDescriptor, - }; - unsafe { - descriptor.get(|| { - ::protobuf::reflect::EnumDescriptor::new("Code", file_descriptor_proto()) - }) - } - } -} - -impl ::std::marker::Copy for Code { -} - -impl ::std::default::Default for Code { - fn default() -> Self { - Code::OK - } -} - -impl ::protobuf::reflect::ProtobufValue for Code { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { - ::protobuf::reflect::ProtobufValueRef::Enum(self.descriptor()) - } -} - -static file_descriptor_proto_data: &'static [u8] = b"\ - \n!third_party/google/rpc/code.proto\x12\ngoogle.rpc*\xb7\x02\n\x04Code\ - \x12\x06\n\x02OK\x10\0\x12\r\n\tCANCELLED\x10\x01\x12\x0b\n\x07UNKNOWN\ - \x10\x02\x12\x14\n\x10INVALID_ARGUMENT\x10\x03\x12\x15\n\x11DEADLINE_EXC\ - EEDED\x10\x04\x12\r\n\tNOT_FOUND\x10\x05\x12\x12\n\x0eALREADY_EXISTS\x10\ - \x06\x12\x15\n\x11PERMISSION_DENIED\x10\x07\x12\x13\n\x0fUNAUTHENTICATED\ - \x10\x10\x12\x16\n\x12RESOURCE_EXHAUSTED\x10\x08\x12\x17\n\x13FAILED_PRE\ - CONDITION\x10\t\x12\x0b\n\x07ABORTED\x10\n\x12\x10\n\x0cOUT_OF_RANGE\x10\ - \x0b\x12\x11\n\rUNIMPLEMENTED\x10\x0c\x12\x0c\n\x08INTERNAL\x10\r\x12\ - \x0f\n\x0bUNAVAILABLE\x10\x0e\x12\r\n\tDATA_LOSS\x10\x0fBX\n\x0ecom.goog\ - le.rpcB\tCodeProtoP\x01Z3google.golang.org/genproto/googleapis/rpc/code;\ - code\xa2\x02\x03RPCb\x06proto3\ -"; - -static mut file_descriptor_proto_lazy: ::protobuf::lazy::Lazy<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const ::protobuf::descriptor::FileDescriptorProto, -}; - -fn parse_descriptor_proto() -> ::protobuf::descriptor::FileDescriptorProto { - ::protobuf::parse_from_bytes(file_descriptor_proto_data).unwrap() -} - -pub fn file_descriptor_proto() -> &'static ::protobuf::descriptor::FileDescriptorProto { - unsafe { - file_descriptor_proto_lazy.get(|| { - parse_descriptor_proto() - }) - } -} diff --git a/sdk/rust/oak/src/proto/grpc_encap.rs b/sdk/rust/oak/src/proto/grpc_encap.rs deleted file mode 100644 index 58703dea4f2..00000000000 --- a/sdk/rust/oak/src/proto/grpc_encap.rs +++ /dev/null @@ -1,592 +0,0 @@ -// This file is generated by rust-protobuf 2.10.1. Do not edit -// @generated - -// https://github.com/rust-lang/rust-clippy/issues/702 -#![allow(unknown_lints)] -#![allow(clippy::all)] - -#![cfg_attr(rustfmt, rustfmt_skip)] - -#![allow(box_pointers)] -#![allow(dead_code)] -#![allow(missing_docs)] -#![allow(non_camel_case_types)] -#![allow(non_snake_case)] -#![allow(non_upper_case_globals)] -#![allow(trivial_casts)] -#![allow(unsafe_code)] -#![allow(unused_imports)] -#![allow(unused_results)] -//! Generated file from `oak/proto/grpc_encap.proto` - -use protobuf::Message as Message_imported_for_functions; -use protobuf::ProtobufEnum as ProtobufEnum_imported_for_functions; - -/// Generated files are compatible only with the same version -/// of protobuf runtime. -// const _PROTOBUF_VERSION_CHECK: () = ::protobuf::VERSION_2_10_1; - -#[derive(PartialEq,Clone,Default)] -pub struct GrpcRequest { - // message fields - pub method_name: ::std::string::String, - pub req_msg: ::protobuf::SingularPtrField<::protobuf::well_known_types::Any>, - pub last: bool, - // special fields - pub unknown_fields: ::protobuf::UnknownFields, - pub cached_size: ::protobuf::CachedSize, -} - -impl<'a> ::std::default::Default for &'a GrpcRequest { - fn default() -> &'a GrpcRequest { - ::default_instance() - } -} - -impl GrpcRequest { - pub fn new() -> GrpcRequest { - ::std::default::Default::default() - } - - // string method_name = 1; - - - pub fn get_method_name(&self) -> &str { - &self.method_name - } - pub fn clear_method_name(&mut self) { - self.method_name.clear(); - } - - // Param is passed by value, moved - pub fn set_method_name(&mut self, v: ::std::string::String) { - self.method_name = v; - } - - // Mutable pointer to the field. - // If field is not initialized, it is initialized with default value first. - pub fn mut_method_name(&mut self) -> &mut ::std::string::String { - &mut self.method_name - } - - // Take field - pub fn take_method_name(&mut self) -> ::std::string::String { - ::std::mem::replace(&mut self.method_name, ::std::string::String::new()) - } - - // .google.protobuf.Any req_msg = 2; - - - pub fn get_req_msg(&self) -> &::protobuf::well_known_types::Any { - self.req_msg.as_ref().unwrap_or_else(|| ::protobuf::well_known_types::Any::default_instance()) - } - pub fn clear_req_msg(&mut self) { - self.req_msg.clear(); - } - - pub fn has_req_msg(&self) -> bool { - self.req_msg.is_some() - } - - // Param is passed by value, moved - pub fn set_req_msg(&mut self, v: ::protobuf::well_known_types::Any) { - self.req_msg = ::protobuf::SingularPtrField::some(v); - } - - // Mutable pointer to the field. - // If field is not initialized, it is initialized with default value first. - pub fn mut_req_msg(&mut self) -> &mut ::protobuf::well_known_types::Any { - if self.req_msg.is_none() { - self.req_msg.set_default(); - } - self.req_msg.as_mut().unwrap() - } - - // Take field - pub fn take_req_msg(&mut self) -> ::protobuf::well_known_types::Any { - self.req_msg.take().unwrap_or_else(|| ::protobuf::well_known_types::Any::new()) - } - - // bool last = 3; - - - pub fn get_last(&self) -> bool { - self.last - } - pub fn clear_last(&mut self) { - self.last = false; - } - - // Param is passed by value, moved - pub fn set_last(&mut self, v: bool) { - self.last = v; - } -} - -impl ::protobuf::Message for GrpcRequest { - fn is_initialized(&self) -> bool { - for v in &self.req_msg { - if !v.is_initialized() { - return false; - } - }; - true - } - - fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> { - while !is.eof()? { - let (field_number, wire_type) = is.read_tag_unpack()?; - match field_number { - 1 => { - ::protobuf::rt::read_singular_proto3_string_into(wire_type, is, &mut self.method_name)?; - }, - 2 => { - ::protobuf::rt::read_singular_message_into(wire_type, is, &mut self.req_msg)?; - }, - 3 => { - if wire_type != ::protobuf::wire_format::WireTypeVarint { - return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); - } - let tmp = is.read_bool()?; - self.last = tmp; - }, - _ => { - ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; - }, - }; - } - ::std::result::Result::Ok(()) - } - - // Compute sizes of nested messages - #[allow(unused_variables)] - fn compute_size(&self) -> u32 { - let mut my_size = 0; - if !self.method_name.is_empty() { - my_size += ::protobuf::rt::string_size(1, &self.method_name); - } - if let Some(ref v) = self.req_msg.as_ref() { - let len = v.compute_size(); - my_size += 1 + ::protobuf::rt::compute_raw_varint32_size(len) + len; - } - if self.last != false { - my_size += 2; - } - my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); - self.cached_size.set(my_size); - my_size - } - - fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { - if !self.method_name.is_empty() { - os.write_string(1, &self.method_name)?; - } - if let Some(ref v) = self.req_msg.as_ref() { - os.write_tag(2, ::protobuf::wire_format::WireTypeLengthDelimited)?; - os.write_raw_varint32(v.get_cached_size())?; - v.write_to_with_cached_sizes(os)?; - } - if self.last != false { - os.write_bool(3, self.last)?; - } - os.write_unknown_fields(self.get_unknown_fields())?; - ::std::result::Result::Ok(()) - } - - fn get_cached_size(&self) -> u32 { - self.cached_size.get() - } - - fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { - &self.unknown_fields - } - - fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { - &mut self.unknown_fields - } - - fn as_any(&self) -> &dyn (::std::any::Any) { - self as &dyn (::std::any::Any) - } - fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { - self as &mut dyn (::std::any::Any) - } - fn into_any(self: Box) -> ::std::boxed::Box { - self - } - - fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { - Self::descriptor_static() - } - - fn new() -> GrpcRequest { - GrpcRequest::new() - } - - fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor { - static mut descriptor: ::protobuf::lazy::Lazy<::protobuf::reflect::MessageDescriptor> = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const ::protobuf::reflect::MessageDescriptor, - }; - unsafe { - descriptor.get(|| { - let mut fields = ::std::vec::Vec::new(); - fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeString>( - "method_name", - |m: &GrpcRequest| { &m.method_name }, - |m: &mut GrpcRequest| { &mut m.method_name }, - )); - fields.push(::protobuf::reflect::accessor::make_singular_ptr_field_accessor::<_, ::protobuf::types::ProtobufTypeMessage<::protobuf::well_known_types::Any>>( - "req_msg", - |m: &GrpcRequest| { &m.req_msg }, - |m: &mut GrpcRequest| { &mut m.req_msg }, - )); - fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeBool>( - "last", - |m: &GrpcRequest| { &m.last }, - |m: &mut GrpcRequest| { &mut m.last }, - )); - ::protobuf::reflect::MessageDescriptor::new::( - "GrpcRequest", - fields, - file_descriptor_proto() - ) - }) - } - } - - fn default_instance() -> &'static GrpcRequest { - static mut instance: ::protobuf::lazy::Lazy = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const GrpcRequest, - }; - unsafe { - instance.get(GrpcRequest::new) - } - } -} - -impl ::protobuf::Clear for GrpcRequest { - fn clear(&mut self) { - self.method_name.clear(); - self.req_msg.clear(); - self.last = false; - self.unknown_fields.clear(); - } -} - -impl ::std::fmt::Debug for GrpcRequest { - fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { - ::protobuf::text_format::fmt(self, f) - } -} - -impl ::protobuf::reflect::ProtobufValue for GrpcRequest { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { - ::protobuf::reflect::ProtobufValueRef::Message(self) - } -} - -#[derive(PartialEq,Clone,Default)] -pub struct GrpcResponse { - // message fields - pub rsp_msg: ::protobuf::SingularPtrField<::protobuf::well_known_types::Any>, - pub status: ::protobuf::SingularPtrField, - pub last: bool, - // special fields - pub unknown_fields: ::protobuf::UnknownFields, - pub cached_size: ::protobuf::CachedSize, -} - -impl<'a> ::std::default::Default for &'a GrpcResponse { - fn default() -> &'a GrpcResponse { - ::default_instance() - } -} - -impl GrpcResponse { - pub fn new() -> GrpcResponse { - ::std::default::Default::default() - } - - // .google.protobuf.Any rsp_msg = 1; - - - pub fn get_rsp_msg(&self) -> &::protobuf::well_known_types::Any { - self.rsp_msg.as_ref().unwrap_or_else(|| ::protobuf::well_known_types::Any::default_instance()) - } - pub fn clear_rsp_msg(&mut self) { - self.rsp_msg.clear(); - } - - pub fn has_rsp_msg(&self) -> bool { - self.rsp_msg.is_some() - } - - // Param is passed by value, moved - pub fn set_rsp_msg(&mut self, v: ::protobuf::well_known_types::Any) { - self.rsp_msg = ::protobuf::SingularPtrField::some(v); - } - - // Mutable pointer to the field. - // If field is not initialized, it is initialized with default value first. - pub fn mut_rsp_msg(&mut self) -> &mut ::protobuf::well_known_types::Any { - if self.rsp_msg.is_none() { - self.rsp_msg.set_default(); - } - self.rsp_msg.as_mut().unwrap() - } - - // Take field - pub fn take_rsp_msg(&mut self) -> ::protobuf::well_known_types::Any { - self.rsp_msg.take().unwrap_or_else(|| ::protobuf::well_known_types::Any::new()) - } - - // .google.rpc.Status status = 2; - - - pub fn get_status(&self) -> &super::status::Status { - self.status.as_ref().unwrap_or_else(|| super::status::Status::default_instance()) - } - pub fn clear_status(&mut self) { - self.status.clear(); - } - - pub fn has_status(&self) -> bool { - self.status.is_some() - } - - // Param is passed by value, moved - pub fn set_status(&mut self, v: super::status::Status) { - self.status = ::protobuf::SingularPtrField::some(v); - } - - // Mutable pointer to the field. - // If field is not initialized, it is initialized with default value first. - pub fn mut_status(&mut self) -> &mut super::status::Status { - if self.status.is_none() { - self.status.set_default(); - } - self.status.as_mut().unwrap() - } - - // Take field - pub fn take_status(&mut self) -> super::status::Status { - self.status.take().unwrap_or_else(|| super::status::Status::new()) - } - - // bool last = 3; - - - pub fn get_last(&self) -> bool { - self.last - } - pub fn clear_last(&mut self) { - self.last = false; - } - - // Param is passed by value, moved - pub fn set_last(&mut self, v: bool) { - self.last = v; - } -} - -impl ::protobuf::Message for GrpcResponse { - fn is_initialized(&self) -> bool { - for v in &self.rsp_msg { - if !v.is_initialized() { - return false; - } - }; - for v in &self.status { - if !v.is_initialized() { - return false; - } - }; - true - } - - fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> { - while !is.eof()? { - let (field_number, wire_type) = is.read_tag_unpack()?; - match field_number { - 1 => { - ::protobuf::rt::read_singular_message_into(wire_type, is, &mut self.rsp_msg)?; - }, - 2 => { - ::protobuf::rt::read_singular_message_into(wire_type, is, &mut self.status)?; - }, - 3 => { - if wire_type != ::protobuf::wire_format::WireTypeVarint { - return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); - } - let tmp = is.read_bool()?; - self.last = tmp; - }, - _ => { - ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; - }, - }; - } - ::std::result::Result::Ok(()) - } - - // Compute sizes of nested messages - #[allow(unused_variables)] - fn compute_size(&self) -> u32 { - let mut my_size = 0; - if let Some(ref v) = self.rsp_msg.as_ref() { - let len = v.compute_size(); - my_size += 1 + ::protobuf::rt::compute_raw_varint32_size(len) + len; - } - if let Some(ref v) = self.status.as_ref() { - let len = v.compute_size(); - my_size += 1 + ::protobuf::rt::compute_raw_varint32_size(len) + len; - } - if self.last != false { - my_size += 2; - } - my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); - self.cached_size.set(my_size); - my_size - } - - fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { - if let Some(ref v) = self.rsp_msg.as_ref() { - os.write_tag(1, ::protobuf::wire_format::WireTypeLengthDelimited)?; - os.write_raw_varint32(v.get_cached_size())?; - v.write_to_with_cached_sizes(os)?; - } - if let Some(ref v) = self.status.as_ref() { - os.write_tag(2, ::protobuf::wire_format::WireTypeLengthDelimited)?; - os.write_raw_varint32(v.get_cached_size())?; - v.write_to_with_cached_sizes(os)?; - } - if self.last != false { - os.write_bool(3, self.last)?; - } - os.write_unknown_fields(self.get_unknown_fields())?; - ::std::result::Result::Ok(()) - } - - fn get_cached_size(&self) -> u32 { - self.cached_size.get() - } - - fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { - &self.unknown_fields - } - - fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { - &mut self.unknown_fields - } - - fn as_any(&self) -> &dyn (::std::any::Any) { - self as &dyn (::std::any::Any) - } - fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { - self as &mut dyn (::std::any::Any) - } - fn into_any(self: Box) -> ::std::boxed::Box { - self - } - - fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { - Self::descriptor_static() - } - - fn new() -> GrpcResponse { - GrpcResponse::new() - } - - fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor { - static mut descriptor: ::protobuf::lazy::Lazy<::protobuf::reflect::MessageDescriptor> = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const ::protobuf::reflect::MessageDescriptor, - }; - unsafe { - descriptor.get(|| { - let mut fields = ::std::vec::Vec::new(); - fields.push(::protobuf::reflect::accessor::make_singular_ptr_field_accessor::<_, ::protobuf::types::ProtobufTypeMessage<::protobuf::well_known_types::Any>>( - "rsp_msg", - |m: &GrpcResponse| { &m.rsp_msg }, - |m: &mut GrpcResponse| { &mut m.rsp_msg }, - )); - fields.push(::protobuf::reflect::accessor::make_singular_ptr_field_accessor::<_, ::protobuf::types::ProtobufTypeMessage>( - "status", - |m: &GrpcResponse| { &m.status }, - |m: &mut GrpcResponse| { &mut m.status }, - )); - fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeBool>( - "last", - |m: &GrpcResponse| { &m.last }, - |m: &mut GrpcResponse| { &mut m.last }, - )); - ::protobuf::reflect::MessageDescriptor::new::( - "GrpcResponse", - fields, - file_descriptor_proto() - ) - }) - } - } - - fn default_instance() -> &'static GrpcResponse { - static mut instance: ::protobuf::lazy::Lazy = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const GrpcResponse, - }; - unsafe { - instance.get(GrpcResponse::new) - } - } -} - -impl ::protobuf::Clear for GrpcResponse { - fn clear(&mut self) { - self.rsp_msg.clear(); - self.status.clear(); - self.last = false; - self.unknown_fields.clear(); - } -} - -impl ::std::fmt::Debug for GrpcResponse { - fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { - ::protobuf::text_format::fmt(self, f) - } -} - -impl ::protobuf::reflect::ProtobufValue for GrpcResponse { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { - ::protobuf::reflect::ProtobufValueRef::Message(self) - } -} - -static file_descriptor_proto_data: &'static [u8] = b"\ - \n\x1aoak/proto/grpc_encap.proto\x12\x03oak\x1a\x19google/protobuf/any.p\ - roto\x1a#third_party/google/rpc/status.proto\"q\n\x0bGrpcRequest\x12\x1f\ - \n\x0bmethod_name\x18\x01\x20\x01(\tR\nmethodName\x12-\n\x07req_msg\x18\ - \x02\x20\x01(\x0b2\x14.google.protobuf.AnyR\x06reqMsg\x12\x12\n\x04last\ - \x18\x03\x20\x01(\x08R\x04last\"}\n\x0cGrpcResponse\x12-\n\x07rsp_msg\ - \x18\x01\x20\x01(\x0b2\x14.google.protobuf.AnyR\x06rspMsg\x12*\n\x06stat\ - us\x18\x02\x20\x01(\x0b2\x12.google.rpc.StatusR\x06status\x12\x12\n\x04l\ - ast\x18\x03\x20\x01(\x08R\x04lastb\x06proto3\ -"; - -static mut file_descriptor_proto_lazy: ::protobuf::lazy::Lazy<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const ::protobuf::descriptor::FileDescriptorProto, -}; - -fn parse_descriptor_proto() -> ::protobuf::descriptor::FileDescriptorProto { - ::protobuf::parse_from_bytes(file_descriptor_proto_data).unwrap() -} - -pub fn file_descriptor_proto() -> &'static ::protobuf::descriptor::FileDescriptorProto { - unsafe { - file_descriptor_proto_lazy.get(|| { - parse_descriptor_proto() - }) - } -} diff --git a/sdk/rust/oak/src/proto/label.rs b/sdk/rust/oak/src/proto/label.rs deleted file mode 100644 index 15b4a8375d0..00000000000 --- a/sdk/rust/oak/src/proto/label.rs +++ /dev/null @@ -1,1160 +0,0 @@ -// This file is generated by rust-protobuf 2.10.1. Do not edit -// @generated - -// https://github.com/rust-lang/rust-clippy/issues/702 -#![allow(unknown_lints)] -#![allow(clippy::all)] - -#![cfg_attr(rustfmt, rustfmt_skip)] - -#![allow(box_pointers)] -#![allow(dead_code)] -#![allow(missing_docs)] -#![allow(non_camel_case_types)] -#![allow(non_snake_case)] -#![allow(non_upper_case_globals)] -#![allow(trivial_casts)] -#![allow(unsafe_code)] -#![allow(unused_imports)] -#![allow(unused_results)] -//! Generated file from `oak/proto/label.proto` - -use protobuf::Message as Message_imported_for_functions; -use protobuf::ProtobufEnum as ProtobufEnum_imported_for_functions; - -/// Generated files are compatible only with the same version -/// of protobuf runtime. -// const _PROTOBUF_VERSION_CHECK: () = ::protobuf::VERSION_2_10_1; - -#[derive(PartialEq,Clone,Default)] -pub struct Label { - // message fields - pub secrecy_tags: ::protobuf::RepeatedField, - pub integrity_tags: ::protobuf::RepeatedField, - // special fields - pub unknown_fields: ::protobuf::UnknownFields, - pub cached_size: ::protobuf::CachedSize, -} - -impl<'a> ::std::default::Default for &'a Label { - fn default() -> &'a Label { -