diff --git a/codelabs/grpc-rust-getting-started/README.md b/codelabs/grpc-rust-getting-started/README.md new file mode 100644 index 00000000..7323c622 --- /dev/null +++ b/codelabs/grpc-rust-getting-started/README.md @@ -0,0 +1,89 @@ +# Generate Code from Proto Files + +This is a tutorial for generating code from Proto files using gRPC-Rust. This tutorial will utilize the RouteGuide example. + +### Prerequisites + +* [**Tonic**](https://github.com/hyperium/tonic.git), the open source repository that gRPC-Rust is build off on +```sh +$ git clone https://github.com/hyperium/tonic.git +``` +* [**Rust**](https://www.rust-lang.org/). + * Follow installation instructions [here](https://www.rust-lang.org/tools/install). +* [**Bazel 8.3.1**](https://bazel.build/). + * Follow installation instructions [here](https://github.com/bazelbuild/bazel/releases). +* [**Protocol buffer**](https://developers.google.com/protocol-buffers) **compiler**, `protoc`, [version 3](https://protobuf.dev/programming-guides/proto3). + * For installation instructions, see [Protocol Buffer Compiler Installation](https://grpc.io/docs/protoc-installation/). + * NOTE: Must need a version of Protoc 3.31.1 or higher. +* **Rust plugins** for the protocol compiler: +```sh +$ cd tonic/protoc-gen-rust-grpc +$ bazel build //src:protoc-gen-rust-grpc +$ PLUGIN_PATH="$(pwd)/bazel-bin/src/protoc-gen-rust-grpc" +``` + +* Update your PATH so that the protoc compiler can find the plugins: + +```sh +export PATH="$(pwd)/bazel-bin/src/:$PATH" +``` + +## Generating client and server code + +Next we need to generate the gRPC client and server interfaces from our `.proto` +service definition. + +### Dependencies +Edit `Cargo.toml` and add the dependency we'll need for this example, which is tonic-protobuf-build: + +```console +cargo add tonic-protobuf-build +``` + +### Compiling and Building Proto +Create a `build.rs` file at the root of your crate. A build.rs script is a Rust program that Cargo executes before compiling your main project. Its purpose is to perform tasks like generating source code, linking to non-Rust libraries, or setting environment variables that influence the build process. + +In this case, we will be putting the command to compile and build the `.proto` file in build.rs. We will use gRPC's tonic_protobuf_build crate to generate code from the `.proto` file. +```rust +fn main() { + tonic_protobuf_build::CodeGen::new() + .include("proto") + .inputs(["routeguide.proto"]) + .output_dir("generated") + .compile() + .unwrap(); +} +``` +Now, run +```shell +$ cargo build +``` + +That's it. The generated code contains: + +- Struct definitions for message types `Point` and `Feature`. +- A service trait we'll need to implement: `route_guide_server::RouteGuide`. +- A client type we'll use to call the server: `route_guide_client::RouteGuideClient`. + +If your are curious as to where the generated files are, keep reading. The mystery will be revealed +soon! We can now move on to the fun part. + +## Bringing Generated Code into Scope + +The generated code is placed inside our target directory, in a location defined by the `OUT_DIR` +environment variable that is set by cargo. For our example, this means you can find the generated +code in a path similar to `target/debug/build/routeguide/out/routeguide.rs`. + +We can use gRPC's `include_proto` macro to bring the generated code into scope: + +```rust +pub mod routeguide { + tonic::include_proto!("routeguide"); +} +``` + +**Note**: The token passed to the `include_proto` macro (in our case "routeguide") is the name of +the package declared in our `.proto` file, not a filename, e.g "routeguide.rs". + +With this in place, we can stub out our service implementation: + diff --git a/codelabs/grpc-rust-getting-started/completed/Cargo.toml b/codelabs/grpc-rust-getting-started/completed/Cargo.toml new file mode 100644 index 00000000..afcad933 --- /dev/null +++ b/codelabs/grpc-rust-getting-started/completed/Cargo.toml @@ -0,0 +1,44 @@ +[package] +edition = "2021" +license = "MIT" +name = "getting-started" + +[[bin]] +name = "routeguide-server" +path = "src/server/server.rs" + +[[bin]] +name = "routeguide-client" +path = "src/client/client.rs" + +[features] +routeguide = ["dep:async-stream", "dep:tokio-stream", "dep:rand", "dep:serde", "dep:serde_json"] +full = ["routeguide"] +default = ["full"] + +[dependencies] +# Common dependencies +tokio = { version = "1.0", features = ["rt-multi-thread", "macros"] } +prost = "0.14" +tonic = { git = "https://github.com/hyperium/tonic", branch="master"} +tonic-protobuf = {git = "https://github.com/hyperium/tonic", branch="master", package = "tonic-protobuf" } +grpc = {git = "https://github.com/hyperium/tonic", branch="master", package = "grpc"} +# Optional dependencies +async-stream = { version = "0.3", optional = true } +tokio-stream = { version = "0.1", optional = true } +tokio-util = { version = "0.7.8", optional = true } +tower = { version = "0.5", optional = true } +rand = { version = "0.9", optional = true } +serde = { version = "1.0", features = ["derive"], optional = true } +serde_json = { version = "1.0", optional = true } +prost-types = { version = "0.14", optional = true } +http = { version = "1", optional = true } +hyper = { version = "1", optional = true } +hyper-util = { version = "0.1.4", optional = true } +tokio-rustls = { version = "0.26.1", optional = true, features = ["ring", "tls12"], default-features = false } +hyper-rustls = { version = "0.27.0", features = ["http2", "ring", "tls12"], optional = true, default-features = false } +tower-http = { version = "0.6", optional = true } +protobuf = { version = "4.31.1-release"} + +[build-dependencies] +protobuf-codegen = { version = "4.31.1-release"} diff --git a/codelabs/grpc-rust-getting-started/completed/build.rs b/codelabs/grpc-rust-getting-started/completed/build.rs new file mode 100644 index 00000000..ecf15526 --- /dev/null +++ b/codelabs/grpc-rust-getting-started/completed/build.rs @@ -0,0 +1,8 @@ +fn main() { + protobuf_codegen::CodeGen::new() + .include("proto") + .inputs(["routeguide.proto"]) + .output_dir("generated") + .compile_only() + .unwrap(); +} diff --git a/codelabs/grpc-rust-getting-started/completed/generated/crate_mapping.txt b/codelabs/grpc-rust-getting-started/completed/generated/crate_mapping.txt new file mode 100644 index 00000000..e69de29b diff --git a/codelabs/grpc-rust-getting-started/completed/generated/generated.rs b/codelabs/grpc-rust-getting-started/completed/generated/generated.rs new file mode 100644 index 00000000..3bd5dfb0 --- /dev/null +++ b/codelabs/grpc-rust-getting-started/completed/generated/generated.rs @@ -0,0 +1,5 @@ +#[path = "routeguide.u.pb.rs"] +#[allow(nonstandard_style)] +pub mod internal_do_not_use_routeguide; +#[allow(unused_imports, nonstandard_style)] +pub use internal_do_not_use_routeguide::*; diff --git a/codelabs/grpc-rust-getting-started/completed/generated/routeguide.u.pb.rs b/codelabs/grpc-rust-getting-started/completed/generated/routeguide.u.pb.rs new file mode 100644 index 00000000..229dead8 --- /dev/null +++ b/codelabs/grpc-rust-getting-started/completed/generated/routeguide.u.pb.rs @@ -0,0 +1,1743 @@ +const _: () = ::protobuf::__internal::assert_compatible_gencode_version( + "4.31.1-release", +); +#[allow(non_camel_case_types)] +pub struct Point { + inner: ::protobuf::__internal::runtime::MessageInner, +} +impl ::protobuf::Message for Point {} +impl ::std::default::Default for Point { + fn default() -> Self { + Self::new() + } +} +impl ::protobuf::Parse for Point { + fn parse(serialized: &[u8]) -> ::std::result::Result { + Self::parse(serialized) + } +} +impl ::std::fmt::Debug for Point { + fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { + let string = unsafe { + ::protobuf::__internal::runtime::debug_string( + self.raw_msg(), + ::mini_table(), + ) + }; + write!(f, "{}", string) + } +} +impl ::protobuf::TakeFrom for Point { + fn take_from(&mut self, src: impl ::protobuf::AsMut) { + let mut m = self.as_mut(); + ::protobuf::TakeFrom::take_from(&mut m, src) + } +} +impl ::protobuf::CopyFrom for Point { + fn copy_from(&mut self, src: impl ::protobuf::AsView) { + let mut m = self.as_mut(); + ::protobuf::CopyFrom::copy_from(&mut m, src) + } +} +impl ::protobuf::MergeFrom for Point { + fn merge_from<'src>(&mut self, src: impl ::protobuf::AsView) { + let mut m = self.as_mut(); + ::protobuf::MergeFrom::merge_from(&mut m, src) + } +} +impl ::protobuf::Serialize for Point { + fn serialize(&self) -> ::std::result::Result, ::protobuf::SerializeError> { + ::protobuf::AsView::as_view(self).serialize() + } +} +impl ::protobuf::Clear for Point { + fn clear(&mut self) { + let mut m = self.as_mut(); + ::protobuf::Clear::clear(&mut m) + } +} +impl ::protobuf::ClearAndParse for Point { + fn clear_and_parse( + &mut self, + data: &[u8], + ) -> ::std::result::Result<(), ::protobuf::ParseError> { + let mut m = self.as_mut(); + ::protobuf::ClearAndParse::clear_and_parse(&mut m, data) + } +} +unsafe impl Sync for Point {} +unsafe impl Send for Point {} +impl ::protobuf::Proxied for Point { + type View<'msg> = PointView<'msg>; +} +impl ::protobuf::__internal::SealedInternal for Point {} +impl ::protobuf::MutProxied for Point { + type Mut<'msg> = PointMut<'msg>; +} +#[derive(Copy, Clone)] +#[allow(dead_code)] +pub struct PointView<'msg> { + msg: ::protobuf::__internal::runtime::RawMessage, + _phantom: ::std::marker::PhantomData<&'msg ()>, +} +impl<'msg> ::protobuf::__internal::SealedInternal for PointView<'msg> {} +impl<'msg> ::protobuf::MessageView<'msg> for PointView<'msg> { + type Message = Point; +} +impl ::std::fmt::Debug for PointView<'_> { + fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { + let string = unsafe { + ::protobuf::__internal::runtime::debug_string( + self.raw_msg(), + ::mini_table(), + ) + }; + write!(f, "{}", string) + } +} +impl ::protobuf::Serialize for PointView<'_> { + fn serialize(&self) -> ::std::result::Result, ::protobuf::SerializeError> { + let encoded = unsafe { + ::protobuf::__internal::runtime::wire::encode( + self.raw_msg(), + ::mini_table(), + ) + }; + encoded.map_err(|_| ::protobuf::SerializeError) + } +} +impl ::std::default::Default for PointView<'_> { + fn default() -> PointView<'static> { + PointView::new( + ::protobuf::__internal::Private, + ::protobuf::__internal::runtime::ScratchSpace::zeroed_block(), + ) + } +} +#[allow(dead_code)] +impl<'msg> PointView<'msg> { + #[doc(hidden)] + pub fn new( + _private: ::protobuf::__internal::Private, + msg: ::protobuf::__internal::runtime::RawMessage, + ) -> Self { + Self { + msg, + _phantom: ::std::marker::PhantomData, + } + } + fn raw_msg(&self) -> ::protobuf::__internal::runtime::RawMessage { + self.msg + } + pub fn to_owned(&self) -> Point { + ::protobuf::IntoProxied::into_proxied(*self, ::protobuf::__internal::Private) + } + pub fn latitude(self) -> i32 { + unsafe { + let mt = ::mini_table(); + let f = ::protobuf::__internal::runtime::upb_MiniTable_GetFieldByIndex( + mt, + 0, + ); + ::protobuf::__internal::runtime::upb_Message_GetInt32( + self.raw_msg(), + f, + (0i32).into(), + ) + .try_into() + .unwrap() + } + } + pub fn longitude(self) -> i32 { + unsafe { + let mt = ::mini_table(); + let f = ::protobuf::__internal::runtime::upb_MiniTable_GetFieldByIndex( + mt, + 1, + ); + ::protobuf::__internal::runtime::upb_Message_GetInt32( + self.raw_msg(), + f, + (0i32).into(), + ) + .try_into() + .unwrap() + } + } +} +unsafe impl Sync for PointView<'_> {} +unsafe impl Send for PointView<'_> {} +impl<'msg> ::protobuf::Proxy<'msg> for PointView<'msg> {} +impl<'msg> ::protobuf::ViewProxy<'msg> for PointView<'msg> {} +impl<'msg> ::protobuf::AsView for PointView<'msg> { + type Proxied = Point; + fn as_view(&self) -> ::protobuf::View<'msg, Point> { + *self + } +} +impl<'msg> ::protobuf::IntoView<'msg> for PointView<'msg> { + fn into_view<'shorter>(self) -> PointView<'shorter> + where + 'msg: 'shorter, + { + self + } +} +impl<'msg> ::protobuf::IntoProxied for PointView<'msg> { + fn into_proxied(self, _private: ::protobuf::__internal::Private) -> Point { + let dst = Point::new(); + unsafe { + ::protobuf::__internal::runtime::upb_Message_DeepCopy( + dst.inner.msg, + self.msg, + ::mini_table(), + dst.inner.arena.raw(), + ) + }; + dst + } +} +impl<'msg> ::protobuf::IntoProxied for PointMut<'msg> { + fn into_proxied(self, _private: ::protobuf::__internal::Private) -> Point { + ::protobuf::IntoProxied::into_proxied( + ::protobuf::IntoView::into_view(self), + _private, + ) + } +} +unsafe impl ::protobuf::ProxiedInRepeated for Point { + fn repeated_new( + _private: ::protobuf::__internal::Private, + ) -> ::protobuf::Repeated { + let arena = ::protobuf::__internal::runtime::Arena::new(); + unsafe { + ::protobuf::Repeated::from_inner( + ::protobuf::__internal::Private, + ::protobuf::__internal::runtime::InnerRepeated::from_raw_parts( + ::protobuf::__internal::runtime::upb_Array_New( + arena.raw(), + ::protobuf::__internal::runtime::CType::Message, + ), + arena, + ), + ) + } + } + unsafe fn repeated_free( + _private: ::protobuf::__internal::Private, + _f: &mut ::protobuf::Repeated, + ) {} + fn repeated_len(f: ::protobuf::View<::protobuf::Repeated>) -> usize { + unsafe { + ::protobuf::__internal::runtime::upb_Array_Size( + f.as_raw(::protobuf::__internal::Private), + ) + } + } + unsafe fn repeated_set_unchecked( + mut f: ::protobuf::Mut<::protobuf::Repeated>, + i: usize, + v: impl ::protobuf::IntoProxied, + ) { + unsafe { + ::protobuf::__internal::runtime::upb_Array_Set( + f.as_raw(::protobuf::__internal::Private), + i, + ::into_message_value_fuse_if_required( + f.raw_arena(::protobuf::__internal::Private), + v.into_proxied(::protobuf::__internal::Private), + ), + ) + } + } + unsafe fn repeated_get_unchecked( + f: ::protobuf::View<::protobuf::Repeated>, + i: usize, + ) -> ::protobuf::View { + let msg_ptr = unsafe { + ::protobuf::__internal::runtime::upb_Array_Get( + f.as_raw(::protobuf::__internal::Private), + i, + ) + .msg_val + } + .expect("upb_Array* element should not be NULL."); + ::protobuf::View::::new(::protobuf::__internal::Private, msg_ptr) + } + unsafe fn repeated_get_mut_unchecked( + mut f: ::protobuf::Mut<::protobuf::Repeated>, + i: usize, + ) -> ::protobuf::Mut { + let msg_ptr = unsafe { + ::protobuf::__internal::runtime::upb_Array_GetMutable( + f.as_raw(::protobuf::__internal::Private), + i, + ) + }; + unsafe { + ::protobuf::Mut:: { + inner: ::protobuf::__internal::runtime::MutatorMessageRef::from_raw_parts( + msg_ptr, + f.arena(::protobuf::__internal::Private), + ), + } + } + } + fn repeated_clear(mut f: ::protobuf::Mut<::protobuf::Repeated>) { + unsafe { + ::protobuf::__internal::runtime::upb_Array_Resize( + f.as_raw(::protobuf::__internal::Private), + 0, + f.raw_arena(::protobuf::__internal::Private), + ) + }; + } + fn repeated_push( + mut f: ::protobuf::Mut<::protobuf::Repeated>, + v: impl ::protobuf::IntoProxied, + ) { + unsafe { + ::protobuf::__internal::runtime::upb_Array_Append( + f.as_raw(::protobuf::__internal::Private), + ::into_message_value_fuse_if_required( + f.raw_arena(::protobuf::__internal::Private), + v.into_proxied(::protobuf::__internal::Private), + ), + f.raw_arena(::protobuf::__internal::Private), + ); + }; + } + fn repeated_copy_from( + src: ::protobuf::View<::protobuf::Repeated>, + dest: ::protobuf::Mut<::protobuf::Repeated>, + ) { + unsafe { + ::protobuf::__internal::runtime::repeated_message_copy_from( + src, + dest, + ::mini_table(), + ); + } + } + fn repeated_reserve( + mut f: ::protobuf::Mut<::protobuf::Repeated>, + additional: usize, + ) { + unsafe { + let size = ::protobuf::__internal::runtime::upb_Array_Size( + f.as_raw(::protobuf::__internal::Private), + ); + ::protobuf::__internal::runtime::upb_Array_Reserve( + f.as_raw(::protobuf::__internal::Private), + size + additional, + f.raw_arena(::protobuf::__internal::Private), + ); + } + } +} +impl ::protobuf::__internal::runtime::UpbTypeConversions for Point { + fn upb_type() -> ::protobuf::__internal::runtime::CType { + ::protobuf::__internal::runtime::CType::Message + } + fn to_message_value( + val: ::protobuf::View<'_, Self>, + ) -> ::protobuf::__internal::runtime::upb_MessageValue { + ::protobuf::__internal::runtime::upb_MessageValue { + msg_val: Some(val.raw_msg()), + } + } + unsafe fn into_message_value_fuse_if_required( + raw_parent_arena: ::protobuf::__internal::runtime::RawArena, + mut val: Self, + ) -> ::protobuf::__internal::runtime::upb_MessageValue { + let parent_arena = ::std::mem::ManuallyDrop::new(unsafe { + ::protobuf::__internal::runtime::Arena::from_raw(raw_parent_arena) + }); + parent_arena + .fuse(val.as_mutator_message_ref(::protobuf::__internal::Private).arena()); + ::protobuf::__internal::runtime::upb_MessageValue { + msg_val: Some(val.raw_msg()), + } + } + unsafe fn from_message_value<'msg>( + msg: ::protobuf::__internal::runtime::upb_MessageValue, + ) -> ::protobuf::View<'msg, Self> { + PointView::new( + ::protobuf::__internal::Private, + unsafe { msg.msg_val }.expect("expected present message value in map"), + ) + } + unsafe fn from_message_mut<'msg>( + msg: *mut ::protobuf::__internal::runtime::upb_Message, + arena: &'msg ::protobuf::__internal::runtime::Arena, + ) -> PointMut<'msg> { + PointMut { + inner: unsafe { + ::protobuf::__internal::runtime::MutatorMessageRef::from_raw_parts( + std::ptr::NonNull::new(msg) + .expect("expected present message value in map"), + arena, + ) + }, + } + } +} +#[allow(dead_code)] +#[allow(non_camel_case_types)] +pub struct PointMut<'msg> { + inner: ::protobuf::__internal::runtime::MutatorMessageRef<'msg>, +} +impl<'msg> ::protobuf::__internal::SealedInternal for PointMut<'msg> {} +impl<'msg> ::protobuf::MessageMut<'msg> for PointMut<'msg> { + type Message = Point; +} +impl ::std::fmt::Debug for PointMut<'_> { + fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { + let string = unsafe { + ::protobuf::__internal::runtime::debug_string( + self.raw_msg(), + ::mini_table(), + ) + }; + write!(f, "{}", string) + } +} +impl ::protobuf::Serialize for PointMut<'_> { + fn serialize(&self) -> ::std::result::Result, ::protobuf::SerializeError> { + ::protobuf::AsView::as_view(self).serialize() + } +} +impl ::protobuf::Clear for PointMut<'_> { + fn clear(&mut self) { + unsafe { + ::protobuf::__internal::runtime::upb_Message_Clear( + self.raw_msg(), + ::mini_table(), + ) + } + } +} +impl ::protobuf::ClearAndParse for PointMut<'_> { + fn clear_and_parse( + &mut self, + data: &[u8], + ) -> ::std::result::Result<(), ::protobuf::ParseError> { + ::protobuf::Clear::clear(self); + let status = unsafe { + ::protobuf::__internal::runtime::wire::decode( + data, + self.raw_msg(), + ::mini_table(), + self.arena(), + ) + }; + match status { + Ok(_) => Ok(()), + Err(_) => Err(::protobuf::ParseError), + } + } +} +impl ::protobuf::TakeFrom for PointMut<'_> { + fn take_from(&mut self, mut src: impl ::protobuf::AsMut) { + let mut src = src.as_mut(); + ::protobuf::CopyFrom::copy_from(self, ::protobuf::AsView::as_view(&src)); + ::protobuf::Clear::clear(&mut src); + } +} +impl ::protobuf::CopyFrom for PointMut<'_> { + fn copy_from(&mut self, src: impl ::protobuf::AsView) { + unsafe { + assert!( + ::protobuf::__internal::runtime::upb_Message_DeepCopy(self.raw_msg(), src + .as_view().raw_msg(), < Self as + ::protobuf::__internal::runtime::AssociatedMiniTable >::mini_table(), + self.arena().raw()) + ); + } + } +} +impl ::protobuf::MergeFrom for PointMut<'_> { + fn merge_from(&mut self, src: impl ::protobuf::AsView) { + unsafe { + assert!( + ::protobuf::__internal::runtime::upb_Message_MergeFrom(self.raw_msg(), + src.as_view().raw_msg(), < Self as + ::protobuf::__internal::runtime::AssociatedMiniTable >::mini_table(), + ::std::ptr::null(), self.arena().raw()) + ); + } + } +} +#[allow(dead_code)] +impl<'msg> PointMut<'msg> { + #[doc(hidden)] + pub fn from_parent( + _private: ::protobuf::__internal::Private, + parent: ::protobuf::__internal::runtime::MutatorMessageRef<'msg>, + msg: ::protobuf::__internal::runtime::RawMessage, + ) -> Self { + Self { + inner: ::protobuf::__internal::runtime::MutatorMessageRef::from_parent( + parent, + msg, + ), + } + } + #[doc(hidden)] + pub fn new( + _private: ::protobuf::__internal::Private, + msg: &'msg mut ::protobuf::__internal::runtime::MessageInner, + ) -> Self { + Self { + inner: ::protobuf::__internal::runtime::MutatorMessageRef::new(msg), + } + } + fn raw_msg(&self) -> ::protobuf::__internal::runtime::RawMessage { + self.inner.msg() + } + #[doc(hidden)] + pub fn as_mutator_message_ref( + &mut self, + _private: ::protobuf::__internal::Private, + ) -> ::protobuf::__internal::runtime::MutatorMessageRef<'msg> { + self.inner + } + pub fn to_owned(&self) -> Point { + ::protobuf::AsView::as_view(self).to_owned() + } + fn arena(&self) -> &::protobuf::__internal::runtime::Arena { + self.inner.arena() + } + pub fn latitude(&self) -> i32 { + unsafe { + let mt = ::mini_table(); + let f = ::protobuf::__internal::runtime::upb_MiniTable_GetFieldByIndex( + mt, + 0, + ); + ::protobuf::__internal::runtime::upb_Message_GetInt32( + self.raw_msg(), + f, + (0i32).into(), + ) + .try_into() + .unwrap() + } + } + pub fn set_latitude(&mut self, val: i32) { + unsafe { + let mt = ::mini_table(); + let f = ::protobuf::__internal::runtime::upb_MiniTable_GetFieldByIndex( + mt, + 0, + ); + ::protobuf::__internal::runtime::upb_Message_SetBaseFieldInt32( + self.raw_msg(), + f, + val.into(), + ); + } + } + pub fn longitude(&self) -> i32 { + unsafe { + let mt = ::mini_table(); + let f = ::protobuf::__internal::runtime::upb_MiniTable_GetFieldByIndex( + mt, + 1, + ); + ::protobuf::__internal::runtime::upb_Message_GetInt32( + self.raw_msg(), + f, + (0i32).into(), + ) + .try_into() + .unwrap() + } + } + pub fn set_longitude(&mut self, val: i32) { + unsafe { + let mt = ::mini_table(); + let f = ::protobuf::__internal::runtime::upb_MiniTable_GetFieldByIndex( + mt, + 1, + ); + ::protobuf::__internal::runtime::upb_Message_SetBaseFieldInt32( + self.raw_msg(), + f, + val.into(), + ); + } + } +} +unsafe impl Sync for PointMut<'_> {} +impl<'msg> ::protobuf::Proxy<'msg> for PointMut<'msg> {} +impl<'msg> ::protobuf::MutProxy<'msg> for PointMut<'msg> {} +impl<'msg> ::protobuf::AsView for PointMut<'msg> { + type Proxied = Point; + fn as_view(&self) -> ::protobuf::View<'_, Point> { + PointView { + msg: self.raw_msg(), + _phantom: ::std::marker::PhantomData, + } + } +} +impl<'msg> ::protobuf::IntoView<'msg> for PointMut<'msg> { + fn into_view<'shorter>(self) -> ::protobuf::View<'shorter, Point> + where + 'msg: 'shorter, + { + PointView { + msg: self.raw_msg(), + _phantom: ::std::marker::PhantomData, + } + } +} +impl<'msg> ::protobuf::AsMut for PointMut<'msg> { + type MutProxied = Point; + fn as_mut(&mut self) -> PointMut<'msg> { + PointMut { inner: self.inner } + } +} +impl<'msg> ::protobuf::IntoMut<'msg> for PointMut<'msg> { + fn into_mut<'shorter>(self) -> PointMut<'shorter> + where + 'msg: 'shorter, + { + self + } +} +#[allow(dead_code)] +impl Point { + pub fn new() -> Self { + let arena = ::protobuf::__internal::runtime::Arena::new(); + let raw_msg = unsafe { + ::protobuf::__internal::runtime::upb_Message_New( + ::mini_table(), + arena.raw(), + ) + .unwrap() + }; + Self { + inner: ::protobuf::__internal::runtime::MessageInner { + msg: raw_msg, + arena, + }, + } + } + fn raw_msg(&self) -> ::protobuf::__internal::runtime::RawMessage { + self.inner.msg + } + #[doc(hidden)] + pub fn as_mutator_message_ref( + &mut self, + _private: ::protobuf::__internal::Private, + ) -> ::protobuf::__internal::runtime::MutatorMessageRef { + ::protobuf::__internal::runtime::MutatorMessageRef::new(&mut self.inner) + } + fn arena(&self) -> &::protobuf::__internal::runtime::Arena { + &self.inner.arena + } + pub fn parse(data: &[u8]) -> ::std::result::Result { + let mut msg = Self::new(); + ::protobuf::ClearAndParse::clear_and_parse(&mut msg, data).map(|_| msg) + } + pub fn as_view(&self) -> PointView { + PointView::new(::protobuf::__internal::Private, self.inner.msg) + } + pub fn as_mut(&mut self) -> PointMut { + PointMut::new(::protobuf::__internal::Private, &mut self.inner) + } + pub fn latitude(&self) -> i32 { + unsafe { + let mt = ::mini_table(); + let f = ::protobuf::__internal::runtime::upb_MiniTable_GetFieldByIndex( + mt, + 0, + ); + ::protobuf::__internal::runtime::upb_Message_GetInt32( + self.raw_msg(), + f, + (0i32).into(), + ) + .try_into() + .unwrap() + } + } + pub fn set_latitude(&mut self, val: i32) { + unsafe { + let mt = ::mini_table(); + let f = ::protobuf::__internal::runtime::upb_MiniTable_GetFieldByIndex( + mt, + 0, + ); + ::protobuf::__internal::runtime::upb_Message_SetBaseFieldInt32( + self.raw_msg(), + f, + val.into(), + ); + } + } + pub fn longitude(&self) -> i32 { + unsafe { + let mt = ::mini_table(); + let f = ::protobuf::__internal::runtime::upb_MiniTable_GetFieldByIndex( + mt, + 1, + ); + ::protobuf::__internal::runtime::upb_Message_GetInt32( + self.raw_msg(), + f, + (0i32).into(), + ) + .try_into() + .unwrap() + } + } + pub fn set_longitude(&mut self, val: i32) { + unsafe { + let mt = ::mini_table(); + let f = ::protobuf::__internal::runtime::upb_MiniTable_GetFieldByIndex( + mt, + 1, + ); + ::protobuf::__internal::runtime::upb_Message_SetBaseFieldInt32( + self.raw_msg(), + f, + val.into(), + ); + } + } +} +impl ::std::ops::Drop for Point { + fn drop(&mut self) {} +} +impl ::std::clone::Clone for Point { + fn clone(&self) -> Self { + self.as_view().to_owned() + } +} +impl ::protobuf::AsView for Point { + type Proxied = Self; + fn as_view(&self) -> PointView { + self.as_view() + } +} +impl ::protobuf::AsMut for Point { + type MutProxied = Self; + fn as_mut(&mut self) -> PointMut { + self.as_mut() + } +} +unsafe impl ::protobuf::__internal::runtime::AssociatedMiniTable for Point { + #[inline(always)] + fn mini_table() -> *const ::protobuf::__internal::runtime::upb_MiniTable { + #[allow(unused_unsafe)] + unsafe { ::std::ptr::addr_of!(routeguide__Point_msg_init) } + } +} +unsafe impl ::protobuf::__internal::runtime::AssociatedMiniTable for PointView<'_> { + #[inline(always)] + fn mini_table() -> *const ::protobuf::__internal::runtime::upb_MiniTable { + #[allow(unused_unsafe)] + unsafe { ::std::ptr::addr_of!(routeguide__Point_msg_init) } + } +} +unsafe impl ::protobuf::__internal::runtime::AssociatedMiniTable for PointMut<'_> { + #[inline(always)] + fn mini_table() -> *const ::protobuf::__internal::runtime::upb_MiniTable { + #[allow(unused_unsafe)] + unsafe { ::std::ptr::addr_of!(routeguide__Point_msg_init) } + } +} +extern "C" { + /// Opaque static extern for this message's MiniTable, generated + /// by the upb C MiniTable codegen. The only valid way to + /// reference this static is with `std::ptr::addr_of!(..)`. + static routeguide__Point_msg_init: ::protobuf::__internal::runtime::upb_MiniTable; +} +impl ::protobuf::OwnedMessageInterop for Point {} +impl<'a> ::protobuf::MessageMutInterop<'a> for PointMut<'a> {} +impl<'a> ::protobuf::MessageViewInterop<'a> for PointView<'a> { + unsafe fn __unstable_wrap_raw_message(msg: &'a *const ::std::ffi::c_void) -> Self { + Self::new( + ::protobuf::__internal::Private, + ::protobuf::__internal::runtime::RawMessage::new(*msg as *mut _).unwrap(), + ) + } + unsafe fn __unstable_wrap_raw_message_unchecked_lifetime( + msg: *const ::std::ffi::c_void, + ) -> Self { + Self::new( + ::protobuf::__internal::Private, + ::protobuf::__internal::runtime::RawMessage::new(msg as *mut _).unwrap(), + ) + } + fn __unstable_as_raw_message(&self) -> *const ::std::ffi::c_void { + self.msg.as_ptr() as *const _ + } +} +impl ::protobuf::__internal::MatcherEq for Point { + fn matches(&self, o: &Self) -> bool { + ::protobuf::__internal::MatcherEq::matches( + &::protobuf::AsView::as_view(self), + &::protobuf::AsView::as_view(o), + ) + } +} +impl<'a> ::protobuf::__internal::MatcherEq for PointMut<'a> { + fn matches(&self, o: &Self) -> bool { + ::protobuf::__internal::MatcherEq::matches( + &::protobuf::AsView::as_view(self), + &::protobuf::AsView::as_view(o), + ) + } +} +impl<'a> ::protobuf::__internal::MatcherEq for PointView<'a> { + fn matches(&self, o: &Self) -> bool { + unsafe { + ::protobuf::__internal::runtime::upb_Message_IsEqual( + self.msg, + o.msg, + ::mini_table(), + 0, + ) + } + } +} +#[allow(non_camel_case_types)] +pub struct Feature { + inner: ::protobuf::__internal::runtime::MessageInner, +} +impl ::protobuf::Message for Feature {} +impl ::std::default::Default for Feature { + fn default() -> Self { + Self::new() + } +} +impl ::protobuf::Parse for Feature { + fn parse(serialized: &[u8]) -> ::std::result::Result { + Self::parse(serialized) + } +} +impl ::std::fmt::Debug for Feature { + fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { + let string = unsafe { + ::protobuf::__internal::runtime::debug_string( + self.raw_msg(), + ::mini_table(), + ) + }; + write!(f, "{}", string) + } +} +impl ::protobuf::TakeFrom for Feature { + fn take_from(&mut self, src: impl ::protobuf::AsMut) { + let mut m = self.as_mut(); + ::protobuf::TakeFrom::take_from(&mut m, src) + } +} +impl ::protobuf::CopyFrom for Feature { + fn copy_from(&mut self, src: impl ::protobuf::AsView) { + let mut m = self.as_mut(); + ::protobuf::CopyFrom::copy_from(&mut m, src) + } +} +impl ::protobuf::MergeFrom for Feature { + fn merge_from<'src>(&mut self, src: impl ::protobuf::AsView) { + let mut m = self.as_mut(); + ::protobuf::MergeFrom::merge_from(&mut m, src) + } +} +impl ::protobuf::Serialize for Feature { + fn serialize(&self) -> ::std::result::Result, ::protobuf::SerializeError> { + ::protobuf::AsView::as_view(self).serialize() + } +} +impl ::protobuf::Clear for Feature { + fn clear(&mut self) { + let mut m = self.as_mut(); + ::protobuf::Clear::clear(&mut m) + } +} +impl ::protobuf::ClearAndParse for Feature { + fn clear_and_parse( + &mut self, + data: &[u8], + ) -> ::std::result::Result<(), ::protobuf::ParseError> { + let mut m = self.as_mut(); + ::protobuf::ClearAndParse::clear_and_parse(&mut m, data) + } +} +unsafe impl Sync for Feature {} +unsafe impl Send for Feature {} +impl ::protobuf::Proxied for Feature { + type View<'msg> = FeatureView<'msg>; +} +impl ::protobuf::__internal::SealedInternal for Feature {} +impl ::protobuf::MutProxied for Feature { + type Mut<'msg> = FeatureMut<'msg>; +} +#[derive(Copy, Clone)] +#[allow(dead_code)] +pub struct FeatureView<'msg> { + msg: ::protobuf::__internal::runtime::RawMessage, + _phantom: ::std::marker::PhantomData<&'msg ()>, +} +impl<'msg> ::protobuf::__internal::SealedInternal for FeatureView<'msg> {} +impl<'msg> ::protobuf::MessageView<'msg> for FeatureView<'msg> { + type Message = Feature; +} +impl ::std::fmt::Debug for FeatureView<'_> { + fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { + let string = unsafe { + ::protobuf::__internal::runtime::debug_string( + self.raw_msg(), + ::mini_table(), + ) + }; + write!(f, "{}", string) + } +} +impl ::protobuf::Serialize for FeatureView<'_> { + fn serialize(&self) -> ::std::result::Result, ::protobuf::SerializeError> { + let encoded = unsafe { + ::protobuf::__internal::runtime::wire::encode( + self.raw_msg(), + ::mini_table(), + ) + }; + encoded.map_err(|_| ::protobuf::SerializeError) + } +} +impl ::std::default::Default for FeatureView<'_> { + fn default() -> FeatureView<'static> { + FeatureView::new( + ::protobuf::__internal::Private, + ::protobuf::__internal::runtime::ScratchSpace::zeroed_block(), + ) + } +} +#[allow(dead_code)] +impl<'msg> FeatureView<'msg> { + #[doc(hidden)] + pub fn new( + _private: ::protobuf::__internal::Private, + msg: ::protobuf::__internal::runtime::RawMessage, + ) -> Self { + Self { + msg, + _phantom: ::std::marker::PhantomData, + } + } + fn raw_msg(&self) -> ::protobuf::__internal::runtime::RawMessage { + self.msg + } + pub fn to_owned(&self) -> Feature { + ::protobuf::IntoProxied::into_proxied(*self, ::protobuf::__internal::Private) + } + pub fn name(self) -> ::protobuf::View<'msg, ::protobuf::ProtoString> { + let str_view = unsafe { + let f = ::protobuf::__internal::runtime::upb_MiniTable_GetFieldByIndex( + ::mini_table(), + 0, + ); + ::protobuf::__internal::runtime::upb_Message_GetString( + self.raw_msg(), + f, + (b"").into(), + ) + }; + unsafe { ::protobuf::ProtoStr::from_utf8_unchecked(str_view.as_ref()) } + } + pub fn has_location(self) -> bool { + unsafe { + let f = ::protobuf::__internal::runtime::upb_MiniTable_GetFieldByIndex( + ::mini_table(), + 1, + ); + ::protobuf::__internal::runtime::upb_Message_HasBaseField(self.raw_msg(), f) + } + } + pub fn location_opt(self) -> ::protobuf::Optional> { + ::protobuf::Optional::new(self.location(), self.has_location()) + } + pub fn location(self) -> super::PointView<'msg> { + let submsg = unsafe { + let f = ::protobuf::__internal::runtime::upb_MiniTable_GetFieldByIndex( + ::mini_table(), + 1, + ); + ::protobuf::__internal::runtime::upb_Message_GetMessage(self.raw_msg(), f) + }; + match submsg { + None => { + super::PointView::new( + ::protobuf::__internal::Private, + ::protobuf::__internal::runtime::ScratchSpace::zeroed_block(), + ) + } + Some(sub_raw_msg) => { + super::PointView::new(::protobuf::__internal::Private, sub_raw_msg) + } + } + } +} +unsafe impl Sync for FeatureView<'_> {} +unsafe impl Send for FeatureView<'_> {} +impl<'msg> ::protobuf::Proxy<'msg> for FeatureView<'msg> {} +impl<'msg> ::protobuf::ViewProxy<'msg> for FeatureView<'msg> {} +impl<'msg> ::protobuf::AsView for FeatureView<'msg> { + type Proxied = Feature; + fn as_view(&self) -> ::protobuf::View<'msg, Feature> { + *self + } +} +impl<'msg> ::protobuf::IntoView<'msg> for FeatureView<'msg> { + fn into_view<'shorter>(self) -> FeatureView<'shorter> + where + 'msg: 'shorter, + { + self + } +} +impl<'msg> ::protobuf::IntoProxied for FeatureView<'msg> { + fn into_proxied(self, _private: ::protobuf::__internal::Private) -> Feature { + let dst = Feature::new(); + unsafe { + ::protobuf::__internal::runtime::upb_Message_DeepCopy( + dst.inner.msg, + self.msg, + ::mini_table(), + dst.inner.arena.raw(), + ) + }; + dst + } +} +impl<'msg> ::protobuf::IntoProxied for FeatureMut<'msg> { + fn into_proxied(self, _private: ::protobuf::__internal::Private) -> Feature { + ::protobuf::IntoProxied::into_proxied( + ::protobuf::IntoView::into_view(self), + _private, + ) + } +} +unsafe impl ::protobuf::ProxiedInRepeated for Feature { + fn repeated_new( + _private: ::protobuf::__internal::Private, + ) -> ::protobuf::Repeated { + let arena = ::protobuf::__internal::runtime::Arena::new(); + unsafe { + ::protobuf::Repeated::from_inner( + ::protobuf::__internal::Private, + ::protobuf::__internal::runtime::InnerRepeated::from_raw_parts( + ::protobuf::__internal::runtime::upb_Array_New( + arena.raw(), + ::protobuf::__internal::runtime::CType::Message, + ), + arena, + ), + ) + } + } + unsafe fn repeated_free( + _private: ::protobuf::__internal::Private, + _f: &mut ::protobuf::Repeated, + ) {} + fn repeated_len(f: ::protobuf::View<::protobuf::Repeated>) -> usize { + unsafe { + ::protobuf::__internal::runtime::upb_Array_Size( + f.as_raw(::protobuf::__internal::Private), + ) + } + } + unsafe fn repeated_set_unchecked( + mut f: ::protobuf::Mut<::protobuf::Repeated>, + i: usize, + v: impl ::protobuf::IntoProxied, + ) { + unsafe { + ::protobuf::__internal::runtime::upb_Array_Set( + f.as_raw(::protobuf::__internal::Private), + i, + ::into_message_value_fuse_if_required( + f.raw_arena(::protobuf::__internal::Private), + v.into_proxied(::protobuf::__internal::Private), + ), + ) + } + } + unsafe fn repeated_get_unchecked( + f: ::protobuf::View<::protobuf::Repeated>, + i: usize, + ) -> ::protobuf::View { + let msg_ptr = unsafe { + ::protobuf::__internal::runtime::upb_Array_Get( + f.as_raw(::protobuf::__internal::Private), + i, + ) + .msg_val + } + .expect("upb_Array* element should not be NULL."); + ::protobuf::View::::new(::protobuf::__internal::Private, msg_ptr) + } + unsafe fn repeated_get_mut_unchecked( + mut f: ::protobuf::Mut<::protobuf::Repeated>, + i: usize, + ) -> ::protobuf::Mut { + let msg_ptr = unsafe { + ::protobuf::__internal::runtime::upb_Array_GetMutable( + f.as_raw(::protobuf::__internal::Private), + i, + ) + }; + unsafe { + ::protobuf::Mut:: { + inner: ::protobuf::__internal::runtime::MutatorMessageRef::from_raw_parts( + msg_ptr, + f.arena(::protobuf::__internal::Private), + ), + } + } + } + fn repeated_clear(mut f: ::protobuf::Mut<::protobuf::Repeated>) { + unsafe { + ::protobuf::__internal::runtime::upb_Array_Resize( + f.as_raw(::protobuf::__internal::Private), + 0, + f.raw_arena(::protobuf::__internal::Private), + ) + }; + } + fn repeated_push( + mut f: ::protobuf::Mut<::protobuf::Repeated>, + v: impl ::protobuf::IntoProxied, + ) { + unsafe { + ::protobuf::__internal::runtime::upb_Array_Append( + f.as_raw(::protobuf::__internal::Private), + ::into_message_value_fuse_if_required( + f.raw_arena(::protobuf::__internal::Private), + v.into_proxied(::protobuf::__internal::Private), + ), + f.raw_arena(::protobuf::__internal::Private), + ); + }; + } + fn repeated_copy_from( + src: ::protobuf::View<::protobuf::Repeated>, + dest: ::protobuf::Mut<::protobuf::Repeated>, + ) { + unsafe { + ::protobuf::__internal::runtime::repeated_message_copy_from( + src, + dest, + ::mini_table(), + ); + } + } + fn repeated_reserve( + mut f: ::protobuf::Mut<::protobuf::Repeated>, + additional: usize, + ) { + unsafe { + let size = ::protobuf::__internal::runtime::upb_Array_Size( + f.as_raw(::protobuf::__internal::Private), + ); + ::protobuf::__internal::runtime::upb_Array_Reserve( + f.as_raw(::protobuf::__internal::Private), + size + additional, + f.raw_arena(::protobuf::__internal::Private), + ); + } + } +} +impl ::protobuf::__internal::runtime::UpbTypeConversions for Feature { + fn upb_type() -> ::protobuf::__internal::runtime::CType { + ::protobuf::__internal::runtime::CType::Message + } + fn to_message_value( + val: ::protobuf::View<'_, Self>, + ) -> ::protobuf::__internal::runtime::upb_MessageValue { + ::protobuf::__internal::runtime::upb_MessageValue { + msg_val: Some(val.raw_msg()), + } + } + unsafe fn into_message_value_fuse_if_required( + raw_parent_arena: ::protobuf::__internal::runtime::RawArena, + mut val: Self, + ) -> ::protobuf::__internal::runtime::upb_MessageValue { + let parent_arena = ::std::mem::ManuallyDrop::new(unsafe { + ::protobuf::__internal::runtime::Arena::from_raw(raw_parent_arena) + }); + parent_arena + .fuse(val.as_mutator_message_ref(::protobuf::__internal::Private).arena()); + ::protobuf::__internal::runtime::upb_MessageValue { + msg_val: Some(val.raw_msg()), + } + } + unsafe fn from_message_value<'msg>( + msg: ::protobuf::__internal::runtime::upb_MessageValue, + ) -> ::protobuf::View<'msg, Self> { + FeatureView::new( + ::protobuf::__internal::Private, + unsafe { msg.msg_val }.expect("expected present message value in map"), + ) + } + unsafe fn from_message_mut<'msg>( + msg: *mut ::protobuf::__internal::runtime::upb_Message, + arena: &'msg ::protobuf::__internal::runtime::Arena, + ) -> FeatureMut<'msg> { + FeatureMut { + inner: unsafe { + ::protobuf::__internal::runtime::MutatorMessageRef::from_raw_parts( + std::ptr::NonNull::new(msg) + .expect("expected present message value in map"), + arena, + ) + }, + } + } +} +#[allow(dead_code)] +#[allow(non_camel_case_types)] +pub struct FeatureMut<'msg> { + inner: ::protobuf::__internal::runtime::MutatorMessageRef<'msg>, +} +impl<'msg> ::protobuf::__internal::SealedInternal for FeatureMut<'msg> {} +impl<'msg> ::protobuf::MessageMut<'msg> for FeatureMut<'msg> { + type Message = Feature; +} +impl ::std::fmt::Debug for FeatureMut<'_> { + fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { + let string = unsafe { + ::protobuf::__internal::runtime::debug_string( + self.raw_msg(), + ::mini_table(), + ) + }; + write!(f, "{}", string) + } +} +impl ::protobuf::Serialize for FeatureMut<'_> { + fn serialize(&self) -> ::std::result::Result, ::protobuf::SerializeError> { + ::protobuf::AsView::as_view(self).serialize() + } +} +impl ::protobuf::Clear for FeatureMut<'_> { + fn clear(&mut self) { + unsafe { + ::protobuf::__internal::runtime::upb_Message_Clear( + self.raw_msg(), + ::mini_table(), + ) + } + } +} +impl ::protobuf::ClearAndParse for FeatureMut<'_> { + fn clear_and_parse( + &mut self, + data: &[u8], + ) -> ::std::result::Result<(), ::protobuf::ParseError> { + ::protobuf::Clear::clear(self); + let status = unsafe { + ::protobuf::__internal::runtime::wire::decode( + data, + self.raw_msg(), + ::mini_table(), + self.arena(), + ) + }; + match status { + Ok(_) => Ok(()), + Err(_) => Err(::protobuf::ParseError), + } + } +} +impl ::protobuf::TakeFrom for FeatureMut<'_> { + fn take_from(&mut self, mut src: impl ::protobuf::AsMut) { + let mut src = src.as_mut(); + ::protobuf::CopyFrom::copy_from(self, ::protobuf::AsView::as_view(&src)); + ::protobuf::Clear::clear(&mut src); + } +} +impl ::protobuf::CopyFrom for FeatureMut<'_> { + fn copy_from(&mut self, src: impl ::protobuf::AsView) { + unsafe { + assert!( + ::protobuf::__internal::runtime::upb_Message_DeepCopy(self.raw_msg(), src + .as_view().raw_msg(), < Self as + ::protobuf::__internal::runtime::AssociatedMiniTable >::mini_table(), + self.arena().raw()) + ); + } + } +} +impl ::protobuf::MergeFrom for FeatureMut<'_> { + fn merge_from(&mut self, src: impl ::protobuf::AsView) { + unsafe { + assert!( + ::protobuf::__internal::runtime::upb_Message_MergeFrom(self.raw_msg(), + src.as_view().raw_msg(), < Self as + ::protobuf::__internal::runtime::AssociatedMiniTable >::mini_table(), + ::std::ptr::null(), self.arena().raw()) + ); + } + } +} +#[allow(dead_code)] +impl<'msg> FeatureMut<'msg> { + #[doc(hidden)] + pub fn from_parent( + _private: ::protobuf::__internal::Private, + parent: ::protobuf::__internal::runtime::MutatorMessageRef<'msg>, + msg: ::protobuf::__internal::runtime::RawMessage, + ) -> Self { + Self { + inner: ::protobuf::__internal::runtime::MutatorMessageRef::from_parent( + parent, + msg, + ), + } + } + #[doc(hidden)] + pub fn new( + _private: ::protobuf::__internal::Private, + msg: &'msg mut ::protobuf::__internal::runtime::MessageInner, + ) -> Self { + Self { + inner: ::protobuf::__internal::runtime::MutatorMessageRef::new(msg), + } + } + fn raw_msg(&self) -> ::protobuf::__internal::runtime::RawMessage { + self.inner.msg() + } + #[doc(hidden)] + pub fn as_mutator_message_ref( + &mut self, + _private: ::protobuf::__internal::Private, + ) -> ::protobuf::__internal::runtime::MutatorMessageRef<'msg> { + self.inner + } + pub fn to_owned(&self) -> Feature { + ::protobuf::AsView::as_view(self).to_owned() + } + fn arena(&self) -> &::protobuf::__internal::runtime::Arena { + self.inner.arena() + } + pub fn name(&self) -> ::protobuf::View<'_, ::protobuf::ProtoString> { + let str_view = unsafe { + let f = ::protobuf::__internal::runtime::upb_MiniTable_GetFieldByIndex( + ::mini_table(), + 0, + ); + ::protobuf::__internal::runtime::upb_Message_GetString( + self.raw_msg(), + f, + (b"").into(), + ) + }; + unsafe { ::protobuf::ProtoStr::from_utf8_unchecked(str_view.as_ref()) } + } + pub fn set_name( + &mut self, + val: impl ::protobuf::IntoProxied<::protobuf::ProtoString>, + ) { + let s = val.into_proxied(::protobuf::__internal::Private); + let (view, arena) = s + .into_inner(::protobuf::__internal::Private) + .into_raw_parts(); + let mm_ref = self.as_mutator_message_ref(::protobuf::__internal::Private); + let parent_arena = mm_ref.arena(); + parent_arena.fuse(&arena); + unsafe { + let f = ::protobuf::__internal::runtime::upb_MiniTable_GetFieldByIndex( + ::mini_table(), + 0, + ); + ::protobuf::__internal::runtime::upb_Message_SetBaseFieldString( + self.as_mutator_message_ref(::protobuf::__internal::Private).msg(), + f, + view, + ); + } + } + pub fn has_location(&self) -> bool { + unsafe { + let f = ::protobuf::__internal::runtime::upb_MiniTable_GetFieldByIndex( + ::mini_table(), + 1, + ); + ::protobuf::__internal::runtime::upb_Message_HasBaseField(self.raw_msg(), f) + } + } + pub fn clear_location(&mut self) { + unsafe { + let mt = ::mini_table(); + let f = ::protobuf::__internal::runtime::upb_MiniTable_GetFieldByIndex( + mt, + 1, + ); + ::protobuf::__internal::runtime::upb_Message_ClearBaseField( + self.raw_msg(), + f, + ); + } + } + pub fn location_opt(&self) -> ::protobuf::Optional> { + ::protobuf::Optional::new(self.location(), self.has_location()) + } + pub fn location(&self) -> super::PointView<'_> { + let submsg = unsafe { + let f = ::protobuf::__internal::runtime::upb_MiniTable_GetFieldByIndex( + ::mini_table(), + 1, + ); + ::protobuf::__internal::runtime::upb_Message_GetMessage(self.raw_msg(), f) + }; + match submsg { + None => { + super::PointView::new( + ::protobuf::__internal::Private, + ::protobuf::__internal::runtime::ScratchSpace::zeroed_block(), + ) + } + Some(sub_raw_msg) => { + super::PointView::new(::protobuf::__internal::Private, sub_raw_msg) + } + } + } + pub fn location_mut(&mut self) -> super::PointMut<'_> { + let raw_msg = unsafe { + let mt = ::mini_table(); + let f = ::protobuf::__internal::runtime::upb_MiniTable_GetFieldByIndex( + mt, + 1, + ); + ::protobuf::__internal::runtime::upb_Message_GetOrCreateMutableMessage( + self.raw_msg(), + mt, + f, + self.arena().raw(), + ) + .unwrap() + }; + super::PointMut::from_parent( + ::protobuf::__internal::Private, + self.as_mutator_message_ref(::protobuf::__internal::Private), + raw_msg, + ) + } + pub fn set_location(&mut self, val: impl ::protobuf::IntoProxied) { + let mut msg = val.into_proxied(::protobuf::__internal::Private); + self.as_mutator_message_ref(::protobuf::__internal::Private) + .arena() + .fuse(msg.as_mutator_message_ref(::protobuf::__internal::Private).arena()); + unsafe { + let f = ::protobuf::__internal::runtime::upb_MiniTable_GetFieldByIndex( + ::mini_table(), + 1, + ); + ::protobuf::__internal::runtime::upb_Message_SetBaseFieldMessage( + self.as_mutator_message_ref(::protobuf::__internal::Private).msg(), + f, + msg.as_mutator_message_ref(::protobuf::__internal::Private).msg(), + ); + } + } +} +unsafe impl Sync for FeatureMut<'_> {} +impl<'msg> ::protobuf::Proxy<'msg> for FeatureMut<'msg> {} +impl<'msg> ::protobuf::MutProxy<'msg> for FeatureMut<'msg> {} +impl<'msg> ::protobuf::AsView for FeatureMut<'msg> { + type Proxied = Feature; + fn as_view(&self) -> ::protobuf::View<'_, Feature> { + FeatureView { + msg: self.raw_msg(), + _phantom: ::std::marker::PhantomData, + } + } +} +impl<'msg> ::protobuf::IntoView<'msg> for FeatureMut<'msg> { + fn into_view<'shorter>(self) -> ::protobuf::View<'shorter, Feature> + where + 'msg: 'shorter, + { + FeatureView { + msg: self.raw_msg(), + _phantom: ::std::marker::PhantomData, + } + } +} +impl<'msg> ::protobuf::AsMut for FeatureMut<'msg> { + type MutProxied = Feature; + fn as_mut(&mut self) -> FeatureMut<'msg> { + FeatureMut { inner: self.inner } + } +} +impl<'msg> ::protobuf::IntoMut<'msg> for FeatureMut<'msg> { + fn into_mut<'shorter>(self) -> FeatureMut<'shorter> + where + 'msg: 'shorter, + { + self + } +} +#[allow(dead_code)] +impl Feature { + pub fn new() -> Self { + let arena = ::protobuf::__internal::runtime::Arena::new(); + let raw_msg = unsafe { + ::protobuf::__internal::runtime::upb_Message_New( + ::mini_table(), + arena.raw(), + ) + .unwrap() + }; + Self { + inner: ::protobuf::__internal::runtime::MessageInner { + msg: raw_msg, + arena, + }, + } + } + fn raw_msg(&self) -> ::protobuf::__internal::runtime::RawMessage { + self.inner.msg + } + #[doc(hidden)] + pub fn as_mutator_message_ref( + &mut self, + _private: ::protobuf::__internal::Private, + ) -> ::protobuf::__internal::runtime::MutatorMessageRef { + ::protobuf::__internal::runtime::MutatorMessageRef::new(&mut self.inner) + } + fn arena(&self) -> &::protobuf::__internal::runtime::Arena { + &self.inner.arena + } + pub fn parse(data: &[u8]) -> ::std::result::Result { + let mut msg = Self::new(); + ::protobuf::ClearAndParse::clear_and_parse(&mut msg, data).map(|_| msg) + } + pub fn as_view(&self) -> FeatureView { + FeatureView::new(::protobuf::__internal::Private, self.inner.msg) + } + pub fn as_mut(&mut self) -> FeatureMut { + FeatureMut::new(::protobuf::__internal::Private, &mut self.inner) + } + pub fn name(&self) -> ::protobuf::View<'_, ::protobuf::ProtoString> { + let str_view = unsafe { + let f = ::protobuf::__internal::runtime::upb_MiniTable_GetFieldByIndex( + ::mini_table(), + 0, + ); + ::protobuf::__internal::runtime::upb_Message_GetString( + self.raw_msg(), + f, + (b"").into(), + ) + }; + unsafe { ::protobuf::ProtoStr::from_utf8_unchecked(str_view.as_ref()) } + } + pub fn set_name( + &mut self, + val: impl ::protobuf::IntoProxied<::protobuf::ProtoString>, + ) { + let s = val.into_proxied(::protobuf::__internal::Private); + let (view, arena) = s + .into_inner(::protobuf::__internal::Private) + .into_raw_parts(); + let mm_ref = self.as_mutator_message_ref(::protobuf::__internal::Private); + let parent_arena = mm_ref.arena(); + parent_arena.fuse(&arena); + unsafe { + let f = ::protobuf::__internal::runtime::upb_MiniTable_GetFieldByIndex( + ::mini_table(), + 0, + ); + ::protobuf::__internal::runtime::upb_Message_SetBaseFieldString( + self.as_mutator_message_ref(::protobuf::__internal::Private).msg(), + f, + view, + ); + } + } + pub fn has_location(&self) -> bool { + unsafe { + let f = ::protobuf::__internal::runtime::upb_MiniTable_GetFieldByIndex( + ::mini_table(), + 1, + ); + ::protobuf::__internal::runtime::upb_Message_HasBaseField(self.raw_msg(), f) + } + } + pub fn clear_location(&mut self) { + unsafe { + let mt = ::mini_table(); + let f = ::protobuf::__internal::runtime::upb_MiniTable_GetFieldByIndex( + mt, + 1, + ); + ::protobuf::__internal::runtime::upb_Message_ClearBaseField( + self.raw_msg(), + f, + ); + } + } + pub fn location_opt(&self) -> ::protobuf::Optional> { + ::protobuf::Optional::new(self.location(), self.has_location()) + } + pub fn location(&self) -> super::PointView<'_> { + let submsg = unsafe { + let f = ::protobuf::__internal::runtime::upb_MiniTable_GetFieldByIndex( + ::mini_table(), + 1, + ); + ::protobuf::__internal::runtime::upb_Message_GetMessage(self.raw_msg(), f) + }; + match submsg { + None => { + super::PointView::new( + ::protobuf::__internal::Private, + ::protobuf::__internal::runtime::ScratchSpace::zeroed_block(), + ) + } + Some(sub_raw_msg) => { + super::PointView::new(::protobuf::__internal::Private, sub_raw_msg) + } + } + } + pub fn location_mut(&mut self) -> super::PointMut<'_> { + let raw_msg = unsafe { + let mt = ::mini_table(); + let f = ::protobuf::__internal::runtime::upb_MiniTable_GetFieldByIndex( + mt, + 1, + ); + ::protobuf::__internal::runtime::upb_Message_GetOrCreateMutableMessage( + self.raw_msg(), + mt, + f, + self.arena().raw(), + ) + .unwrap() + }; + super::PointMut::from_parent( + ::protobuf::__internal::Private, + self.as_mutator_message_ref(::protobuf::__internal::Private), + raw_msg, + ) + } + pub fn set_location(&mut self, val: impl ::protobuf::IntoProxied) { + let mut msg = val.into_proxied(::protobuf::__internal::Private); + self.as_mutator_message_ref(::protobuf::__internal::Private) + .arena() + .fuse(msg.as_mutator_message_ref(::protobuf::__internal::Private).arena()); + unsafe { + let f = ::protobuf::__internal::runtime::upb_MiniTable_GetFieldByIndex( + ::mini_table(), + 1, + ); + ::protobuf::__internal::runtime::upb_Message_SetBaseFieldMessage( + self.as_mutator_message_ref(::protobuf::__internal::Private).msg(), + f, + msg.as_mutator_message_ref(::protobuf::__internal::Private).msg(), + ); + } + } +} +impl ::std::ops::Drop for Feature { + fn drop(&mut self) {} +} +impl ::std::clone::Clone for Feature { + fn clone(&self) -> Self { + self.as_view().to_owned() + } +} +impl ::protobuf::AsView for Feature { + type Proxied = Self; + fn as_view(&self) -> FeatureView { + self.as_view() + } +} +impl ::protobuf::AsMut for Feature { + type MutProxied = Self; + fn as_mut(&mut self) -> FeatureMut { + self.as_mut() + } +} +unsafe impl ::protobuf::__internal::runtime::AssociatedMiniTable for Feature { + #[inline(always)] + fn mini_table() -> *const ::protobuf::__internal::runtime::upb_MiniTable { + #[allow(unused_unsafe)] + unsafe { ::std::ptr::addr_of!(routeguide__Feature_msg_init) } + } +} +unsafe impl ::protobuf::__internal::runtime::AssociatedMiniTable for FeatureView<'_> { + #[inline(always)] + fn mini_table() -> *const ::protobuf::__internal::runtime::upb_MiniTable { + #[allow(unused_unsafe)] + unsafe { ::std::ptr::addr_of!(routeguide__Feature_msg_init) } + } +} +unsafe impl ::protobuf::__internal::runtime::AssociatedMiniTable for FeatureMut<'_> { + #[inline(always)] + fn mini_table() -> *const ::protobuf::__internal::runtime::upb_MiniTable { + #[allow(unused_unsafe)] + unsafe { ::std::ptr::addr_of!(routeguide__Feature_msg_init) } + } +} +extern "C" { + /// Opaque static extern for this message's MiniTable, generated + /// by the upb C MiniTable codegen. The only valid way to + /// reference this static is with `std::ptr::addr_of!(..)`. + static routeguide__Feature_msg_init: ::protobuf::__internal::runtime::upb_MiniTable; +} +impl ::protobuf::OwnedMessageInterop for Feature {} +impl<'a> ::protobuf::MessageMutInterop<'a> for FeatureMut<'a> {} +impl<'a> ::protobuf::MessageViewInterop<'a> for FeatureView<'a> { + unsafe fn __unstable_wrap_raw_message(msg: &'a *const ::std::ffi::c_void) -> Self { + Self::new( + ::protobuf::__internal::Private, + ::protobuf::__internal::runtime::RawMessage::new(*msg as *mut _).unwrap(), + ) + } + unsafe fn __unstable_wrap_raw_message_unchecked_lifetime( + msg: *const ::std::ffi::c_void, + ) -> Self { + Self::new( + ::protobuf::__internal::Private, + ::protobuf::__internal::runtime::RawMessage::new(msg as *mut _).unwrap(), + ) + } + fn __unstable_as_raw_message(&self) -> *const ::std::ffi::c_void { + self.msg.as_ptr() as *const _ + } +} +impl ::protobuf::__internal::MatcherEq for Feature { + fn matches(&self, o: &Self) -> bool { + ::protobuf::__internal::MatcherEq::matches( + &::protobuf::AsView::as_view(self), + &::protobuf::AsView::as_view(o), + ) + } +} +impl<'a> ::protobuf::__internal::MatcherEq for FeatureMut<'a> { + fn matches(&self, o: &Self) -> bool { + ::protobuf::__internal::MatcherEq::matches( + &::protobuf::AsView::as_view(self), + &::protobuf::AsView::as_view(o), + ) + } +} +impl<'a> ::protobuf::__internal::MatcherEq for FeatureView<'a> { + fn matches(&self, o: &Self) -> bool { + unsafe { + ::protobuf::__internal::runtime::upb_Message_IsEqual( + self.msg, + o.msg, + ::mini_table(), + 0, + ) + } + } +} diff --git a/codelabs/grpc-rust-getting-started/completed/generated/routeguide.upb_minitable.c b/codelabs/grpc-rust-getting-started/completed/generated/routeguide.upb_minitable.c new file mode 100644 index 00000000..a4893139 --- /dev/null +++ b/codelabs/grpc-rust-getting-started/completed/generated/routeguide.upb_minitable.c @@ -0,0 +1,76 @@ +/* This file was generated by upb_generator from the input file: + * + * routeguide.proto + * + * Do not edit -- your changes will be discarded when the file is + * regenerated. + * NO CHECKED-IN PROTOBUF GENCODE */ + +#include +#include "upb/generated_code_support.h" +#include "routeguide.upb_minitable.h" + +// Must be last. +#include "upb/port/def.inc" + +extern const struct upb_MiniTable UPB_PRIVATE(_kUpb_MiniTable_StaticallyTreeShaken); +static const upb_MiniTableField routeguide_Point__fields[2] = { + {1, 8, 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}, + {2, 12, 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}, +}; + +const upb_MiniTable routeguide__Point_msg_init = { + NULL, + &routeguide_Point__fields[0], + 16, 2, kUpb_ExtMode_NonExtendable, 2, UPB_FASTTABLE_MASK(24), 0, +#ifdef UPB_TRACING_ENABLED + "routeguide.Point", +#endif + UPB_FASTTABLE_INIT({ + {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, + {0x000800003f000008, &upb_psv4_1bt}, + {0x000c00003f000010, &upb_psv4_1bt}, + {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, + }) +}; + +const upb_MiniTable* routeguide__Point_msg_init_ptr = &routeguide__Point_msg_init; +static const upb_MiniTableSubInternal routeguide_Feature__submsgs[1] = { + {.UPB_PRIVATE(submsg) = &routeguide__Point_msg_init_ptr}, +}; + +static const upb_MiniTableField routeguide_Feature__fields[2] = { + {1, 16, 0, kUpb_NoSub, 9, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, + {2, UPB_SIZE(12, 32), 64, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, +}; + +const upb_MiniTable routeguide__Feature_msg_init = { + &routeguide_Feature__submsgs[0], + &routeguide_Feature__fields[0], + UPB_SIZE(24, 40), 2, kUpb_ExtMode_NonExtendable, 2, UPB_FASTTABLE_MASK(8), 0, +#ifdef UPB_TRACING_ENABLED + "routeguide.Feature", +#endif + UPB_FASTTABLE_INIT({ + {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, + {0x001000003f00000a, &upb_pss_1bt}, + }) +}; + +const upb_MiniTable* routeguide__Feature_msg_init_ptr = &routeguide__Feature_msg_init; +static const upb_MiniTable *messages_layout[2] = { + &routeguide__Point_msg_init, + &routeguide__Feature_msg_init, +}; + +const upb_MiniTableFile routeguide_proto_upb_file_layout = { + messages_layout, + NULL, + NULL, + 2, + 0, + 0, +}; + +#include "upb/port/undef.inc" + diff --git a/codelabs/grpc-rust-getting-started/completed/generated/routeguide.upb_minitable.h b/codelabs/grpc-rust-getting-started/completed/generated/routeguide.upb_minitable.h new file mode 100644 index 00000000..8fc2387c --- /dev/null +++ b/codelabs/grpc-rust-getting-started/completed/generated/routeguide.upb_minitable.h @@ -0,0 +1,34 @@ +/* This file was generated by upb_generator from the input file: + * + * routeguide.proto + * + * Do not edit -- your changes will be discarded when the file is + * regenerated. + * NO CHECKED-IN PROTOBUF GENCODE */ + +#ifndef ROUTEGUIDE_PROTO_UPB_H__UPB_MINITABLE_H_ +#define ROUTEGUIDE_PROTO_UPB_H__UPB_MINITABLE_H_ + +#include "upb/generated_code_support.h" + +// Must be last. +#include "upb/port/def.inc" + +#ifdef __cplusplus +extern "C" { +#endif + +extern const upb_MiniTable routeguide__Point_msg_init; +extern const upb_MiniTable* routeguide__Point_msg_init_ptr; +extern const upb_MiniTable routeguide__Feature_msg_init; +extern const upb_MiniTable* routeguide__Feature_msg_init_ptr; + +extern const upb_MiniTableFile routeguide_proto_upb_file_layout; + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#include "upb/port/undef.inc" + +#endif /* ROUTEGUIDE_PROTO_UPB_H__UPB_MINITABLE_H_ */ diff --git a/codelabs/grpc-rust-getting-started/completed/generated/routeguide_grpc.pb.rs b/codelabs/grpc-rust-getting-started/completed/generated/routeguide_grpc.pb.rs new file mode 100644 index 00000000..71411362 --- /dev/null +++ b/codelabs/grpc-rust-getting-started/completed/generated/routeguide_grpc.pb.rs @@ -0,0 +1,296 @@ +/// Generated client implementations. +pub mod route_guide_client { + #![allow( + unused_variables, + dead_code, + missing_docs, + clippy::wildcard_imports, + clippy::let_unit_value, + )] + use tonic::codegen::*; + use tonic::codegen::http::Uri; + /// Interface exported by the server. + #[derive(Debug, Clone)] + pub struct RouteGuideClient { + inner: tonic::client::Grpc, + } + impl RouteGuideClient + where + T: tonic::client::GrpcService, + T::Error: Into, + T::ResponseBody: Body + std::marker::Send + 'static, + ::Error: Into + std::marker::Send, + { + pub fn new(inner: T) -> Self { + let inner = tonic::client::Grpc::new(inner); + Self { inner } + } + pub fn with_origin(inner: T, origin: Uri) -> Self { + let inner = tonic::client::Grpc::with_origin(inner, origin); + Self { inner } + } + pub fn with_interceptor( + inner: T, + interceptor: F, + ) -> RouteGuideClient> + where + F: tonic::service::Interceptor, + T::ResponseBody: Default, + T: tonic::codegen::Service< + http::Request, + Response = http::Response< + >::ResponseBody, + >, + >, + , + >>::Error: Into + std::marker::Send + std::marker::Sync, + { + RouteGuideClient::new(InterceptedService::new(inner, interceptor)) + } + /// Compress requests with the given encoding. + /// + /// This requires the server to support it otherwise it might respond with an + /// error. + #[must_use] + pub fn send_compressed(mut self, encoding: CompressionEncoding) -> Self { + self.inner = self.inner.send_compressed(encoding); + self + } + /// Enable decompressing responses. + #[must_use] + pub fn accept_compressed(mut self, encoding: CompressionEncoding) -> Self { + self.inner = self.inner.accept_compressed(encoding); + self + } + /// Limits the maximum size of a decoded message. + /// + /// Default: `4MB` + #[must_use] + pub fn max_decoding_message_size(mut self, limit: usize) -> Self { + self.inner = self.inner.max_decoding_message_size(limit); + self + } + /// Limits the maximum size of an encoded message. + /// + /// Default: `usize::MAX` + #[must_use] + pub fn max_encoding_message_size(mut self, limit: usize) -> Self { + self.inner = self.inner.max_encoding_message_size(limit); + self + } + /// A simple RPC. + /// + /// Obtains the feature at a given position. + /// + /// A feature with an empty name is returned if there's no feature at the given + /// position. + pub async fn get_feature( + &mut self, + request: impl tonic::IntoRequest, + ) -> std::result::Result, tonic::Status> { + self.inner + .ready() + .await + .map_err(|e| { + tonic::Status::unknown( + format!("Service was not ready: {}", e.into()), + ) + })?; + let codec = tonic_protobuf::ProtoCodec::default(); + let path = http::uri::PathAndQuery::from_static( + "/routeguide.RouteGuide/GetFeature", + ); + let mut req = request.into_request(); + req.extensions_mut() + .insert(GrpcMethod::new("routeguide.RouteGuide", "GetFeature")); + self.inner.unary(req, path, codec).await + } + } +} +/// Generated server implementations. +pub mod route_guide_server { + #![allow( + unused_variables, + dead_code, + missing_docs, + clippy::wildcard_imports, + clippy::let_unit_value, + )] + use tonic::codegen::*; + /// Generated trait containing gRPC methods that should be implemented for use with RouteGuideServer. + #[async_trait] + pub trait RouteGuide: std::marker::Send + std::marker::Sync + 'static { + /// A simple RPC. + /// + /// Obtains the feature at a given position. + /// + /// A feature with an empty name is returned if there's no feature at the given + /// position. + async fn get_feature( + &self, + request: tonic::Request, + ) -> std::result::Result, tonic::Status> { + Err(tonic::Status::unimplemented("Not yet implemented")) + } + } + /// Interface exported by the server. + #[derive(Debug)] + pub struct RouteGuideServer { + inner: Arc, + accept_compression_encodings: EnabledCompressionEncodings, + send_compression_encodings: EnabledCompressionEncodings, + max_decoding_message_size: Option, + max_encoding_message_size: Option, + } + impl RouteGuideServer { + pub fn new(inner: T) -> Self { + Self::from_arc(Arc::new(inner)) + } + pub fn from_arc(inner: Arc) -> Self { + Self { + inner, + accept_compression_encodings: Default::default(), + send_compression_encodings: Default::default(), + max_decoding_message_size: None, + max_encoding_message_size: None, + } + } + pub fn with_interceptor( + inner: T, + interceptor: F, + ) -> InterceptedService + where + F: tonic::service::Interceptor, + { + InterceptedService::new(Self::new(inner), interceptor) + } + /// Enable decompressing requests with the given encoding. + #[must_use] + pub fn accept_compressed(mut self, encoding: CompressionEncoding) -> Self { + self.accept_compression_encodings.enable(encoding); + self + } + /// Compress responses with the given encoding, if the client supports it. + #[must_use] + pub fn send_compressed(mut self, encoding: CompressionEncoding) -> Self { + self.send_compression_encodings.enable(encoding); + self + } + /// Limits the maximum size of a decoded message. + /// + /// Default: `4MB` + #[must_use] + pub fn max_decoding_message_size(mut self, limit: usize) -> Self { + self.max_decoding_message_size = Some(limit); + self + } + /// Limits the maximum size of an encoded message. + /// + /// Default: `usize::MAX` + #[must_use] + pub fn max_encoding_message_size(mut self, limit: usize) -> Self { + self.max_encoding_message_size = Some(limit); + self + } + } + impl tonic::codegen::Service> for RouteGuideServer + where + T: RouteGuide, + B: Body + std::marker::Send + 'static, + B::Error: Into + std::marker::Send + 'static, + { + type Response = http::Response; + type Error = std::convert::Infallible; + type Future = BoxFuture; + fn poll_ready( + &mut self, + _cx: &mut Context<'_>, + ) -> Poll> { + Poll::Ready(Ok(())) + } + fn call(&mut self, req: http::Request) -> Self::Future { + match req.uri().path() { + "/routeguide.RouteGuide/GetFeature" => { + #[allow(non_camel_case_types)] + struct get_featureSvc(pub Arc); + impl tonic::server::UnaryService + for get_featureSvc { + type Response = super::Feature; + type Future = BoxFuture< + tonic::Response, + tonic::Status, + >; + fn call( + &mut self, + request: tonic::Request, + ) -> Self::Future { + let inner = Arc::clone(&self.0); + let fut = async move { + ::get_feature(&inner, request).await + }; + Box::pin(fut) + } + } + let accept_compression_encodings = self.accept_compression_encodings; + let send_compression_encodings = self.send_compression_encodings; + let max_decoding_message_size = self.max_decoding_message_size; + let max_encoding_message_size = self.max_encoding_message_size; + let inner = self.inner.clone(); + let fut = async move { + let method = get_featureSvc(inner); + let codec = tonic_protobuf::ProtoCodec::default(); + let mut grpc = tonic::server::Grpc::new(codec) + .apply_compression_config( + accept_compression_encodings, + send_compression_encodings, + ) + .apply_max_message_size_config( + max_decoding_message_size, + max_encoding_message_size, + ); + let res = grpc.unary(method, req).await; + Ok(res) + }; + Box::pin(fut) + } + _ => { + Box::pin(async move { + let mut response = http::Response::new( + tonic::body::Body::default(), + ); + let headers = response.headers_mut(); + headers + .insert( + tonic::Status::GRPC_STATUS, + (tonic::Code::Unimplemented as i32).into(), + ); + headers + .insert( + http::header::CONTENT_TYPE, + tonic::metadata::GRPC_CONTENT_TYPE, + ); + Ok(response) + }) + } + } + } + } + impl Clone for RouteGuideServer { + fn clone(&self) -> Self { + let inner = self.inner.clone(); + Self { + inner, + accept_compression_encodings: self.accept_compression_encodings, + send_compression_encodings: self.send_compression_encodings, + max_decoding_message_size: self.max_decoding_message_size, + max_encoding_message_size: self.max_encoding_message_size, + } + } + } + /// Generated gRPC service name + pub const SERVICE_NAME: &str = "routeguide.RouteGuide"; + impl tonic::server::NamedService for RouteGuideServer { + const NAME: &'static str = SERVICE_NAME; + } +} diff --git a/codelabs/grpc-rust-getting-started/completed/proto/routeguide.proto b/codelabs/grpc-rust-getting-started/completed/proto/routeguide.proto new file mode 100644 index 00000000..698fe845 --- /dev/null +++ b/codelabs/grpc-rust-getting-started/completed/proto/routeguide.proto @@ -0,0 +1,51 @@ +// Copyright 2015 gRPC 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. + +syntax = "proto3"; + +option java_multiple_files = true; +option java_package = "io.grpc.examples.routeguide"; +option java_outer_classname = "RouteGuideProto"; + +package routeguide; + +// Interface exported by the server. +service RouteGuide { + // A simple RPC. + // + // Obtains the feature at a given position. + // + // A feature with an empty name is returned if there's no feature at the given + // position. + rpc GetFeature(Point) returns (Feature) {} +} + +message Point { + int32 latitude = 1; + int32 longitude = 2; +} + +// A feature names something at a given point. +// +// If a feature could not be named, the name is empty. +message Feature { + // The name of the feature. + string name = 1; + + // The point where the feature is detected. + Point location = 2; +} + + + diff --git a/codelabs/grpc-rust-getting-started/completed/protoc-31.1-linux-x86_64.zip b/codelabs/grpc-rust-getting-started/completed/protoc-31.1-linux-x86_64.zip new file mode 100644 index 00000000..f8445f93 Binary files /dev/null and b/codelabs/grpc-rust-getting-started/completed/protoc-31.1-linux-x86_64.zip differ diff --git a/codelabs/grpc-rust-getting-started/completed/src/client/client.rs b/codelabs/grpc-rust-getting-started/completed/src/client/client.rs new file mode 100644 index 00000000..64520c0c --- /dev/null +++ b/codelabs/grpc-rust-getting-started/completed/src/client/client.rs @@ -0,0 +1,47 @@ +use tonic::Request; +use tonic::transport::{Endpoint}; +use protobuf::proto; + +mod grpc_pb { + // Include message code. + include!(concat!( + env!("CARGO_MANIFEST_DIR"), + "/generated/generated.rs" + )); + // Include service code. + include!(concat!( + env!("CARGO_MANIFEST_DIR"), + "/generated/routeguide_grpc.pb.rs" + )); +} + +use grpc_pb::{ + route_guide_client::RouteGuideClient, + Point, +}; + +#[tokio::main] +async fn main() -> Result<(), Box> { + //Create endpoint to connect to + let endpoint = Endpoint::new("http://[::1]:10000")?; + let channel = endpoint.connect().await?; + + // Create a new client + let mut client = RouteGuideClient::new(channel); + + println!("*** SIMPLE RPC ***"); + let point = proto!(Point{ + latitude: 409_146_138, + longitude: -746_188_906 + }); + let response = client + .get_feature(Request::new(point)) + .await?.into_inner(); + + println!("Response = Name = \"{}\", Latitude = {}, Longitude = {}", + response.name(), + response.location().latitude(), + response.location().longitude()); + Ok(()) +} + diff --git a/codelabs/grpc-rust-getting-started/completed/src/data/route_guide_db.json b/codelabs/grpc-rust-getting-started/completed/src/data/route_guide_db.json new file mode 100644 index 00000000..732f0997 --- /dev/null +++ b/codelabs/grpc-rust-getting-started/completed/src/data/route_guide_db.json @@ -0,0 +1,702 @@ +[ + { + "location": { + "latitude": 407838351, + "longitude": -746143763 + }, + "name": "Patriots Path, Mendham, NJ 07945, USA" + }, + { + "location": { + "latitude": 408122808, + "longitude": -743999179 + }, + "name": "101 New Jersey 10, Whippany, NJ 07981, USA" + }, + { + "location": { + "latitude": 413628156, + "longitude": -749015468 + }, + "name": "U.S. 6, Shohola, PA 18458, USA" + }, + { + "location": { + "latitude": 419999544, + "longitude": -740371136 + }, + "name": "5 Conners Road, Kingston, NY 12401, USA" + }, + { + "location": { + "latitude": 414008389, + "longitude": -743951297 + }, + "name": "Mid Hudson Psychiatric Center, New Hampton, NY 10958, USA" + }, + { + "location": { + "latitude": 419611318, + "longitude": -746524769 + }, + "name": "287 Flugertown Road, Livingston Manor, NY 12758, USA" + }, + { + "location": { + "latitude": 406109563, + "longitude": -742186778 + }, + "name": "4001 Tremley Point Road, Linden, NJ 07036, USA" + }, + { + "location": { + "latitude": 416802456, + "longitude": -742370183 + }, + "name": "352 South Mountain Road, Wallkill, NY 12589, USA" + }, + { + "location": { + "latitude": 412950425, + "longitude": -741077389 + }, + "name": "Bailey Turn Road, Harriman, NY 10926, USA" + }, + { + "location": { + "latitude": 412144655, + "longitude": -743949739 + }, + "name": "193-199 Wawayanda Road, Hewitt, NJ 07421, USA" + }, + { + "location": { + "latitude": 415736605, + "longitude": -742847522 + }, + "name": "406-496 Ward Avenue, Pine Bush, NY 12566, USA" + }, + { + "location": { + "latitude": 413843930, + "longitude": -740501726 + }, + "name": "162 Merrill Road, Highland Mills, NY 10930, USA" + }, + { + "location": { + "latitude": 410873075, + "longitude": -744459023 + }, + "name": "Clinton Road, West Milford, NJ 07480, USA" + }, + { + "location": { + "latitude": 412346009, + "longitude": -744026814 + }, + "name": "16 Old Brook Lane, Warwick, NY 10990, USA" + }, + { + "location": { + "latitude": 402948455, + "longitude": -747903913 + }, + "name": "3 Drake Lane, Pennington, NJ 08534, USA" + }, + { + "location": { + "latitude": 406337092, + "longitude": -740122226 + }, + "name": "6324 8th Avenue, Brooklyn, NY 11220, USA" + }, + { + "location": { + "latitude": 406421967, + "longitude": -747727624 + }, + "name": "1 Merck Access Road, Whitehouse Station, NJ 08889, USA" + }, + { + "location": { + "latitude": 416318082, + "longitude": -749677716 + }, + "name": "78-98 Schalck Road, Narrowsburg, NY 12764, USA" + }, + { + "location": { + "latitude": 415301720, + "longitude": -748416257 + }, + "name": "282 Lakeview Drive Road, Highland Lake, NY 12743, USA" + }, + { + "location": { + "latitude": 402647019, + "longitude": -747071791 + }, + "name": "330 Evelyn Avenue, Hamilton Township, NJ 08619, USA" + }, + { + "location": { + "latitude": 412567807, + "longitude": -741058078 + }, + "name": "New York State Reference Route 987E, Southfields, NY 10975, USA" + }, + { + "location": { + "latitude": 416855156, + "longitude": -744420597 + }, + "name": "103-271 Tempaloni Road, Ellenville, NY 12428, USA" + }, + { + "location": { + "latitude": 404663628, + "longitude": -744820157 + }, + "name": "1300 Airport Road, North Brunswick Township, NJ 08902, USA" + }, + { + "location": { + "latitude": 407113723, + "longitude": -749746483 + }, + "name": "" + }, + { + "location": { + "latitude": 402133926, + "longitude": -743613249 + }, + "name": "" + }, + { + "location": { + "latitude": 400273442, + "longitude": -741220915 + }, + "name": "" + }, + { + "location": { + "latitude": 411236786, + "longitude": -744070769 + }, + "name": "" + }, + { + "location": { + "latitude": 411633782, + "longitude": -746784970 + }, + "name": "211-225 Plains Road, Augusta, NJ 07822, USA" + }, + { + "location": { + "latitude": 415830701, + "longitude": -742952812 + }, + "name": "" + }, + { + "location": { + "latitude": 413447164, + "longitude": -748712898 + }, + "name": "165 Pedersen Ridge Road, Milford, PA 18337, USA" + }, + { + "location": { + "latitude": 405047245, + "longitude": -749800722 + }, + "name": "100-122 Locktown Road, Frenchtown, NJ 08825, USA" + }, + { + "location": { + "latitude": 418858923, + "longitude": -746156790 + }, + "name": "" + }, + { + "location": { + "latitude": 417951888, + "longitude": -748484944 + }, + "name": "650-652 Willi Hill Road, Swan Lake, NY 12783, USA" + }, + { + "location": { + "latitude": 407033786, + "longitude": -743977337 + }, + "name": "26 East 3rd Street, New Providence, NJ 07974, USA" + }, + { + "location": { + "latitude": 417548014, + "longitude": -740075041 + }, + "name": "" + }, + { + "location": { + "latitude": 410395868, + "longitude": -744972325 + }, + "name": "" + }, + { + "location": { + "latitude": 404615353, + "longitude": -745129803 + }, + "name": "" + }, + { + "location": { + "latitude": 406589790, + "longitude": -743560121 + }, + "name": "611 Lawrence Avenue, Westfield, NJ 07090, USA" + }, + { + "location": { + "latitude": 414653148, + "longitude": -740477477 + }, + "name": "18 Lannis Avenue, New Windsor, NY 12553, USA" + }, + { + "location": { + "latitude": 405957808, + "longitude": -743255336 + }, + "name": "82-104 Amherst Avenue, Colonia, NJ 07067, USA" + }, + { + "location": { + "latitude": 411733589, + "longitude": -741648093 + }, + "name": "170 Seven Lakes Drive, Sloatsburg, NY 10974, USA" + }, + { + "location": { + "latitude": 412676291, + "longitude": -742606606 + }, + "name": "1270 Lakes Road, Monroe, NY 10950, USA" + }, + { + "location": { + "latitude": 409224445, + "longitude": -748286738 + }, + "name": "509-535 Alphano Road, Great Meadows, NJ 07838, USA" + }, + { + "location": { + "latitude": 406523420, + "longitude": -742135517 + }, + "name": "652 Garden Street, Elizabeth, NJ 07202, USA" + }, + { + "location": { + "latitude": 401827388, + "longitude": -740294537 + }, + "name": "349 Sea Spray Court, Neptune City, NJ 07753, USA" + }, + { + "location": { + "latitude": 410564152, + "longitude": -743685054 + }, + "name": "13-17 Stanley Street, West Milford, NJ 07480, USA" + }, + { + "location": { + "latitude": 408472324, + "longitude": -740726046 + }, + "name": "47 Industrial Avenue, Teterboro, NJ 07608, USA" + }, + { + "location": { + "latitude": 412452168, + "longitude": -740214052 + }, + "name": "5 White Oak Lane, Stony Point, NY 10980, USA" + }, + { + "location": { + "latitude": 409146138, + "longitude": -746188906 + }, + "name": "Berkshire Valley Management Area Trail, Jefferson, NJ, USA" + }, + { + "location": { + "latitude": 404701380, + "longitude": -744781745 + }, + "name": "1007 Jersey Avenue, New Brunswick, NJ 08901, USA" + }, + { + "location": { + "latitude": 409642566, + "longitude": -746017679 + }, + "name": "6 East Emerald Isle Drive, Lake Hopatcong, NJ 07849, USA" + }, + { + "location": { + "latitude": 408031728, + "longitude": -748645385 + }, + "name": "1358-1474 New Jersey 57, Port Murray, NJ 07865, USA" + }, + { + "location": { + "latitude": 413700272, + "longitude": -742135189 + }, + "name": "367 Prospect Road, Chester, NY 10918, USA" + }, + { + "location": { + "latitude": 404310607, + "longitude": -740282632 + }, + "name": "10 Simon Lake Drive, Atlantic Highlands, NJ 07716, USA" + }, + { + "location": { + "latitude": 409319800, + "longitude": -746201391 + }, + "name": "11 Ward Street, Mount Arlington, NJ 07856, USA" + }, + { + "location": { + "latitude": 406685311, + "longitude": -742108603 + }, + "name": "300-398 Jefferson Avenue, Elizabeth, NJ 07201, USA" + }, + { + "location": { + "latitude": 419018117, + "longitude": -749142781 + }, + "name": "43 Dreher Road, Roscoe, NY 12776, USA" + }, + { + "location": { + "latitude": 412856162, + "longitude": -745148837 + }, + "name": "Swan Street, Pine Island, NY 10969, USA" + }, + { + "location": { + "latitude": 416560744, + "longitude": -746721964 + }, + "name": "66 Pleasantview Avenue, Monticello, NY 12701, USA" + }, + { + "location": { + "latitude": 405314270, + "longitude": -749836354 + }, + "name": "" + }, + { + "location": { + "latitude": 414219548, + "longitude": -743327440 + }, + "name": "" + }, + { + "location": { + "latitude": 415534177, + "longitude": -742900616 + }, + "name": "565 Winding Hills Road, Montgomery, NY 12549, USA" + }, + { + "location": { + "latitude": 406898530, + "longitude": -749127080 + }, + "name": "231 Rocky Run Road, Glen Gardner, NJ 08826, USA" + }, + { + "location": { + "latitude": 407586880, + "longitude": -741670168 + }, + "name": "100 Mount Pleasant Avenue, Newark, NJ 07104, USA" + }, + { + "location": { + "latitude": 400106455, + "longitude": -742870190 + }, + "name": "517-521 Huntington Drive, Manchester Township, NJ 08759, USA" + }, + { + "location": { + "latitude": 400066188, + "longitude": -746793294 + }, + "name": "" + }, + { + "location": { + "latitude": 418803880, + "longitude": -744102673 + }, + "name": "40 Mountain Road, Napanoch, NY 12458, USA" + }, + { + "location": { + "latitude": 414204288, + "longitude": -747895140 + }, + "name": "" + }, + { + "location": { + "latitude": 414777405, + "longitude": -740615601 + }, + "name": "" + }, + { + "location": { + "latitude": 415464475, + "longitude": -747175374 + }, + "name": "48 North Road, Forestburgh, NY 12777, USA" + }, + { + "location": { + "latitude": 404062378, + "longitude": -746376177 + }, + "name": "" + }, + { + "location": { + "latitude": 405688272, + "longitude": -749285130 + }, + "name": "" + }, + { + "location": { + "latitude": 400342070, + "longitude": -748788996 + }, + "name": "" + }, + { + "location": { + "latitude": 401809022, + "longitude": -744157964 + }, + "name": "" + }, + { + "location": { + "latitude": 404226644, + "longitude": -740517141 + }, + "name": "9 Thompson Avenue, Leonardo, NJ 07737, USA" + }, + { + "location": { + "latitude": 410322033, + "longitude": -747871659 + }, + "name": "" + }, + { + "location": { + "latitude": 407100674, + "longitude": -747742727 + }, + "name": "" + }, + { + "location": { + "latitude": 418811433, + "longitude": -741718005 + }, + "name": "213 Bush Road, Stone Ridge, NY 12484, USA" + }, + { + "location": { + "latitude": 415034302, + "longitude": -743850945 + }, + "name": "" + }, + { + "location": { + "latitude": 411349992, + "longitude": -743694161 + }, + "name": "" + }, + { + "location": { + "latitude": 404839914, + "longitude": -744759616 + }, + "name": "1-17 Bergen Court, New Brunswick, NJ 08901, USA" + }, + { + "location": { + "latitude": 414638017, + "longitude": -745957854 + }, + "name": "35 Oakland Valley Road, Cuddebackville, NY 12729, USA" + }, + { + "location": { + "latitude": 412127800, + "longitude": -740173578 + }, + "name": "" + }, + { + "location": { + "latitude": 401263460, + "longitude": -747964303 + }, + "name": "" + }, + { + "location": { + "latitude": 412843391, + "longitude": -749086026 + }, + "name": "" + }, + { + "location": { + "latitude": 418512773, + "longitude": -743067823 + }, + "name": "" + }, + { + "location": { + "latitude": 404318328, + "longitude": -740835638 + }, + "name": "42-102 Main Street, Belford, NJ 07718, USA" + }, + { + "location": { + "latitude": 419020746, + "longitude": -741172328 + }, + "name": "" + }, + { + "location": { + "latitude": 404080723, + "longitude": -746119569 + }, + "name": "" + }, + { + "location": { + "latitude": 401012643, + "longitude": -744035134 + }, + "name": "" + }, + { + "location": { + "latitude": 404306372, + "longitude": -741079661 + }, + "name": "" + }, + { + "location": { + "latitude": 403966326, + "longitude": -748519297 + }, + "name": "" + }, + { + "location": { + "latitude": 405002031, + "longitude": -748407866 + }, + "name": "" + }, + { + "location": { + "latitude": 409532885, + "longitude": -742200683 + }, + "name": "" + }, + { + "location": { + "latitude": 416851321, + "longitude": -742674555 + }, + "name": "" + }, + { + "location": { + "latitude": 406411633, + "longitude": -741722051 + }, + "name": "3387 Richmond Terrace, Staten Island, NY 10303, USA" + }, + { + "location": { + "latitude": 413069058, + "longitude": -744597778 + }, + "name": "261 Van Sickle Road, Goshen, NY 10924, USA" + }, + { + "location": { + "latitude": 418465462, + "longitude": -746859398 + }, + "name": "" + }, + { + "location": { + "latitude": 411733222, + "longitude": -744228360 + }, + "name": "" + }, + { + "location": { + "latitude": 410248224, + "longitude": -747127767 + }, + "name": "3 Hasta Way, Newton, NJ 07860, USA" + } +] \ No newline at end of file diff --git a/codelabs/grpc-rust-getting-started/completed/src/server/server.rs b/codelabs/grpc-rust-getting-started/completed/src/server/server.rs new file mode 100644 index 00000000..e00e088b --- /dev/null +++ b/codelabs/grpc-rust-getting-started/completed/src/server/server.rs @@ -0,0 +1,89 @@ +use std::sync::Arc; +use tonic::transport::Server; +use tonic::{Request, Response, Status}; +use serde::Deserialize; +use std::fs::File; +use protobuf::proto; + +mod grpc_pb { + include!(concat!( + env!("CARGO_MANIFEST_DIR"), + "/generated/generated.rs" + )); + include!(concat!( + env!("CARGO_MANIFEST_DIR"), + "/generated/routeguide_grpc.pb.rs" + )); +} + +pub use grpc_pb::{ + route_guide_server::{RouteGuideServer, RouteGuide}, + Point, Feature, +}; + +#[derive(Debug)] +pub struct RouteGuideService { + features: Arc>, +} + +#[tonic::async_trait] +impl RouteGuide for RouteGuideService { + async fn get_feature(&self, request: Request) -> Result, Status> { + println!("GetFeature = {:?}", request); + let requested_point = request.get_ref(); + for feature in self.features.iter() { + if feature.location().latitude() == requested_point.latitude() { + if feature.location().longitude() == requested_point.longitude(){ + return Ok(Response::new(feature.clone())) + }; + }; + } + Ok(Response::new(Feature::default())) + } +} + +#[tokio::main] +async fn main() -> Result<(), Box> { + let addr = "[::1]:10000".parse().unwrap(); + println!("RouteGuideServer listening on: {addr}"); + let route_guide = RouteGuideService { + features: Arc::new(load()), + }; + let svc = RouteGuideServer::new(route_guide); + Server::builder().add_service(svc).serve(addr).await?; + Ok(()) +} + +#[derive(Debug, Deserialize)] +struct JsonFeature { + location: Location, + name: String, +} + +#[derive(Debug, Deserialize)] +struct Location { + latitude: i32, + longitude: i32, +} + +#[allow(dead_code)] +pub fn load() -> Vec { + let data_dir = std::path::PathBuf::from_iter([ + std::env!("CARGO_MANIFEST_DIR"), + "src", + "data" + ]); + let file = File::open(data_dir.join("route_guide_db.json")).expect("failed to open data file"); + let decoded: Vec = + serde_json::from_reader(&file).expect("failed to deserialize features"); + decoded + .into_iter() + .map(|feature| proto!(Feature { + name: feature.name, + location: proto!(Point { + longitude: feature.location.longitude, + latitude: feature.location.latitude, + }), + })) + .collect() +} \ No newline at end of file diff --git a/codelabs/grpc-rust-getting-started/start_here/Cargo.toml b/codelabs/grpc-rust-getting-started/start_here/Cargo.toml new file mode 100644 index 00000000..06c8cc0f --- /dev/null +++ b/codelabs/grpc-rust-getting-started/start_here/Cargo.toml @@ -0,0 +1,36 @@ +[package] +edition = "2021" +license = "MIT" +name = "getting-started" + +[features] +routeguide = ["dep:async-stream", "dep:tokio-stream", "dep:rand", "dep:serde", "dep:serde_json"] +full = ["routeguide"] +default = ["full"] + +[dependencies] +# Common dependencies +tokio = { version = "1.0", features = ["rt-multi-thread", "macros"] } +prost = "0.14" +tonic = { git = "https://github.com/hyperium/tonic", branch="master"} +tonic-protobuf = {git = "https://github.com/hyperium/tonic", branch="master", package = "tonic-protobuf" } +grpc = {git = "https://github.com/hyperium/tonic", branch="master", package = "grpc"} +# Optional dependencies +async-stream = { version = "0.3", optional = true } +tokio-stream = { version = "0.1", optional = true } +tokio-util = { version = "0.7.8", optional = true } +tower = { version = "0.5", optional = true } +rand = { version = "0.9", optional = true } +serde = { version = "1.0", features = ["derive"], optional = true } +serde_json = { version = "1.0", optional = true } +prost-types = { version = "0.14", optional = true } +http = { version = "1", optional = true } +hyper = { version = "1", optional = true } +hyper-util = { version = "0.1.4", optional = true } +tokio-rustls = { version = "0.26.1", optional = true, features = ["ring", "tls12"], default-features = false } +hyper-rustls = { version = "0.27.0", features = ["http2", "ring", "tls12"], optional = true, default-features = false } +tower-http = { version = "0.6", optional = true } +protobuf = { version = "4.31.1-release"} + +[build-dependencies] +protobuf-codegen = { version = "4.31.1-release"} diff --git a/codelabs/grpc-rust-getting-started/start_here/build.rs b/codelabs/grpc-rust-getting-started/start_here/build.rs new file mode 100644 index 00000000..b12def9b --- /dev/null +++ b/codelabs/grpc-rust-getting-started/start_here/build.rs @@ -0,0 +1,9 @@ +fn main() { + protobuf_codegen::CodeGen::new() + .include("proto") + .inputs(["routeguide.proto"]) + .output_dir("generated") + .compile_only() + .unwrap(); +} + diff --git a/codelabs/grpc-rust-getting-started/start_here/generated/crate_mapping.txt b/codelabs/grpc-rust-getting-started/start_here/generated/crate_mapping.txt new file mode 100644 index 00000000..e69de29b diff --git a/codelabs/grpc-rust-getting-started/start_here/generated/generated.rs b/codelabs/grpc-rust-getting-started/start_here/generated/generated.rs new file mode 100644 index 00000000..3bd5dfb0 --- /dev/null +++ b/codelabs/grpc-rust-getting-started/start_here/generated/generated.rs @@ -0,0 +1,5 @@ +#[path = "routeguide.u.pb.rs"] +#[allow(nonstandard_style)] +pub mod internal_do_not_use_routeguide; +#[allow(unused_imports, nonstandard_style)] +pub use internal_do_not_use_routeguide::*; diff --git a/codelabs/grpc-rust-getting-started/start_here/generated/routeguide.u.pb.rs b/codelabs/grpc-rust-getting-started/start_here/generated/routeguide.u.pb.rs new file mode 100644 index 00000000..229dead8 --- /dev/null +++ b/codelabs/grpc-rust-getting-started/start_here/generated/routeguide.u.pb.rs @@ -0,0 +1,1743 @@ +const _: () = ::protobuf::__internal::assert_compatible_gencode_version( + "4.31.1-release", +); +#[allow(non_camel_case_types)] +pub struct Point { + inner: ::protobuf::__internal::runtime::MessageInner, +} +impl ::protobuf::Message for Point {} +impl ::std::default::Default for Point { + fn default() -> Self { + Self::new() + } +} +impl ::protobuf::Parse for Point { + fn parse(serialized: &[u8]) -> ::std::result::Result { + Self::parse(serialized) + } +} +impl ::std::fmt::Debug for Point { + fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { + let string = unsafe { + ::protobuf::__internal::runtime::debug_string( + self.raw_msg(), + ::mini_table(), + ) + }; + write!(f, "{}", string) + } +} +impl ::protobuf::TakeFrom for Point { + fn take_from(&mut self, src: impl ::protobuf::AsMut) { + let mut m = self.as_mut(); + ::protobuf::TakeFrom::take_from(&mut m, src) + } +} +impl ::protobuf::CopyFrom for Point { + fn copy_from(&mut self, src: impl ::protobuf::AsView) { + let mut m = self.as_mut(); + ::protobuf::CopyFrom::copy_from(&mut m, src) + } +} +impl ::protobuf::MergeFrom for Point { + fn merge_from<'src>(&mut self, src: impl ::protobuf::AsView) { + let mut m = self.as_mut(); + ::protobuf::MergeFrom::merge_from(&mut m, src) + } +} +impl ::protobuf::Serialize for Point { + fn serialize(&self) -> ::std::result::Result, ::protobuf::SerializeError> { + ::protobuf::AsView::as_view(self).serialize() + } +} +impl ::protobuf::Clear for Point { + fn clear(&mut self) { + let mut m = self.as_mut(); + ::protobuf::Clear::clear(&mut m) + } +} +impl ::protobuf::ClearAndParse for Point { + fn clear_and_parse( + &mut self, + data: &[u8], + ) -> ::std::result::Result<(), ::protobuf::ParseError> { + let mut m = self.as_mut(); + ::protobuf::ClearAndParse::clear_and_parse(&mut m, data) + } +} +unsafe impl Sync for Point {} +unsafe impl Send for Point {} +impl ::protobuf::Proxied for Point { + type View<'msg> = PointView<'msg>; +} +impl ::protobuf::__internal::SealedInternal for Point {} +impl ::protobuf::MutProxied for Point { + type Mut<'msg> = PointMut<'msg>; +} +#[derive(Copy, Clone)] +#[allow(dead_code)] +pub struct PointView<'msg> { + msg: ::protobuf::__internal::runtime::RawMessage, + _phantom: ::std::marker::PhantomData<&'msg ()>, +} +impl<'msg> ::protobuf::__internal::SealedInternal for PointView<'msg> {} +impl<'msg> ::protobuf::MessageView<'msg> for PointView<'msg> { + type Message = Point; +} +impl ::std::fmt::Debug for PointView<'_> { + fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { + let string = unsafe { + ::protobuf::__internal::runtime::debug_string( + self.raw_msg(), + ::mini_table(), + ) + }; + write!(f, "{}", string) + } +} +impl ::protobuf::Serialize for PointView<'_> { + fn serialize(&self) -> ::std::result::Result, ::protobuf::SerializeError> { + let encoded = unsafe { + ::protobuf::__internal::runtime::wire::encode( + self.raw_msg(), + ::mini_table(), + ) + }; + encoded.map_err(|_| ::protobuf::SerializeError) + } +} +impl ::std::default::Default for PointView<'_> { + fn default() -> PointView<'static> { + PointView::new( + ::protobuf::__internal::Private, + ::protobuf::__internal::runtime::ScratchSpace::zeroed_block(), + ) + } +} +#[allow(dead_code)] +impl<'msg> PointView<'msg> { + #[doc(hidden)] + pub fn new( + _private: ::protobuf::__internal::Private, + msg: ::protobuf::__internal::runtime::RawMessage, + ) -> Self { + Self { + msg, + _phantom: ::std::marker::PhantomData, + } + } + fn raw_msg(&self) -> ::protobuf::__internal::runtime::RawMessage { + self.msg + } + pub fn to_owned(&self) -> Point { + ::protobuf::IntoProxied::into_proxied(*self, ::protobuf::__internal::Private) + } + pub fn latitude(self) -> i32 { + unsafe { + let mt = ::mini_table(); + let f = ::protobuf::__internal::runtime::upb_MiniTable_GetFieldByIndex( + mt, + 0, + ); + ::protobuf::__internal::runtime::upb_Message_GetInt32( + self.raw_msg(), + f, + (0i32).into(), + ) + .try_into() + .unwrap() + } + } + pub fn longitude(self) -> i32 { + unsafe { + let mt = ::mini_table(); + let f = ::protobuf::__internal::runtime::upb_MiniTable_GetFieldByIndex( + mt, + 1, + ); + ::protobuf::__internal::runtime::upb_Message_GetInt32( + self.raw_msg(), + f, + (0i32).into(), + ) + .try_into() + .unwrap() + } + } +} +unsafe impl Sync for PointView<'_> {} +unsafe impl Send for PointView<'_> {} +impl<'msg> ::protobuf::Proxy<'msg> for PointView<'msg> {} +impl<'msg> ::protobuf::ViewProxy<'msg> for PointView<'msg> {} +impl<'msg> ::protobuf::AsView for PointView<'msg> { + type Proxied = Point; + fn as_view(&self) -> ::protobuf::View<'msg, Point> { + *self + } +} +impl<'msg> ::protobuf::IntoView<'msg> for PointView<'msg> { + fn into_view<'shorter>(self) -> PointView<'shorter> + where + 'msg: 'shorter, + { + self + } +} +impl<'msg> ::protobuf::IntoProxied for PointView<'msg> { + fn into_proxied(self, _private: ::protobuf::__internal::Private) -> Point { + let dst = Point::new(); + unsafe { + ::protobuf::__internal::runtime::upb_Message_DeepCopy( + dst.inner.msg, + self.msg, + ::mini_table(), + dst.inner.arena.raw(), + ) + }; + dst + } +} +impl<'msg> ::protobuf::IntoProxied for PointMut<'msg> { + fn into_proxied(self, _private: ::protobuf::__internal::Private) -> Point { + ::protobuf::IntoProxied::into_proxied( + ::protobuf::IntoView::into_view(self), + _private, + ) + } +} +unsafe impl ::protobuf::ProxiedInRepeated for Point { + fn repeated_new( + _private: ::protobuf::__internal::Private, + ) -> ::protobuf::Repeated { + let arena = ::protobuf::__internal::runtime::Arena::new(); + unsafe { + ::protobuf::Repeated::from_inner( + ::protobuf::__internal::Private, + ::protobuf::__internal::runtime::InnerRepeated::from_raw_parts( + ::protobuf::__internal::runtime::upb_Array_New( + arena.raw(), + ::protobuf::__internal::runtime::CType::Message, + ), + arena, + ), + ) + } + } + unsafe fn repeated_free( + _private: ::protobuf::__internal::Private, + _f: &mut ::protobuf::Repeated, + ) {} + fn repeated_len(f: ::protobuf::View<::protobuf::Repeated>) -> usize { + unsafe { + ::protobuf::__internal::runtime::upb_Array_Size( + f.as_raw(::protobuf::__internal::Private), + ) + } + } + unsafe fn repeated_set_unchecked( + mut f: ::protobuf::Mut<::protobuf::Repeated>, + i: usize, + v: impl ::protobuf::IntoProxied, + ) { + unsafe { + ::protobuf::__internal::runtime::upb_Array_Set( + f.as_raw(::protobuf::__internal::Private), + i, + ::into_message_value_fuse_if_required( + f.raw_arena(::protobuf::__internal::Private), + v.into_proxied(::protobuf::__internal::Private), + ), + ) + } + } + unsafe fn repeated_get_unchecked( + f: ::protobuf::View<::protobuf::Repeated>, + i: usize, + ) -> ::protobuf::View { + let msg_ptr = unsafe { + ::protobuf::__internal::runtime::upb_Array_Get( + f.as_raw(::protobuf::__internal::Private), + i, + ) + .msg_val + } + .expect("upb_Array* element should not be NULL."); + ::protobuf::View::::new(::protobuf::__internal::Private, msg_ptr) + } + unsafe fn repeated_get_mut_unchecked( + mut f: ::protobuf::Mut<::protobuf::Repeated>, + i: usize, + ) -> ::protobuf::Mut { + let msg_ptr = unsafe { + ::protobuf::__internal::runtime::upb_Array_GetMutable( + f.as_raw(::protobuf::__internal::Private), + i, + ) + }; + unsafe { + ::protobuf::Mut:: { + inner: ::protobuf::__internal::runtime::MutatorMessageRef::from_raw_parts( + msg_ptr, + f.arena(::protobuf::__internal::Private), + ), + } + } + } + fn repeated_clear(mut f: ::protobuf::Mut<::protobuf::Repeated>) { + unsafe { + ::protobuf::__internal::runtime::upb_Array_Resize( + f.as_raw(::protobuf::__internal::Private), + 0, + f.raw_arena(::protobuf::__internal::Private), + ) + }; + } + fn repeated_push( + mut f: ::protobuf::Mut<::protobuf::Repeated>, + v: impl ::protobuf::IntoProxied, + ) { + unsafe { + ::protobuf::__internal::runtime::upb_Array_Append( + f.as_raw(::protobuf::__internal::Private), + ::into_message_value_fuse_if_required( + f.raw_arena(::protobuf::__internal::Private), + v.into_proxied(::protobuf::__internal::Private), + ), + f.raw_arena(::protobuf::__internal::Private), + ); + }; + } + fn repeated_copy_from( + src: ::protobuf::View<::protobuf::Repeated>, + dest: ::protobuf::Mut<::protobuf::Repeated>, + ) { + unsafe { + ::protobuf::__internal::runtime::repeated_message_copy_from( + src, + dest, + ::mini_table(), + ); + } + } + fn repeated_reserve( + mut f: ::protobuf::Mut<::protobuf::Repeated>, + additional: usize, + ) { + unsafe { + let size = ::protobuf::__internal::runtime::upb_Array_Size( + f.as_raw(::protobuf::__internal::Private), + ); + ::protobuf::__internal::runtime::upb_Array_Reserve( + f.as_raw(::protobuf::__internal::Private), + size + additional, + f.raw_arena(::protobuf::__internal::Private), + ); + } + } +} +impl ::protobuf::__internal::runtime::UpbTypeConversions for Point { + fn upb_type() -> ::protobuf::__internal::runtime::CType { + ::protobuf::__internal::runtime::CType::Message + } + fn to_message_value( + val: ::protobuf::View<'_, Self>, + ) -> ::protobuf::__internal::runtime::upb_MessageValue { + ::protobuf::__internal::runtime::upb_MessageValue { + msg_val: Some(val.raw_msg()), + } + } + unsafe fn into_message_value_fuse_if_required( + raw_parent_arena: ::protobuf::__internal::runtime::RawArena, + mut val: Self, + ) -> ::protobuf::__internal::runtime::upb_MessageValue { + let parent_arena = ::std::mem::ManuallyDrop::new(unsafe { + ::protobuf::__internal::runtime::Arena::from_raw(raw_parent_arena) + }); + parent_arena + .fuse(val.as_mutator_message_ref(::protobuf::__internal::Private).arena()); + ::protobuf::__internal::runtime::upb_MessageValue { + msg_val: Some(val.raw_msg()), + } + } + unsafe fn from_message_value<'msg>( + msg: ::protobuf::__internal::runtime::upb_MessageValue, + ) -> ::protobuf::View<'msg, Self> { + PointView::new( + ::protobuf::__internal::Private, + unsafe { msg.msg_val }.expect("expected present message value in map"), + ) + } + unsafe fn from_message_mut<'msg>( + msg: *mut ::protobuf::__internal::runtime::upb_Message, + arena: &'msg ::protobuf::__internal::runtime::Arena, + ) -> PointMut<'msg> { + PointMut { + inner: unsafe { + ::protobuf::__internal::runtime::MutatorMessageRef::from_raw_parts( + std::ptr::NonNull::new(msg) + .expect("expected present message value in map"), + arena, + ) + }, + } + } +} +#[allow(dead_code)] +#[allow(non_camel_case_types)] +pub struct PointMut<'msg> { + inner: ::protobuf::__internal::runtime::MutatorMessageRef<'msg>, +} +impl<'msg> ::protobuf::__internal::SealedInternal for PointMut<'msg> {} +impl<'msg> ::protobuf::MessageMut<'msg> for PointMut<'msg> { + type Message = Point; +} +impl ::std::fmt::Debug for PointMut<'_> { + fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { + let string = unsafe { + ::protobuf::__internal::runtime::debug_string( + self.raw_msg(), + ::mini_table(), + ) + }; + write!(f, "{}", string) + } +} +impl ::protobuf::Serialize for PointMut<'_> { + fn serialize(&self) -> ::std::result::Result, ::protobuf::SerializeError> { + ::protobuf::AsView::as_view(self).serialize() + } +} +impl ::protobuf::Clear for PointMut<'_> { + fn clear(&mut self) { + unsafe { + ::protobuf::__internal::runtime::upb_Message_Clear( + self.raw_msg(), + ::mini_table(), + ) + } + } +} +impl ::protobuf::ClearAndParse for PointMut<'_> { + fn clear_and_parse( + &mut self, + data: &[u8], + ) -> ::std::result::Result<(), ::protobuf::ParseError> { + ::protobuf::Clear::clear(self); + let status = unsafe { + ::protobuf::__internal::runtime::wire::decode( + data, + self.raw_msg(), + ::mini_table(), + self.arena(), + ) + }; + match status { + Ok(_) => Ok(()), + Err(_) => Err(::protobuf::ParseError), + } + } +} +impl ::protobuf::TakeFrom for PointMut<'_> { + fn take_from(&mut self, mut src: impl ::protobuf::AsMut) { + let mut src = src.as_mut(); + ::protobuf::CopyFrom::copy_from(self, ::protobuf::AsView::as_view(&src)); + ::protobuf::Clear::clear(&mut src); + } +} +impl ::protobuf::CopyFrom for PointMut<'_> { + fn copy_from(&mut self, src: impl ::protobuf::AsView) { + unsafe { + assert!( + ::protobuf::__internal::runtime::upb_Message_DeepCopy(self.raw_msg(), src + .as_view().raw_msg(), < Self as + ::protobuf::__internal::runtime::AssociatedMiniTable >::mini_table(), + self.arena().raw()) + ); + } + } +} +impl ::protobuf::MergeFrom for PointMut<'_> { + fn merge_from(&mut self, src: impl ::protobuf::AsView) { + unsafe { + assert!( + ::protobuf::__internal::runtime::upb_Message_MergeFrom(self.raw_msg(), + src.as_view().raw_msg(), < Self as + ::protobuf::__internal::runtime::AssociatedMiniTable >::mini_table(), + ::std::ptr::null(), self.arena().raw()) + ); + } + } +} +#[allow(dead_code)] +impl<'msg> PointMut<'msg> { + #[doc(hidden)] + pub fn from_parent( + _private: ::protobuf::__internal::Private, + parent: ::protobuf::__internal::runtime::MutatorMessageRef<'msg>, + msg: ::protobuf::__internal::runtime::RawMessage, + ) -> Self { + Self { + inner: ::protobuf::__internal::runtime::MutatorMessageRef::from_parent( + parent, + msg, + ), + } + } + #[doc(hidden)] + pub fn new( + _private: ::protobuf::__internal::Private, + msg: &'msg mut ::protobuf::__internal::runtime::MessageInner, + ) -> Self { + Self { + inner: ::protobuf::__internal::runtime::MutatorMessageRef::new(msg), + } + } + fn raw_msg(&self) -> ::protobuf::__internal::runtime::RawMessage { + self.inner.msg() + } + #[doc(hidden)] + pub fn as_mutator_message_ref( + &mut self, + _private: ::protobuf::__internal::Private, + ) -> ::protobuf::__internal::runtime::MutatorMessageRef<'msg> { + self.inner + } + pub fn to_owned(&self) -> Point { + ::protobuf::AsView::as_view(self).to_owned() + } + fn arena(&self) -> &::protobuf::__internal::runtime::Arena { + self.inner.arena() + } + pub fn latitude(&self) -> i32 { + unsafe { + let mt = ::mini_table(); + let f = ::protobuf::__internal::runtime::upb_MiniTable_GetFieldByIndex( + mt, + 0, + ); + ::protobuf::__internal::runtime::upb_Message_GetInt32( + self.raw_msg(), + f, + (0i32).into(), + ) + .try_into() + .unwrap() + } + } + pub fn set_latitude(&mut self, val: i32) { + unsafe { + let mt = ::mini_table(); + let f = ::protobuf::__internal::runtime::upb_MiniTable_GetFieldByIndex( + mt, + 0, + ); + ::protobuf::__internal::runtime::upb_Message_SetBaseFieldInt32( + self.raw_msg(), + f, + val.into(), + ); + } + } + pub fn longitude(&self) -> i32 { + unsafe { + let mt = ::mini_table(); + let f = ::protobuf::__internal::runtime::upb_MiniTable_GetFieldByIndex( + mt, + 1, + ); + ::protobuf::__internal::runtime::upb_Message_GetInt32( + self.raw_msg(), + f, + (0i32).into(), + ) + .try_into() + .unwrap() + } + } + pub fn set_longitude(&mut self, val: i32) { + unsafe { + let mt = ::mini_table(); + let f = ::protobuf::__internal::runtime::upb_MiniTable_GetFieldByIndex( + mt, + 1, + ); + ::protobuf::__internal::runtime::upb_Message_SetBaseFieldInt32( + self.raw_msg(), + f, + val.into(), + ); + } + } +} +unsafe impl Sync for PointMut<'_> {} +impl<'msg> ::protobuf::Proxy<'msg> for PointMut<'msg> {} +impl<'msg> ::protobuf::MutProxy<'msg> for PointMut<'msg> {} +impl<'msg> ::protobuf::AsView for PointMut<'msg> { + type Proxied = Point; + fn as_view(&self) -> ::protobuf::View<'_, Point> { + PointView { + msg: self.raw_msg(), + _phantom: ::std::marker::PhantomData, + } + } +} +impl<'msg> ::protobuf::IntoView<'msg> for PointMut<'msg> { + fn into_view<'shorter>(self) -> ::protobuf::View<'shorter, Point> + where + 'msg: 'shorter, + { + PointView { + msg: self.raw_msg(), + _phantom: ::std::marker::PhantomData, + } + } +} +impl<'msg> ::protobuf::AsMut for PointMut<'msg> { + type MutProxied = Point; + fn as_mut(&mut self) -> PointMut<'msg> { + PointMut { inner: self.inner } + } +} +impl<'msg> ::protobuf::IntoMut<'msg> for PointMut<'msg> { + fn into_mut<'shorter>(self) -> PointMut<'shorter> + where + 'msg: 'shorter, + { + self + } +} +#[allow(dead_code)] +impl Point { + pub fn new() -> Self { + let arena = ::protobuf::__internal::runtime::Arena::new(); + let raw_msg = unsafe { + ::protobuf::__internal::runtime::upb_Message_New( + ::mini_table(), + arena.raw(), + ) + .unwrap() + }; + Self { + inner: ::protobuf::__internal::runtime::MessageInner { + msg: raw_msg, + arena, + }, + } + } + fn raw_msg(&self) -> ::protobuf::__internal::runtime::RawMessage { + self.inner.msg + } + #[doc(hidden)] + pub fn as_mutator_message_ref( + &mut self, + _private: ::protobuf::__internal::Private, + ) -> ::protobuf::__internal::runtime::MutatorMessageRef { + ::protobuf::__internal::runtime::MutatorMessageRef::new(&mut self.inner) + } + fn arena(&self) -> &::protobuf::__internal::runtime::Arena { + &self.inner.arena + } + pub fn parse(data: &[u8]) -> ::std::result::Result { + let mut msg = Self::new(); + ::protobuf::ClearAndParse::clear_and_parse(&mut msg, data).map(|_| msg) + } + pub fn as_view(&self) -> PointView { + PointView::new(::protobuf::__internal::Private, self.inner.msg) + } + pub fn as_mut(&mut self) -> PointMut { + PointMut::new(::protobuf::__internal::Private, &mut self.inner) + } + pub fn latitude(&self) -> i32 { + unsafe { + let mt = ::mini_table(); + let f = ::protobuf::__internal::runtime::upb_MiniTable_GetFieldByIndex( + mt, + 0, + ); + ::protobuf::__internal::runtime::upb_Message_GetInt32( + self.raw_msg(), + f, + (0i32).into(), + ) + .try_into() + .unwrap() + } + } + pub fn set_latitude(&mut self, val: i32) { + unsafe { + let mt = ::mini_table(); + let f = ::protobuf::__internal::runtime::upb_MiniTable_GetFieldByIndex( + mt, + 0, + ); + ::protobuf::__internal::runtime::upb_Message_SetBaseFieldInt32( + self.raw_msg(), + f, + val.into(), + ); + } + } + pub fn longitude(&self) -> i32 { + unsafe { + let mt = ::mini_table(); + let f = ::protobuf::__internal::runtime::upb_MiniTable_GetFieldByIndex( + mt, + 1, + ); + ::protobuf::__internal::runtime::upb_Message_GetInt32( + self.raw_msg(), + f, + (0i32).into(), + ) + .try_into() + .unwrap() + } + } + pub fn set_longitude(&mut self, val: i32) { + unsafe { + let mt = ::mini_table(); + let f = ::protobuf::__internal::runtime::upb_MiniTable_GetFieldByIndex( + mt, + 1, + ); + ::protobuf::__internal::runtime::upb_Message_SetBaseFieldInt32( + self.raw_msg(), + f, + val.into(), + ); + } + } +} +impl ::std::ops::Drop for Point { + fn drop(&mut self) {} +} +impl ::std::clone::Clone for Point { + fn clone(&self) -> Self { + self.as_view().to_owned() + } +} +impl ::protobuf::AsView for Point { + type Proxied = Self; + fn as_view(&self) -> PointView { + self.as_view() + } +} +impl ::protobuf::AsMut for Point { + type MutProxied = Self; + fn as_mut(&mut self) -> PointMut { + self.as_mut() + } +} +unsafe impl ::protobuf::__internal::runtime::AssociatedMiniTable for Point { + #[inline(always)] + fn mini_table() -> *const ::protobuf::__internal::runtime::upb_MiniTable { + #[allow(unused_unsafe)] + unsafe { ::std::ptr::addr_of!(routeguide__Point_msg_init) } + } +} +unsafe impl ::protobuf::__internal::runtime::AssociatedMiniTable for PointView<'_> { + #[inline(always)] + fn mini_table() -> *const ::protobuf::__internal::runtime::upb_MiniTable { + #[allow(unused_unsafe)] + unsafe { ::std::ptr::addr_of!(routeguide__Point_msg_init) } + } +} +unsafe impl ::protobuf::__internal::runtime::AssociatedMiniTable for PointMut<'_> { + #[inline(always)] + fn mini_table() -> *const ::protobuf::__internal::runtime::upb_MiniTable { + #[allow(unused_unsafe)] + unsafe { ::std::ptr::addr_of!(routeguide__Point_msg_init) } + } +} +extern "C" { + /// Opaque static extern for this message's MiniTable, generated + /// by the upb C MiniTable codegen. The only valid way to + /// reference this static is with `std::ptr::addr_of!(..)`. + static routeguide__Point_msg_init: ::protobuf::__internal::runtime::upb_MiniTable; +} +impl ::protobuf::OwnedMessageInterop for Point {} +impl<'a> ::protobuf::MessageMutInterop<'a> for PointMut<'a> {} +impl<'a> ::protobuf::MessageViewInterop<'a> for PointView<'a> { + unsafe fn __unstable_wrap_raw_message(msg: &'a *const ::std::ffi::c_void) -> Self { + Self::new( + ::protobuf::__internal::Private, + ::protobuf::__internal::runtime::RawMessage::new(*msg as *mut _).unwrap(), + ) + } + unsafe fn __unstable_wrap_raw_message_unchecked_lifetime( + msg: *const ::std::ffi::c_void, + ) -> Self { + Self::new( + ::protobuf::__internal::Private, + ::protobuf::__internal::runtime::RawMessage::new(msg as *mut _).unwrap(), + ) + } + fn __unstable_as_raw_message(&self) -> *const ::std::ffi::c_void { + self.msg.as_ptr() as *const _ + } +} +impl ::protobuf::__internal::MatcherEq for Point { + fn matches(&self, o: &Self) -> bool { + ::protobuf::__internal::MatcherEq::matches( + &::protobuf::AsView::as_view(self), + &::protobuf::AsView::as_view(o), + ) + } +} +impl<'a> ::protobuf::__internal::MatcherEq for PointMut<'a> { + fn matches(&self, o: &Self) -> bool { + ::protobuf::__internal::MatcherEq::matches( + &::protobuf::AsView::as_view(self), + &::protobuf::AsView::as_view(o), + ) + } +} +impl<'a> ::protobuf::__internal::MatcherEq for PointView<'a> { + fn matches(&self, o: &Self) -> bool { + unsafe { + ::protobuf::__internal::runtime::upb_Message_IsEqual( + self.msg, + o.msg, + ::mini_table(), + 0, + ) + } + } +} +#[allow(non_camel_case_types)] +pub struct Feature { + inner: ::protobuf::__internal::runtime::MessageInner, +} +impl ::protobuf::Message for Feature {} +impl ::std::default::Default for Feature { + fn default() -> Self { + Self::new() + } +} +impl ::protobuf::Parse for Feature { + fn parse(serialized: &[u8]) -> ::std::result::Result { + Self::parse(serialized) + } +} +impl ::std::fmt::Debug for Feature { + fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { + let string = unsafe { + ::protobuf::__internal::runtime::debug_string( + self.raw_msg(), + ::mini_table(), + ) + }; + write!(f, "{}", string) + } +} +impl ::protobuf::TakeFrom for Feature { + fn take_from(&mut self, src: impl ::protobuf::AsMut) { + let mut m = self.as_mut(); + ::protobuf::TakeFrom::take_from(&mut m, src) + } +} +impl ::protobuf::CopyFrom for Feature { + fn copy_from(&mut self, src: impl ::protobuf::AsView) { + let mut m = self.as_mut(); + ::protobuf::CopyFrom::copy_from(&mut m, src) + } +} +impl ::protobuf::MergeFrom for Feature { + fn merge_from<'src>(&mut self, src: impl ::protobuf::AsView) { + let mut m = self.as_mut(); + ::protobuf::MergeFrom::merge_from(&mut m, src) + } +} +impl ::protobuf::Serialize for Feature { + fn serialize(&self) -> ::std::result::Result, ::protobuf::SerializeError> { + ::protobuf::AsView::as_view(self).serialize() + } +} +impl ::protobuf::Clear for Feature { + fn clear(&mut self) { + let mut m = self.as_mut(); + ::protobuf::Clear::clear(&mut m) + } +} +impl ::protobuf::ClearAndParse for Feature { + fn clear_and_parse( + &mut self, + data: &[u8], + ) -> ::std::result::Result<(), ::protobuf::ParseError> { + let mut m = self.as_mut(); + ::protobuf::ClearAndParse::clear_and_parse(&mut m, data) + } +} +unsafe impl Sync for Feature {} +unsafe impl Send for Feature {} +impl ::protobuf::Proxied for Feature { + type View<'msg> = FeatureView<'msg>; +} +impl ::protobuf::__internal::SealedInternal for Feature {} +impl ::protobuf::MutProxied for Feature { + type Mut<'msg> = FeatureMut<'msg>; +} +#[derive(Copy, Clone)] +#[allow(dead_code)] +pub struct FeatureView<'msg> { + msg: ::protobuf::__internal::runtime::RawMessage, + _phantom: ::std::marker::PhantomData<&'msg ()>, +} +impl<'msg> ::protobuf::__internal::SealedInternal for FeatureView<'msg> {} +impl<'msg> ::protobuf::MessageView<'msg> for FeatureView<'msg> { + type Message = Feature; +} +impl ::std::fmt::Debug for FeatureView<'_> { + fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { + let string = unsafe { + ::protobuf::__internal::runtime::debug_string( + self.raw_msg(), + ::mini_table(), + ) + }; + write!(f, "{}", string) + } +} +impl ::protobuf::Serialize for FeatureView<'_> { + fn serialize(&self) -> ::std::result::Result, ::protobuf::SerializeError> { + let encoded = unsafe { + ::protobuf::__internal::runtime::wire::encode( + self.raw_msg(), + ::mini_table(), + ) + }; + encoded.map_err(|_| ::protobuf::SerializeError) + } +} +impl ::std::default::Default for FeatureView<'_> { + fn default() -> FeatureView<'static> { + FeatureView::new( + ::protobuf::__internal::Private, + ::protobuf::__internal::runtime::ScratchSpace::zeroed_block(), + ) + } +} +#[allow(dead_code)] +impl<'msg> FeatureView<'msg> { + #[doc(hidden)] + pub fn new( + _private: ::protobuf::__internal::Private, + msg: ::protobuf::__internal::runtime::RawMessage, + ) -> Self { + Self { + msg, + _phantom: ::std::marker::PhantomData, + } + } + fn raw_msg(&self) -> ::protobuf::__internal::runtime::RawMessage { + self.msg + } + pub fn to_owned(&self) -> Feature { + ::protobuf::IntoProxied::into_proxied(*self, ::protobuf::__internal::Private) + } + pub fn name(self) -> ::protobuf::View<'msg, ::protobuf::ProtoString> { + let str_view = unsafe { + let f = ::protobuf::__internal::runtime::upb_MiniTable_GetFieldByIndex( + ::mini_table(), + 0, + ); + ::protobuf::__internal::runtime::upb_Message_GetString( + self.raw_msg(), + f, + (b"").into(), + ) + }; + unsafe { ::protobuf::ProtoStr::from_utf8_unchecked(str_view.as_ref()) } + } + pub fn has_location(self) -> bool { + unsafe { + let f = ::protobuf::__internal::runtime::upb_MiniTable_GetFieldByIndex( + ::mini_table(), + 1, + ); + ::protobuf::__internal::runtime::upb_Message_HasBaseField(self.raw_msg(), f) + } + } + pub fn location_opt(self) -> ::protobuf::Optional> { + ::protobuf::Optional::new(self.location(), self.has_location()) + } + pub fn location(self) -> super::PointView<'msg> { + let submsg = unsafe { + let f = ::protobuf::__internal::runtime::upb_MiniTable_GetFieldByIndex( + ::mini_table(), + 1, + ); + ::protobuf::__internal::runtime::upb_Message_GetMessage(self.raw_msg(), f) + }; + match submsg { + None => { + super::PointView::new( + ::protobuf::__internal::Private, + ::protobuf::__internal::runtime::ScratchSpace::zeroed_block(), + ) + } + Some(sub_raw_msg) => { + super::PointView::new(::protobuf::__internal::Private, sub_raw_msg) + } + } + } +} +unsafe impl Sync for FeatureView<'_> {} +unsafe impl Send for FeatureView<'_> {} +impl<'msg> ::protobuf::Proxy<'msg> for FeatureView<'msg> {} +impl<'msg> ::protobuf::ViewProxy<'msg> for FeatureView<'msg> {} +impl<'msg> ::protobuf::AsView for FeatureView<'msg> { + type Proxied = Feature; + fn as_view(&self) -> ::protobuf::View<'msg, Feature> { + *self + } +} +impl<'msg> ::protobuf::IntoView<'msg> for FeatureView<'msg> { + fn into_view<'shorter>(self) -> FeatureView<'shorter> + where + 'msg: 'shorter, + { + self + } +} +impl<'msg> ::protobuf::IntoProxied for FeatureView<'msg> { + fn into_proxied(self, _private: ::protobuf::__internal::Private) -> Feature { + let dst = Feature::new(); + unsafe { + ::protobuf::__internal::runtime::upb_Message_DeepCopy( + dst.inner.msg, + self.msg, + ::mini_table(), + dst.inner.arena.raw(), + ) + }; + dst + } +} +impl<'msg> ::protobuf::IntoProxied for FeatureMut<'msg> { + fn into_proxied(self, _private: ::protobuf::__internal::Private) -> Feature { + ::protobuf::IntoProxied::into_proxied( + ::protobuf::IntoView::into_view(self), + _private, + ) + } +} +unsafe impl ::protobuf::ProxiedInRepeated for Feature { + fn repeated_new( + _private: ::protobuf::__internal::Private, + ) -> ::protobuf::Repeated { + let arena = ::protobuf::__internal::runtime::Arena::new(); + unsafe { + ::protobuf::Repeated::from_inner( + ::protobuf::__internal::Private, + ::protobuf::__internal::runtime::InnerRepeated::from_raw_parts( + ::protobuf::__internal::runtime::upb_Array_New( + arena.raw(), + ::protobuf::__internal::runtime::CType::Message, + ), + arena, + ), + ) + } + } + unsafe fn repeated_free( + _private: ::protobuf::__internal::Private, + _f: &mut ::protobuf::Repeated, + ) {} + fn repeated_len(f: ::protobuf::View<::protobuf::Repeated>) -> usize { + unsafe { + ::protobuf::__internal::runtime::upb_Array_Size( + f.as_raw(::protobuf::__internal::Private), + ) + } + } + unsafe fn repeated_set_unchecked( + mut f: ::protobuf::Mut<::protobuf::Repeated>, + i: usize, + v: impl ::protobuf::IntoProxied, + ) { + unsafe { + ::protobuf::__internal::runtime::upb_Array_Set( + f.as_raw(::protobuf::__internal::Private), + i, + ::into_message_value_fuse_if_required( + f.raw_arena(::protobuf::__internal::Private), + v.into_proxied(::protobuf::__internal::Private), + ), + ) + } + } + unsafe fn repeated_get_unchecked( + f: ::protobuf::View<::protobuf::Repeated>, + i: usize, + ) -> ::protobuf::View { + let msg_ptr = unsafe { + ::protobuf::__internal::runtime::upb_Array_Get( + f.as_raw(::protobuf::__internal::Private), + i, + ) + .msg_val + } + .expect("upb_Array* element should not be NULL."); + ::protobuf::View::::new(::protobuf::__internal::Private, msg_ptr) + } + unsafe fn repeated_get_mut_unchecked( + mut f: ::protobuf::Mut<::protobuf::Repeated>, + i: usize, + ) -> ::protobuf::Mut { + let msg_ptr = unsafe { + ::protobuf::__internal::runtime::upb_Array_GetMutable( + f.as_raw(::protobuf::__internal::Private), + i, + ) + }; + unsafe { + ::protobuf::Mut:: { + inner: ::protobuf::__internal::runtime::MutatorMessageRef::from_raw_parts( + msg_ptr, + f.arena(::protobuf::__internal::Private), + ), + } + } + } + fn repeated_clear(mut f: ::protobuf::Mut<::protobuf::Repeated>) { + unsafe { + ::protobuf::__internal::runtime::upb_Array_Resize( + f.as_raw(::protobuf::__internal::Private), + 0, + f.raw_arena(::protobuf::__internal::Private), + ) + }; + } + fn repeated_push( + mut f: ::protobuf::Mut<::protobuf::Repeated>, + v: impl ::protobuf::IntoProxied, + ) { + unsafe { + ::protobuf::__internal::runtime::upb_Array_Append( + f.as_raw(::protobuf::__internal::Private), + ::into_message_value_fuse_if_required( + f.raw_arena(::protobuf::__internal::Private), + v.into_proxied(::protobuf::__internal::Private), + ), + f.raw_arena(::protobuf::__internal::Private), + ); + }; + } + fn repeated_copy_from( + src: ::protobuf::View<::protobuf::Repeated>, + dest: ::protobuf::Mut<::protobuf::Repeated>, + ) { + unsafe { + ::protobuf::__internal::runtime::repeated_message_copy_from( + src, + dest, + ::mini_table(), + ); + } + } + fn repeated_reserve( + mut f: ::protobuf::Mut<::protobuf::Repeated>, + additional: usize, + ) { + unsafe { + let size = ::protobuf::__internal::runtime::upb_Array_Size( + f.as_raw(::protobuf::__internal::Private), + ); + ::protobuf::__internal::runtime::upb_Array_Reserve( + f.as_raw(::protobuf::__internal::Private), + size + additional, + f.raw_arena(::protobuf::__internal::Private), + ); + } + } +} +impl ::protobuf::__internal::runtime::UpbTypeConversions for Feature { + fn upb_type() -> ::protobuf::__internal::runtime::CType { + ::protobuf::__internal::runtime::CType::Message + } + fn to_message_value( + val: ::protobuf::View<'_, Self>, + ) -> ::protobuf::__internal::runtime::upb_MessageValue { + ::protobuf::__internal::runtime::upb_MessageValue { + msg_val: Some(val.raw_msg()), + } + } + unsafe fn into_message_value_fuse_if_required( + raw_parent_arena: ::protobuf::__internal::runtime::RawArena, + mut val: Self, + ) -> ::protobuf::__internal::runtime::upb_MessageValue { + let parent_arena = ::std::mem::ManuallyDrop::new(unsafe { + ::protobuf::__internal::runtime::Arena::from_raw(raw_parent_arena) + }); + parent_arena + .fuse(val.as_mutator_message_ref(::protobuf::__internal::Private).arena()); + ::protobuf::__internal::runtime::upb_MessageValue { + msg_val: Some(val.raw_msg()), + } + } + unsafe fn from_message_value<'msg>( + msg: ::protobuf::__internal::runtime::upb_MessageValue, + ) -> ::protobuf::View<'msg, Self> { + FeatureView::new( + ::protobuf::__internal::Private, + unsafe { msg.msg_val }.expect("expected present message value in map"), + ) + } + unsafe fn from_message_mut<'msg>( + msg: *mut ::protobuf::__internal::runtime::upb_Message, + arena: &'msg ::protobuf::__internal::runtime::Arena, + ) -> FeatureMut<'msg> { + FeatureMut { + inner: unsafe { + ::protobuf::__internal::runtime::MutatorMessageRef::from_raw_parts( + std::ptr::NonNull::new(msg) + .expect("expected present message value in map"), + arena, + ) + }, + } + } +} +#[allow(dead_code)] +#[allow(non_camel_case_types)] +pub struct FeatureMut<'msg> { + inner: ::protobuf::__internal::runtime::MutatorMessageRef<'msg>, +} +impl<'msg> ::protobuf::__internal::SealedInternal for FeatureMut<'msg> {} +impl<'msg> ::protobuf::MessageMut<'msg> for FeatureMut<'msg> { + type Message = Feature; +} +impl ::std::fmt::Debug for FeatureMut<'_> { + fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { + let string = unsafe { + ::protobuf::__internal::runtime::debug_string( + self.raw_msg(), + ::mini_table(), + ) + }; + write!(f, "{}", string) + } +} +impl ::protobuf::Serialize for FeatureMut<'_> { + fn serialize(&self) -> ::std::result::Result, ::protobuf::SerializeError> { + ::protobuf::AsView::as_view(self).serialize() + } +} +impl ::protobuf::Clear for FeatureMut<'_> { + fn clear(&mut self) { + unsafe { + ::protobuf::__internal::runtime::upb_Message_Clear( + self.raw_msg(), + ::mini_table(), + ) + } + } +} +impl ::protobuf::ClearAndParse for FeatureMut<'_> { + fn clear_and_parse( + &mut self, + data: &[u8], + ) -> ::std::result::Result<(), ::protobuf::ParseError> { + ::protobuf::Clear::clear(self); + let status = unsafe { + ::protobuf::__internal::runtime::wire::decode( + data, + self.raw_msg(), + ::mini_table(), + self.arena(), + ) + }; + match status { + Ok(_) => Ok(()), + Err(_) => Err(::protobuf::ParseError), + } + } +} +impl ::protobuf::TakeFrom for FeatureMut<'_> { + fn take_from(&mut self, mut src: impl ::protobuf::AsMut) { + let mut src = src.as_mut(); + ::protobuf::CopyFrom::copy_from(self, ::protobuf::AsView::as_view(&src)); + ::protobuf::Clear::clear(&mut src); + } +} +impl ::protobuf::CopyFrom for FeatureMut<'_> { + fn copy_from(&mut self, src: impl ::protobuf::AsView) { + unsafe { + assert!( + ::protobuf::__internal::runtime::upb_Message_DeepCopy(self.raw_msg(), src + .as_view().raw_msg(), < Self as + ::protobuf::__internal::runtime::AssociatedMiniTable >::mini_table(), + self.arena().raw()) + ); + } + } +} +impl ::protobuf::MergeFrom for FeatureMut<'_> { + fn merge_from(&mut self, src: impl ::protobuf::AsView) { + unsafe { + assert!( + ::protobuf::__internal::runtime::upb_Message_MergeFrom(self.raw_msg(), + src.as_view().raw_msg(), < Self as + ::protobuf::__internal::runtime::AssociatedMiniTable >::mini_table(), + ::std::ptr::null(), self.arena().raw()) + ); + } + } +} +#[allow(dead_code)] +impl<'msg> FeatureMut<'msg> { + #[doc(hidden)] + pub fn from_parent( + _private: ::protobuf::__internal::Private, + parent: ::protobuf::__internal::runtime::MutatorMessageRef<'msg>, + msg: ::protobuf::__internal::runtime::RawMessage, + ) -> Self { + Self { + inner: ::protobuf::__internal::runtime::MutatorMessageRef::from_parent( + parent, + msg, + ), + } + } + #[doc(hidden)] + pub fn new( + _private: ::protobuf::__internal::Private, + msg: &'msg mut ::protobuf::__internal::runtime::MessageInner, + ) -> Self { + Self { + inner: ::protobuf::__internal::runtime::MutatorMessageRef::new(msg), + } + } + fn raw_msg(&self) -> ::protobuf::__internal::runtime::RawMessage { + self.inner.msg() + } + #[doc(hidden)] + pub fn as_mutator_message_ref( + &mut self, + _private: ::protobuf::__internal::Private, + ) -> ::protobuf::__internal::runtime::MutatorMessageRef<'msg> { + self.inner + } + pub fn to_owned(&self) -> Feature { + ::protobuf::AsView::as_view(self).to_owned() + } + fn arena(&self) -> &::protobuf::__internal::runtime::Arena { + self.inner.arena() + } + pub fn name(&self) -> ::protobuf::View<'_, ::protobuf::ProtoString> { + let str_view = unsafe { + let f = ::protobuf::__internal::runtime::upb_MiniTable_GetFieldByIndex( + ::mini_table(), + 0, + ); + ::protobuf::__internal::runtime::upb_Message_GetString( + self.raw_msg(), + f, + (b"").into(), + ) + }; + unsafe { ::protobuf::ProtoStr::from_utf8_unchecked(str_view.as_ref()) } + } + pub fn set_name( + &mut self, + val: impl ::protobuf::IntoProxied<::protobuf::ProtoString>, + ) { + let s = val.into_proxied(::protobuf::__internal::Private); + let (view, arena) = s + .into_inner(::protobuf::__internal::Private) + .into_raw_parts(); + let mm_ref = self.as_mutator_message_ref(::protobuf::__internal::Private); + let parent_arena = mm_ref.arena(); + parent_arena.fuse(&arena); + unsafe { + let f = ::protobuf::__internal::runtime::upb_MiniTable_GetFieldByIndex( + ::mini_table(), + 0, + ); + ::protobuf::__internal::runtime::upb_Message_SetBaseFieldString( + self.as_mutator_message_ref(::protobuf::__internal::Private).msg(), + f, + view, + ); + } + } + pub fn has_location(&self) -> bool { + unsafe { + let f = ::protobuf::__internal::runtime::upb_MiniTable_GetFieldByIndex( + ::mini_table(), + 1, + ); + ::protobuf::__internal::runtime::upb_Message_HasBaseField(self.raw_msg(), f) + } + } + pub fn clear_location(&mut self) { + unsafe { + let mt = ::mini_table(); + let f = ::protobuf::__internal::runtime::upb_MiniTable_GetFieldByIndex( + mt, + 1, + ); + ::protobuf::__internal::runtime::upb_Message_ClearBaseField( + self.raw_msg(), + f, + ); + } + } + pub fn location_opt(&self) -> ::protobuf::Optional> { + ::protobuf::Optional::new(self.location(), self.has_location()) + } + pub fn location(&self) -> super::PointView<'_> { + let submsg = unsafe { + let f = ::protobuf::__internal::runtime::upb_MiniTable_GetFieldByIndex( + ::mini_table(), + 1, + ); + ::protobuf::__internal::runtime::upb_Message_GetMessage(self.raw_msg(), f) + }; + match submsg { + None => { + super::PointView::new( + ::protobuf::__internal::Private, + ::protobuf::__internal::runtime::ScratchSpace::zeroed_block(), + ) + } + Some(sub_raw_msg) => { + super::PointView::new(::protobuf::__internal::Private, sub_raw_msg) + } + } + } + pub fn location_mut(&mut self) -> super::PointMut<'_> { + let raw_msg = unsafe { + let mt = ::mini_table(); + let f = ::protobuf::__internal::runtime::upb_MiniTable_GetFieldByIndex( + mt, + 1, + ); + ::protobuf::__internal::runtime::upb_Message_GetOrCreateMutableMessage( + self.raw_msg(), + mt, + f, + self.arena().raw(), + ) + .unwrap() + }; + super::PointMut::from_parent( + ::protobuf::__internal::Private, + self.as_mutator_message_ref(::protobuf::__internal::Private), + raw_msg, + ) + } + pub fn set_location(&mut self, val: impl ::protobuf::IntoProxied) { + let mut msg = val.into_proxied(::protobuf::__internal::Private); + self.as_mutator_message_ref(::protobuf::__internal::Private) + .arena() + .fuse(msg.as_mutator_message_ref(::protobuf::__internal::Private).arena()); + unsafe { + let f = ::protobuf::__internal::runtime::upb_MiniTable_GetFieldByIndex( + ::mini_table(), + 1, + ); + ::protobuf::__internal::runtime::upb_Message_SetBaseFieldMessage( + self.as_mutator_message_ref(::protobuf::__internal::Private).msg(), + f, + msg.as_mutator_message_ref(::protobuf::__internal::Private).msg(), + ); + } + } +} +unsafe impl Sync for FeatureMut<'_> {} +impl<'msg> ::protobuf::Proxy<'msg> for FeatureMut<'msg> {} +impl<'msg> ::protobuf::MutProxy<'msg> for FeatureMut<'msg> {} +impl<'msg> ::protobuf::AsView for FeatureMut<'msg> { + type Proxied = Feature; + fn as_view(&self) -> ::protobuf::View<'_, Feature> { + FeatureView { + msg: self.raw_msg(), + _phantom: ::std::marker::PhantomData, + } + } +} +impl<'msg> ::protobuf::IntoView<'msg> for FeatureMut<'msg> { + fn into_view<'shorter>(self) -> ::protobuf::View<'shorter, Feature> + where + 'msg: 'shorter, + { + FeatureView { + msg: self.raw_msg(), + _phantom: ::std::marker::PhantomData, + } + } +} +impl<'msg> ::protobuf::AsMut for FeatureMut<'msg> { + type MutProxied = Feature; + fn as_mut(&mut self) -> FeatureMut<'msg> { + FeatureMut { inner: self.inner } + } +} +impl<'msg> ::protobuf::IntoMut<'msg> for FeatureMut<'msg> { + fn into_mut<'shorter>(self) -> FeatureMut<'shorter> + where + 'msg: 'shorter, + { + self + } +} +#[allow(dead_code)] +impl Feature { + pub fn new() -> Self { + let arena = ::protobuf::__internal::runtime::Arena::new(); + let raw_msg = unsafe { + ::protobuf::__internal::runtime::upb_Message_New( + ::mini_table(), + arena.raw(), + ) + .unwrap() + }; + Self { + inner: ::protobuf::__internal::runtime::MessageInner { + msg: raw_msg, + arena, + }, + } + } + fn raw_msg(&self) -> ::protobuf::__internal::runtime::RawMessage { + self.inner.msg + } + #[doc(hidden)] + pub fn as_mutator_message_ref( + &mut self, + _private: ::protobuf::__internal::Private, + ) -> ::protobuf::__internal::runtime::MutatorMessageRef { + ::protobuf::__internal::runtime::MutatorMessageRef::new(&mut self.inner) + } + fn arena(&self) -> &::protobuf::__internal::runtime::Arena { + &self.inner.arena + } + pub fn parse(data: &[u8]) -> ::std::result::Result { + let mut msg = Self::new(); + ::protobuf::ClearAndParse::clear_and_parse(&mut msg, data).map(|_| msg) + } + pub fn as_view(&self) -> FeatureView { + FeatureView::new(::protobuf::__internal::Private, self.inner.msg) + } + pub fn as_mut(&mut self) -> FeatureMut { + FeatureMut::new(::protobuf::__internal::Private, &mut self.inner) + } + pub fn name(&self) -> ::protobuf::View<'_, ::protobuf::ProtoString> { + let str_view = unsafe { + let f = ::protobuf::__internal::runtime::upb_MiniTable_GetFieldByIndex( + ::mini_table(), + 0, + ); + ::protobuf::__internal::runtime::upb_Message_GetString( + self.raw_msg(), + f, + (b"").into(), + ) + }; + unsafe { ::protobuf::ProtoStr::from_utf8_unchecked(str_view.as_ref()) } + } + pub fn set_name( + &mut self, + val: impl ::protobuf::IntoProxied<::protobuf::ProtoString>, + ) { + let s = val.into_proxied(::protobuf::__internal::Private); + let (view, arena) = s + .into_inner(::protobuf::__internal::Private) + .into_raw_parts(); + let mm_ref = self.as_mutator_message_ref(::protobuf::__internal::Private); + let parent_arena = mm_ref.arena(); + parent_arena.fuse(&arena); + unsafe { + let f = ::protobuf::__internal::runtime::upb_MiniTable_GetFieldByIndex( + ::mini_table(), + 0, + ); + ::protobuf::__internal::runtime::upb_Message_SetBaseFieldString( + self.as_mutator_message_ref(::protobuf::__internal::Private).msg(), + f, + view, + ); + } + } + pub fn has_location(&self) -> bool { + unsafe { + let f = ::protobuf::__internal::runtime::upb_MiniTable_GetFieldByIndex( + ::mini_table(), + 1, + ); + ::protobuf::__internal::runtime::upb_Message_HasBaseField(self.raw_msg(), f) + } + } + pub fn clear_location(&mut self) { + unsafe { + let mt = ::mini_table(); + let f = ::protobuf::__internal::runtime::upb_MiniTable_GetFieldByIndex( + mt, + 1, + ); + ::protobuf::__internal::runtime::upb_Message_ClearBaseField( + self.raw_msg(), + f, + ); + } + } + pub fn location_opt(&self) -> ::protobuf::Optional> { + ::protobuf::Optional::new(self.location(), self.has_location()) + } + pub fn location(&self) -> super::PointView<'_> { + let submsg = unsafe { + let f = ::protobuf::__internal::runtime::upb_MiniTable_GetFieldByIndex( + ::mini_table(), + 1, + ); + ::protobuf::__internal::runtime::upb_Message_GetMessage(self.raw_msg(), f) + }; + match submsg { + None => { + super::PointView::new( + ::protobuf::__internal::Private, + ::protobuf::__internal::runtime::ScratchSpace::zeroed_block(), + ) + } + Some(sub_raw_msg) => { + super::PointView::new(::protobuf::__internal::Private, sub_raw_msg) + } + } + } + pub fn location_mut(&mut self) -> super::PointMut<'_> { + let raw_msg = unsafe { + let mt = ::mini_table(); + let f = ::protobuf::__internal::runtime::upb_MiniTable_GetFieldByIndex( + mt, + 1, + ); + ::protobuf::__internal::runtime::upb_Message_GetOrCreateMutableMessage( + self.raw_msg(), + mt, + f, + self.arena().raw(), + ) + .unwrap() + }; + super::PointMut::from_parent( + ::protobuf::__internal::Private, + self.as_mutator_message_ref(::protobuf::__internal::Private), + raw_msg, + ) + } + pub fn set_location(&mut self, val: impl ::protobuf::IntoProxied) { + let mut msg = val.into_proxied(::protobuf::__internal::Private); + self.as_mutator_message_ref(::protobuf::__internal::Private) + .arena() + .fuse(msg.as_mutator_message_ref(::protobuf::__internal::Private).arena()); + unsafe { + let f = ::protobuf::__internal::runtime::upb_MiniTable_GetFieldByIndex( + ::mini_table(), + 1, + ); + ::protobuf::__internal::runtime::upb_Message_SetBaseFieldMessage( + self.as_mutator_message_ref(::protobuf::__internal::Private).msg(), + f, + msg.as_mutator_message_ref(::protobuf::__internal::Private).msg(), + ); + } + } +} +impl ::std::ops::Drop for Feature { + fn drop(&mut self) {} +} +impl ::std::clone::Clone for Feature { + fn clone(&self) -> Self { + self.as_view().to_owned() + } +} +impl ::protobuf::AsView for Feature { + type Proxied = Self; + fn as_view(&self) -> FeatureView { + self.as_view() + } +} +impl ::protobuf::AsMut for Feature { + type MutProxied = Self; + fn as_mut(&mut self) -> FeatureMut { + self.as_mut() + } +} +unsafe impl ::protobuf::__internal::runtime::AssociatedMiniTable for Feature { + #[inline(always)] + fn mini_table() -> *const ::protobuf::__internal::runtime::upb_MiniTable { + #[allow(unused_unsafe)] + unsafe { ::std::ptr::addr_of!(routeguide__Feature_msg_init) } + } +} +unsafe impl ::protobuf::__internal::runtime::AssociatedMiniTable for FeatureView<'_> { + #[inline(always)] + fn mini_table() -> *const ::protobuf::__internal::runtime::upb_MiniTable { + #[allow(unused_unsafe)] + unsafe { ::std::ptr::addr_of!(routeguide__Feature_msg_init) } + } +} +unsafe impl ::protobuf::__internal::runtime::AssociatedMiniTable for FeatureMut<'_> { + #[inline(always)] + fn mini_table() -> *const ::protobuf::__internal::runtime::upb_MiniTable { + #[allow(unused_unsafe)] + unsafe { ::std::ptr::addr_of!(routeguide__Feature_msg_init) } + } +} +extern "C" { + /// Opaque static extern for this message's MiniTable, generated + /// by the upb C MiniTable codegen. The only valid way to + /// reference this static is with `std::ptr::addr_of!(..)`. + static routeguide__Feature_msg_init: ::protobuf::__internal::runtime::upb_MiniTable; +} +impl ::protobuf::OwnedMessageInterop for Feature {} +impl<'a> ::protobuf::MessageMutInterop<'a> for FeatureMut<'a> {} +impl<'a> ::protobuf::MessageViewInterop<'a> for FeatureView<'a> { + unsafe fn __unstable_wrap_raw_message(msg: &'a *const ::std::ffi::c_void) -> Self { + Self::new( + ::protobuf::__internal::Private, + ::protobuf::__internal::runtime::RawMessage::new(*msg as *mut _).unwrap(), + ) + } + unsafe fn __unstable_wrap_raw_message_unchecked_lifetime( + msg: *const ::std::ffi::c_void, + ) -> Self { + Self::new( + ::protobuf::__internal::Private, + ::protobuf::__internal::runtime::RawMessage::new(msg as *mut _).unwrap(), + ) + } + fn __unstable_as_raw_message(&self) -> *const ::std::ffi::c_void { + self.msg.as_ptr() as *const _ + } +} +impl ::protobuf::__internal::MatcherEq for Feature { + fn matches(&self, o: &Self) -> bool { + ::protobuf::__internal::MatcherEq::matches( + &::protobuf::AsView::as_view(self), + &::protobuf::AsView::as_view(o), + ) + } +} +impl<'a> ::protobuf::__internal::MatcherEq for FeatureMut<'a> { + fn matches(&self, o: &Self) -> bool { + ::protobuf::__internal::MatcherEq::matches( + &::protobuf::AsView::as_view(self), + &::protobuf::AsView::as_view(o), + ) + } +} +impl<'a> ::protobuf::__internal::MatcherEq for FeatureView<'a> { + fn matches(&self, o: &Self) -> bool { + unsafe { + ::protobuf::__internal::runtime::upb_Message_IsEqual( + self.msg, + o.msg, + ::mini_table(), + 0, + ) + } + } +} diff --git a/codelabs/grpc-rust-getting-started/start_here/generated/routeguide.upb_minitable.c b/codelabs/grpc-rust-getting-started/start_here/generated/routeguide.upb_minitable.c new file mode 100644 index 00000000..a4893139 --- /dev/null +++ b/codelabs/grpc-rust-getting-started/start_here/generated/routeguide.upb_minitable.c @@ -0,0 +1,76 @@ +/* This file was generated by upb_generator from the input file: + * + * routeguide.proto + * + * Do not edit -- your changes will be discarded when the file is + * regenerated. + * NO CHECKED-IN PROTOBUF GENCODE */ + +#include +#include "upb/generated_code_support.h" +#include "routeguide.upb_minitable.h" + +// Must be last. +#include "upb/port/def.inc" + +extern const struct upb_MiniTable UPB_PRIVATE(_kUpb_MiniTable_StaticallyTreeShaken); +static const upb_MiniTableField routeguide_Point__fields[2] = { + {1, 8, 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}, + {2, 12, 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}, +}; + +const upb_MiniTable routeguide__Point_msg_init = { + NULL, + &routeguide_Point__fields[0], + 16, 2, kUpb_ExtMode_NonExtendable, 2, UPB_FASTTABLE_MASK(24), 0, +#ifdef UPB_TRACING_ENABLED + "routeguide.Point", +#endif + UPB_FASTTABLE_INIT({ + {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, + {0x000800003f000008, &upb_psv4_1bt}, + {0x000c00003f000010, &upb_psv4_1bt}, + {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, + }) +}; + +const upb_MiniTable* routeguide__Point_msg_init_ptr = &routeguide__Point_msg_init; +static const upb_MiniTableSubInternal routeguide_Feature__submsgs[1] = { + {.UPB_PRIVATE(submsg) = &routeguide__Point_msg_init_ptr}, +}; + +static const upb_MiniTableField routeguide_Feature__fields[2] = { + {1, 16, 0, kUpb_NoSub, 9, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, + {2, UPB_SIZE(12, 32), 64, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, +}; + +const upb_MiniTable routeguide__Feature_msg_init = { + &routeguide_Feature__submsgs[0], + &routeguide_Feature__fields[0], + UPB_SIZE(24, 40), 2, kUpb_ExtMode_NonExtendable, 2, UPB_FASTTABLE_MASK(8), 0, +#ifdef UPB_TRACING_ENABLED + "routeguide.Feature", +#endif + UPB_FASTTABLE_INIT({ + {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, + {0x001000003f00000a, &upb_pss_1bt}, + }) +}; + +const upb_MiniTable* routeguide__Feature_msg_init_ptr = &routeguide__Feature_msg_init; +static const upb_MiniTable *messages_layout[2] = { + &routeguide__Point_msg_init, + &routeguide__Feature_msg_init, +}; + +const upb_MiniTableFile routeguide_proto_upb_file_layout = { + messages_layout, + NULL, + NULL, + 2, + 0, + 0, +}; + +#include "upb/port/undef.inc" + diff --git a/codelabs/grpc-rust-getting-started/start_here/generated/routeguide.upb_minitable.h b/codelabs/grpc-rust-getting-started/start_here/generated/routeguide.upb_minitable.h new file mode 100644 index 00000000..8fc2387c --- /dev/null +++ b/codelabs/grpc-rust-getting-started/start_here/generated/routeguide.upb_minitable.h @@ -0,0 +1,34 @@ +/* This file was generated by upb_generator from the input file: + * + * routeguide.proto + * + * Do not edit -- your changes will be discarded when the file is + * regenerated. + * NO CHECKED-IN PROTOBUF GENCODE */ + +#ifndef ROUTEGUIDE_PROTO_UPB_H__UPB_MINITABLE_H_ +#define ROUTEGUIDE_PROTO_UPB_H__UPB_MINITABLE_H_ + +#include "upb/generated_code_support.h" + +// Must be last. +#include "upb/port/def.inc" + +#ifdef __cplusplus +extern "C" { +#endif + +extern const upb_MiniTable routeguide__Point_msg_init; +extern const upb_MiniTable* routeguide__Point_msg_init_ptr; +extern const upb_MiniTable routeguide__Feature_msg_init; +extern const upb_MiniTable* routeguide__Feature_msg_init_ptr; + +extern const upb_MiniTableFile routeguide_proto_upb_file_layout; + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#include "upb/port/undef.inc" + +#endif /* ROUTEGUIDE_PROTO_UPB_H__UPB_MINITABLE_H_ */ diff --git a/codelabs/grpc-rust-getting-started/start_here/generated/routeguide_grpc.pb.rs b/codelabs/grpc-rust-getting-started/start_here/generated/routeguide_grpc.pb.rs new file mode 100644 index 00000000..71411362 --- /dev/null +++ b/codelabs/grpc-rust-getting-started/start_here/generated/routeguide_grpc.pb.rs @@ -0,0 +1,296 @@ +/// Generated client implementations. +pub mod route_guide_client { + #![allow( + unused_variables, + dead_code, + missing_docs, + clippy::wildcard_imports, + clippy::let_unit_value, + )] + use tonic::codegen::*; + use tonic::codegen::http::Uri; + /// Interface exported by the server. + #[derive(Debug, Clone)] + pub struct RouteGuideClient { + inner: tonic::client::Grpc, + } + impl RouteGuideClient + where + T: tonic::client::GrpcService, + T::Error: Into, + T::ResponseBody: Body + std::marker::Send + 'static, + ::Error: Into + std::marker::Send, + { + pub fn new(inner: T) -> Self { + let inner = tonic::client::Grpc::new(inner); + Self { inner } + } + pub fn with_origin(inner: T, origin: Uri) -> Self { + let inner = tonic::client::Grpc::with_origin(inner, origin); + Self { inner } + } + pub fn with_interceptor( + inner: T, + interceptor: F, + ) -> RouteGuideClient> + where + F: tonic::service::Interceptor, + T::ResponseBody: Default, + T: tonic::codegen::Service< + http::Request, + Response = http::Response< + >::ResponseBody, + >, + >, + , + >>::Error: Into + std::marker::Send + std::marker::Sync, + { + RouteGuideClient::new(InterceptedService::new(inner, interceptor)) + } + /// Compress requests with the given encoding. + /// + /// This requires the server to support it otherwise it might respond with an + /// error. + #[must_use] + pub fn send_compressed(mut self, encoding: CompressionEncoding) -> Self { + self.inner = self.inner.send_compressed(encoding); + self + } + /// Enable decompressing responses. + #[must_use] + pub fn accept_compressed(mut self, encoding: CompressionEncoding) -> Self { + self.inner = self.inner.accept_compressed(encoding); + self + } + /// Limits the maximum size of a decoded message. + /// + /// Default: `4MB` + #[must_use] + pub fn max_decoding_message_size(mut self, limit: usize) -> Self { + self.inner = self.inner.max_decoding_message_size(limit); + self + } + /// Limits the maximum size of an encoded message. + /// + /// Default: `usize::MAX` + #[must_use] + pub fn max_encoding_message_size(mut self, limit: usize) -> Self { + self.inner = self.inner.max_encoding_message_size(limit); + self + } + /// A simple RPC. + /// + /// Obtains the feature at a given position. + /// + /// A feature with an empty name is returned if there's no feature at the given + /// position. + pub async fn get_feature( + &mut self, + request: impl tonic::IntoRequest, + ) -> std::result::Result, tonic::Status> { + self.inner + .ready() + .await + .map_err(|e| { + tonic::Status::unknown( + format!("Service was not ready: {}", e.into()), + ) + })?; + let codec = tonic_protobuf::ProtoCodec::default(); + let path = http::uri::PathAndQuery::from_static( + "/routeguide.RouteGuide/GetFeature", + ); + let mut req = request.into_request(); + req.extensions_mut() + .insert(GrpcMethod::new("routeguide.RouteGuide", "GetFeature")); + self.inner.unary(req, path, codec).await + } + } +} +/// Generated server implementations. +pub mod route_guide_server { + #![allow( + unused_variables, + dead_code, + missing_docs, + clippy::wildcard_imports, + clippy::let_unit_value, + )] + use tonic::codegen::*; + /// Generated trait containing gRPC methods that should be implemented for use with RouteGuideServer. + #[async_trait] + pub trait RouteGuide: std::marker::Send + std::marker::Sync + 'static { + /// A simple RPC. + /// + /// Obtains the feature at a given position. + /// + /// A feature with an empty name is returned if there's no feature at the given + /// position. + async fn get_feature( + &self, + request: tonic::Request, + ) -> std::result::Result, tonic::Status> { + Err(tonic::Status::unimplemented("Not yet implemented")) + } + } + /// Interface exported by the server. + #[derive(Debug)] + pub struct RouteGuideServer { + inner: Arc, + accept_compression_encodings: EnabledCompressionEncodings, + send_compression_encodings: EnabledCompressionEncodings, + max_decoding_message_size: Option, + max_encoding_message_size: Option, + } + impl RouteGuideServer { + pub fn new(inner: T) -> Self { + Self::from_arc(Arc::new(inner)) + } + pub fn from_arc(inner: Arc) -> Self { + Self { + inner, + accept_compression_encodings: Default::default(), + send_compression_encodings: Default::default(), + max_decoding_message_size: None, + max_encoding_message_size: None, + } + } + pub fn with_interceptor( + inner: T, + interceptor: F, + ) -> InterceptedService + where + F: tonic::service::Interceptor, + { + InterceptedService::new(Self::new(inner), interceptor) + } + /// Enable decompressing requests with the given encoding. + #[must_use] + pub fn accept_compressed(mut self, encoding: CompressionEncoding) -> Self { + self.accept_compression_encodings.enable(encoding); + self + } + /// Compress responses with the given encoding, if the client supports it. + #[must_use] + pub fn send_compressed(mut self, encoding: CompressionEncoding) -> Self { + self.send_compression_encodings.enable(encoding); + self + } + /// Limits the maximum size of a decoded message. + /// + /// Default: `4MB` + #[must_use] + pub fn max_decoding_message_size(mut self, limit: usize) -> Self { + self.max_decoding_message_size = Some(limit); + self + } + /// Limits the maximum size of an encoded message. + /// + /// Default: `usize::MAX` + #[must_use] + pub fn max_encoding_message_size(mut self, limit: usize) -> Self { + self.max_encoding_message_size = Some(limit); + self + } + } + impl tonic::codegen::Service> for RouteGuideServer + where + T: RouteGuide, + B: Body + std::marker::Send + 'static, + B::Error: Into + std::marker::Send + 'static, + { + type Response = http::Response; + type Error = std::convert::Infallible; + type Future = BoxFuture; + fn poll_ready( + &mut self, + _cx: &mut Context<'_>, + ) -> Poll> { + Poll::Ready(Ok(())) + } + fn call(&mut self, req: http::Request) -> Self::Future { + match req.uri().path() { + "/routeguide.RouteGuide/GetFeature" => { + #[allow(non_camel_case_types)] + struct get_featureSvc(pub Arc); + impl tonic::server::UnaryService + for get_featureSvc { + type Response = super::Feature; + type Future = BoxFuture< + tonic::Response, + tonic::Status, + >; + fn call( + &mut self, + request: tonic::Request, + ) -> Self::Future { + let inner = Arc::clone(&self.0); + let fut = async move { + ::get_feature(&inner, request).await + }; + Box::pin(fut) + } + } + let accept_compression_encodings = self.accept_compression_encodings; + let send_compression_encodings = self.send_compression_encodings; + let max_decoding_message_size = self.max_decoding_message_size; + let max_encoding_message_size = self.max_encoding_message_size; + let inner = self.inner.clone(); + let fut = async move { + let method = get_featureSvc(inner); + let codec = tonic_protobuf::ProtoCodec::default(); + let mut grpc = tonic::server::Grpc::new(codec) + .apply_compression_config( + accept_compression_encodings, + send_compression_encodings, + ) + .apply_max_message_size_config( + max_decoding_message_size, + max_encoding_message_size, + ); + let res = grpc.unary(method, req).await; + Ok(res) + }; + Box::pin(fut) + } + _ => { + Box::pin(async move { + let mut response = http::Response::new( + tonic::body::Body::default(), + ); + let headers = response.headers_mut(); + headers + .insert( + tonic::Status::GRPC_STATUS, + (tonic::Code::Unimplemented as i32).into(), + ); + headers + .insert( + http::header::CONTENT_TYPE, + tonic::metadata::GRPC_CONTENT_TYPE, + ); + Ok(response) + }) + } + } + } + } + impl Clone for RouteGuideServer { + fn clone(&self) -> Self { + let inner = self.inner.clone(); + Self { + inner, + accept_compression_encodings: self.accept_compression_encodings, + send_compression_encodings: self.send_compression_encodings, + max_decoding_message_size: self.max_decoding_message_size, + max_encoding_message_size: self.max_encoding_message_size, + } + } + } + /// Generated gRPC service name + pub const SERVICE_NAME: &str = "routeguide.RouteGuide"; + impl tonic::server::NamedService for RouteGuideServer { + const NAME: &'static str = SERVICE_NAME; + } +} diff --git a/codelabs/grpc-rust-getting-started/start_here/proto/routeguide.proto b/codelabs/grpc-rust-getting-started/start_here/proto/routeguide.proto new file mode 100644 index 00000000..f8ee4636 --- /dev/null +++ b/codelabs/grpc-rust-getting-started/start_here/proto/routeguide.proto @@ -0,0 +1,46 @@ +// Copyright 2015 gRPC 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. + +syntax = "proto3"; + +option java_multiple_files = true; +option java_package = "io.grpc.examples.routeguide"; +option java_outer_classname = "RouteGuideProto"; + +package routeguide; + +// Interface exported by the server. +service RouteGuide { + ///////////////////////////////////////////////////////////////////////////// + // Codelab Hint: Define RPC methods here + ///////////////////////////////////////////////////////////////////////////// +} + +message Point { + ///////////////////////////////////////////////////////////////////////////// + // Codelab Hint: Define the Point messages here + ///////////////////////////////////////////////////////////////////////////// +} + +// A feature names something at a given point. +// +// If a feature could not be named, the name is empty. +message Feature { + ///////////////////////////////////////////////////////////////////////////// + // Codelab Hint: Define the Feature messages here + ///////////////////////////////////////////////////////////////////////////// +} + + + diff --git a/codelabs/grpc-rust-getting-started/start_here/src/client/client.rs b/codelabs/grpc-rust-getting-started/start_here/src/client/client.rs new file mode 100644 index 00000000..aa4d311b --- /dev/null +++ b/codelabs/grpc-rust-getting-started/start_here/src/client/client.rs @@ -0,0 +1,18 @@ +use tonic::Request; +use tonic::transport::{Endpoint}; +use protobuf::proto; + +// ///////////////////////////////////////////////////////////////////////// +// Codelab Hint: Bring the generated code into scope. +// ///////////////////////////////////////////////////////////////////////// + +#[tokio::main] +async fn main() { + /////////////////////////////////////////////////////////////////////////// + // Codelab Hint: Logic for your gRPC Client will be added here. + // + // Steps include: + // - Create a connection to the gRPC server using RouteGuideClient::connect(...). + // - Call service methods on the client to interact with the server. + /////////////////////////////////////////////////////////////////////////// +} \ No newline at end of file diff --git a/codelabs/grpc-rust-getting-started/start_here/src/data/route_guide_db.json b/codelabs/grpc-rust-getting-started/start_here/src/data/route_guide_db.json new file mode 100644 index 00000000..732f0997 --- /dev/null +++ b/codelabs/grpc-rust-getting-started/start_here/src/data/route_guide_db.json @@ -0,0 +1,702 @@ +[ + { + "location": { + "latitude": 407838351, + "longitude": -746143763 + }, + "name": "Patriots Path, Mendham, NJ 07945, USA" + }, + { + "location": { + "latitude": 408122808, + "longitude": -743999179 + }, + "name": "101 New Jersey 10, Whippany, NJ 07981, USA" + }, + { + "location": { + "latitude": 413628156, + "longitude": -749015468 + }, + "name": "U.S. 6, Shohola, PA 18458, USA" + }, + { + "location": { + "latitude": 419999544, + "longitude": -740371136 + }, + "name": "5 Conners Road, Kingston, NY 12401, USA" + }, + { + "location": { + "latitude": 414008389, + "longitude": -743951297 + }, + "name": "Mid Hudson Psychiatric Center, New Hampton, NY 10958, USA" + }, + { + "location": { + "latitude": 419611318, + "longitude": -746524769 + }, + "name": "287 Flugertown Road, Livingston Manor, NY 12758, USA" + }, + { + "location": { + "latitude": 406109563, + "longitude": -742186778 + }, + "name": "4001 Tremley Point Road, Linden, NJ 07036, USA" + }, + { + "location": { + "latitude": 416802456, + "longitude": -742370183 + }, + "name": "352 South Mountain Road, Wallkill, NY 12589, USA" + }, + { + "location": { + "latitude": 412950425, + "longitude": -741077389 + }, + "name": "Bailey Turn Road, Harriman, NY 10926, USA" + }, + { + "location": { + "latitude": 412144655, + "longitude": -743949739 + }, + "name": "193-199 Wawayanda Road, Hewitt, NJ 07421, USA" + }, + { + "location": { + "latitude": 415736605, + "longitude": -742847522 + }, + "name": "406-496 Ward Avenue, Pine Bush, NY 12566, USA" + }, + { + "location": { + "latitude": 413843930, + "longitude": -740501726 + }, + "name": "162 Merrill Road, Highland Mills, NY 10930, USA" + }, + { + "location": { + "latitude": 410873075, + "longitude": -744459023 + }, + "name": "Clinton Road, West Milford, NJ 07480, USA" + }, + { + "location": { + "latitude": 412346009, + "longitude": -744026814 + }, + "name": "16 Old Brook Lane, Warwick, NY 10990, USA" + }, + { + "location": { + "latitude": 402948455, + "longitude": -747903913 + }, + "name": "3 Drake Lane, Pennington, NJ 08534, USA" + }, + { + "location": { + "latitude": 406337092, + "longitude": -740122226 + }, + "name": "6324 8th Avenue, Brooklyn, NY 11220, USA" + }, + { + "location": { + "latitude": 406421967, + "longitude": -747727624 + }, + "name": "1 Merck Access Road, Whitehouse Station, NJ 08889, USA" + }, + { + "location": { + "latitude": 416318082, + "longitude": -749677716 + }, + "name": "78-98 Schalck Road, Narrowsburg, NY 12764, USA" + }, + { + "location": { + "latitude": 415301720, + "longitude": -748416257 + }, + "name": "282 Lakeview Drive Road, Highland Lake, NY 12743, USA" + }, + { + "location": { + "latitude": 402647019, + "longitude": -747071791 + }, + "name": "330 Evelyn Avenue, Hamilton Township, NJ 08619, USA" + }, + { + "location": { + "latitude": 412567807, + "longitude": -741058078 + }, + "name": "New York State Reference Route 987E, Southfields, NY 10975, USA" + }, + { + "location": { + "latitude": 416855156, + "longitude": -744420597 + }, + "name": "103-271 Tempaloni Road, Ellenville, NY 12428, USA" + }, + { + "location": { + "latitude": 404663628, + "longitude": -744820157 + }, + "name": "1300 Airport Road, North Brunswick Township, NJ 08902, USA" + }, + { + "location": { + "latitude": 407113723, + "longitude": -749746483 + }, + "name": "" + }, + { + "location": { + "latitude": 402133926, + "longitude": -743613249 + }, + "name": "" + }, + { + "location": { + "latitude": 400273442, + "longitude": -741220915 + }, + "name": "" + }, + { + "location": { + "latitude": 411236786, + "longitude": -744070769 + }, + "name": "" + }, + { + "location": { + "latitude": 411633782, + "longitude": -746784970 + }, + "name": "211-225 Plains Road, Augusta, NJ 07822, USA" + }, + { + "location": { + "latitude": 415830701, + "longitude": -742952812 + }, + "name": "" + }, + { + "location": { + "latitude": 413447164, + "longitude": -748712898 + }, + "name": "165 Pedersen Ridge Road, Milford, PA 18337, USA" + }, + { + "location": { + "latitude": 405047245, + "longitude": -749800722 + }, + "name": "100-122 Locktown Road, Frenchtown, NJ 08825, USA" + }, + { + "location": { + "latitude": 418858923, + "longitude": -746156790 + }, + "name": "" + }, + { + "location": { + "latitude": 417951888, + "longitude": -748484944 + }, + "name": "650-652 Willi Hill Road, Swan Lake, NY 12783, USA" + }, + { + "location": { + "latitude": 407033786, + "longitude": -743977337 + }, + "name": "26 East 3rd Street, New Providence, NJ 07974, USA" + }, + { + "location": { + "latitude": 417548014, + "longitude": -740075041 + }, + "name": "" + }, + { + "location": { + "latitude": 410395868, + "longitude": -744972325 + }, + "name": "" + }, + { + "location": { + "latitude": 404615353, + "longitude": -745129803 + }, + "name": "" + }, + { + "location": { + "latitude": 406589790, + "longitude": -743560121 + }, + "name": "611 Lawrence Avenue, Westfield, NJ 07090, USA" + }, + { + "location": { + "latitude": 414653148, + "longitude": -740477477 + }, + "name": "18 Lannis Avenue, New Windsor, NY 12553, USA" + }, + { + "location": { + "latitude": 405957808, + "longitude": -743255336 + }, + "name": "82-104 Amherst Avenue, Colonia, NJ 07067, USA" + }, + { + "location": { + "latitude": 411733589, + "longitude": -741648093 + }, + "name": "170 Seven Lakes Drive, Sloatsburg, NY 10974, USA" + }, + { + "location": { + "latitude": 412676291, + "longitude": -742606606 + }, + "name": "1270 Lakes Road, Monroe, NY 10950, USA" + }, + { + "location": { + "latitude": 409224445, + "longitude": -748286738 + }, + "name": "509-535 Alphano Road, Great Meadows, NJ 07838, USA" + }, + { + "location": { + "latitude": 406523420, + "longitude": -742135517 + }, + "name": "652 Garden Street, Elizabeth, NJ 07202, USA" + }, + { + "location": { + "latitude": 401827388, + "longitude": -740294537 + }, + "name": "349 Sea Spray Court, Neptune City, NJ 07753, USA" + }, + { + "location": { + "latitude": 410564152, + "longitude": -743685054 + }, + "name": "13-17 Stanley Street, West Milford, NJ 07480, USA" + }, + { + "location": { + "latitude": 408472324, + "longitude": -740726046 + }, + "name": "47 Industrial Avenue, Teterboro, NJ 07608, USA" + }, + { + "location": { + "latitude": 412452168, + "longitude": -740214052 + }, + "name": "5 White Oak Lane, Stony Point, NY 10980, USA" + }, + { + "location": { + "latitude": 409146138, + "longitude": -746188906 + }, + "name": "Berkshire Valley Management Area Trail, Jefferson, NJ, USA" + }, + { + "location": { + "latitude": 404701380, + "longitude": -744781745 + }, + "name": "1007 Jersey Avenue, New Brunswick, NJ 08901, USA" + }, + { + "location": { + "latitude": 409642566, + "longitude": -746017679 + }, + "name": "6 East Emerald Isle Drive, Lake Hopatcong, NJ 07849, USA" + }, + { + "location": { + "latitude": 408031728, + "longitude": -748645385 + }, + "name": "1358-1474 New Jersey 57, Port Murray, NJ 07865, USA" + }, + { + "location": { + "latitude": 413700272, + "longitude": -742135189 + }, + "name": "367 Prospect Road, Chester, NY 10918, USA" + }, + { + "location": { + "latitude": 404310607, + "longitude": -740282632 + }, + "name": "10 Simon Lake Drive, Atlantic Highlands, NJ 07716, USA" + }, + { + "location": { + "latitude": 409319800, + "longitude": -746201391 + }, + "name": "11 Ward Street, Mount Arlington, NJ 07856, USA" + }, + { + "location": { + "latitude": 406685311, + "longitude": -742108603 + }, + "name": "300-398 Jefferson Avenue, Elizabeth, NJ 07201, USA" + }, + { + "location": { + "latitude": 419018117, + "longitude": -749142781 + }, + "name": "43 Dreher Road, Roscoe, NY 12776, USA" + }, + { + "location": { + "latitude": 412856162, + "longitude": -745148837 + }, + "name": "Swan Street, Pine Island, NY 10969, USA" + }, + { + "location": { + "latitude": 416560744, + "longitude": -746721964 + }, + "name": "66 Pleasantview Avenue, Monticello, NY 12701, USA" + }, + { + "location": { + "latitude": 405314270, + "longitude": -749836354 + }, + "name": "" + }, + { + "location": { + "latitude": 414219548, + "longitude": -743327440 + }, + "name": "" + }, + { + "location": { + "latitude": 415534177, + "longitude": -742900616 + }, + "name": "565 Winding Hills Road, Montgomery, NY 12549, USA" + }, + { + "location": { + "latitude": 406898530, + "longitude": -749127080 + }, + "name": "231 Rocky Run Road, Glen Gardner, NJ 08826, USA" + }, + { + "location": { + "latitude": 407586880, + "longitude": -741670168 + }, + "name": "100 Mount Pleasant Avenue, Newark, NJ 07104, USA" + }, + { + "location": { + "latitude": 400106455, + "longitude": -742870190 + }, + "name": "517-521 Huntington Drive, Manchester Township, NJ 08759, USA" + }, + { + "location": { + "latitude": 400066188, + "longitude": -746793294 + }, + "name": "" + }, + { + "location": { + "latitude": 418803880, + "longitude": -744102673 + }, + "name": "40 Mountain Road, Napanoch, NY 12458, USA" + }, + { + "location": { + "latitude": 414204288, + "longitude": -747895140 + }, + "name": "" + }, + { + "location": { + "latitude": 414777405, + "longitude": -740615601 + }, + "name": "" + }, + { + "location": { + "latitude": 415464475, + "longitude": -747175374 + }, + "name": "48 North Road, Forestburgh, NY 12777, USA" + }, + { + "location": { + "latitude": 404062378, + "longitude": -746376177 + }, + "name": "" + }, + { + "location": { + "latitude": 405688272, + "longitude": -749285130 + }, + "name": "" + }, + { + "location": { + "latitude": 400342070, + "longitude": -748788996 + }, + "name": "" + }, + { + "location": { + "latitude": 401809022, + "longitude": -744157964 + }, + "name": "" + }, + { + "location": { + "latitude": 404226644, + "longitude": -740517141 + }, + "name": "9 Thompson Avenue, Leonardo, NJ 07737, USA" + }, + { + "location": { + "latitude": 410322033, + "longitude": -747871659 + }, + "name": "" + }, + { + "location": { + "latitude": 407100674, + "longitude": -747742727 + }, + "name": "" + }, + { + "location": { + "latitude": 418811433, + "longitude": -741718005 + }, + "name": "213 Bush Road, Stone Ridge, NY 12484, USA" + }, + { + "location": { + "latitude": 415034302, + "longitude": -743850945 + }, + "name": "" + }, + { + "location": { + "latitude": 411349992, + "longitude": -743694161 + }, + "name": "" + }, + { + "location": { + "latitude": 404839914, + "longitude": -744759616 + }, + "name": "1-17 Bergen Court, New Brunswick, NJ 08901, USA" + }, + { + "location": { + "latitude": 414638017, + "longitude": -745957854 + }, + "name": "35 Oakland Valley Road, Cuddebackville, NY 12729, USA" + }, + { + "location": { + "latitude": 412127800, + "longitude": -740173578 + }, + "name": "" + }, + { + "location": { + "latitude": 401263460, + "longitude": -747964303 + }, + "name": "" + }, + { + "location": { + "latitude": 412843391, + "longitude": -749086026 + }, + "name": "" + }, + { + "location": { + "latitude": 418512773, + "longitude": -743067823 + }, + "name": "" + }, + { + "location": { + "latitude": 404318328, + "longitude": -740835638 + }, + "name": "42-102 Main Street, Belford, NJ 07718, USA" + }, + { + "location": { + "latitude": 419020746, + "longitude": -741172328 + }, + "name": "" + }, + { + "location": { + "latitude": 404080723, + "longitude": -746119569 + }, + "name": "" + }, + { + "location": { + "latitude": 401012643, + "longitude": -744035134 + }, + "name": "" + }, + { + "location": { + "latitude": 404306372, + "longitude": -741079661 + }, + "name": "" + }, + { + "location": { + "latitude": 403966326, + "longitude": -748519297 + }, + "name": "" + }, + { + "location": { + "latitude": 405002031, + "longitude": -748407866 + }, + "name": "" + }, + { + "location": { + "latitude": 409532885, + "longitude": -742200683 + }, + "name": "" + }, + { + "location": { + "latitude": 416851321, + "longitude": -742674555 + }, + "name": "" + }, + { + "location": { + "latitude": 406411633, + "longitude": -741722051 + }, + "name": "3387 Richmond Terrace, Staten Island, NY 10303, USA" + }, + { + "location": { + "latitude": 413069058, + "longitude": -744597778 + }, + "name": "261 Van Sickle Road, Goshen, NY 10924, USA" + }, + { + "location": { + "latitude": 418465462, + "longitude": -746859398 + }, + "name": "" + }, + { + "location": { + "latitude": 411733222, + "longitude": -744228360 + }, + "name": "" + }, + { + "location": { + "latitude": 410248224, + "longitude": -747127767 + }, + "name": "3 Hasta Way, Newton, NJ 07860, USA" + } +] \ No newline at end of file diff --git a/codelabs/grpc-rust-getting-started/start_here/src/server/server.rs b/codelabs/grpc-rust-getting-started/start_here/src/server/server.rs new file mode 100644 index 00000000..ba9fe0ff --- /dev/null +++ b/codelabs/grpc-rust-getting-started/start_here/src/server/server.rs @@ -0,0 +1,89 @@ +use std::sync::Arc; +use tonic::transport::Server; +use tonic::{Request, Response, Status}; +use serde::Deserialize; +use std::fs::File; +use protobuf::proto; + +// ///////////////////////////////////////////////////////////////////////// +// Codelab Hint: Bring the generated code into scope. +// ///////////////////////////////////////////////////////////////////////// + +#[derive(Debug, Deserialize)] +struct JsonFeature { + location: Location, + name: String, +} + +#[derive(Debug, Deserialize)] +struct Location { + latitude: i32, + longitude: i32, +} + +#[derive(Debug)] +pub struct RouteGuideService { + features: Arc>, +} + +#[tonic::async_trait] +impl RouteGuide for RouteGuideService { + async fn get_feature(&self, request: Request) -> Result, Status> { + // ///////////////////////////////////////////////////////////////////////// + // Codelab Hint: Logic for GetFeature will be added here. + // + // Steps include: + // - Loop through server's features to find the feature that matches the + // point. + // - Return the feature if found. + // - Return an unnamed feature if no feature is found. + // ///////////////////////////////////////////////////////////////////////// + } +} + + +#[tokio::main] +async fn main() { + /////////////////////////////////////////////////////////////////////////// + // Codelab Hint: Logic for starting up a gRPC Server will be added here. + // + // Steps include: + // - Specify the port we want to use to listen for client requests using + // - Create an instance of the gRPC server using RouteGuideServer::new(). + // - Register our service implementation with the server. + /////////////////////////////////////////////////////////////////////////// +} + +#[derive(Debug, Deserialize)] +struct JsonFeature { + location: Location, + name: String, +} + +#[derive(Debug, Deserialize)] +struct Location { + latitude: i32, + longitude: i32, +} + +#[allow(dead_code)] +pub fn load() -> Vec { + let data_dir = std::path::PathBuf::from_iter([ + std::env!("CARGO_MANIFEST_DIR"), + "src", + "data" + ]); + let file = File::open(data_dir.join("route_guide_db.json")).expect("failed to open data file"); + let decoded: Vec = + serde_json::from_reader(&file).expect("failed to deserialize features"); + decoded + .into_iter() + .map(|feature| proto!(Feature { + name: feature.name, + location: proto!(Point { + longitude: feature.location.longitude, + latitude: feature.location.latitude, + }), + })) + .collect() +} \ No newline at end of file