diff --git a/codelabs/grpc-rust-streaming/README.md b/codelabs/grpc-rust-streaming/README.md new file mode 100644 index 00000000..4cfb230f --- /dev/null +++ b/codelabs/grpc-rust-streaming/README.md @@ -0,0 +1,126 @@ +# 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 all the dependencies we'll need for this example: + +```toml +[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"} +tonic-prost = {git = "https://github.com/hyperium/tonic", branch = "master", package = "tonic-prost" } +# 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] +tonic-protobuf-build = {git = "https://github.com/hyperium/tonic.git", branch = "master", package = "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 +``` + +## 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 { + grpc::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-streaming/completed/Cargo.toml b/codelabs/grpc-rust-streaming/completed/Cargo.toml new file mode 100644 index 00000000..3e4015b2 --- /dev/null +++ b/codelabs/grpc-rust-streaming/completed/Cargo.toml @@ -0,0 +1,76 @@ +[package] +authors = ["Lucio Franco "] +edition = "2021" +license = "MIT" +name = "examples" + +[[bin]] +name = "routeguide-server" +path = "src/server/server.rs" +required-features = ["routeguide"] + +[[bin]] +name = "routeguide-client" +path = "src/client/client.rs" +required-features = ["routeguide"] + +[features] +gcp = ["dep:prost-types", "tonic/tls-ring"] +routeguide = ["dep:async-stream", "dep:tokio-stream", "dep:rand", "dep:serde", "dep:serde_json"] +reflection = ["dep:tonic-reflection"] +autoreload = ["dep:tokio-stream", "tokio-stream?/net", "dep:listenfd"] +health = ["dep:tonic-health"] +grpc-web = ["dep:tonic-web", "dep:bytes", "dep:http", "dep:hyper", "dep:hyper-util", "dep:tracing-subscriber", "dep:tower", "dep:tower-http", "tower-http?/cors"] +tracing = ["dep:tracing", "dep:tracing-subscriber"] +uds = ["dep:tokio-stream", "tokio-stream?/net", "dep:tower", "dep:hyper", "dep:hyper-util"] +streaming = ["dep:tokio-stream", "dep:h2"] +mock = ["dep:tokio-stream", "dep:tower", "dep:hyper-util"] +tower = ["dep:tower", "dep:http"] +json-codec = ["dep:serde", "dep:serde_json", "dep:bytes"] +compression = ["tonic/gzip"] +tls = ["tonic/tls-ring"] +tls-rustls = ["dep:http", "dep:hyper", "dep:hyper-util", "dep:hyper-rustls", "dep:tower", "tower-http/util", "tower-http/add-extension", "dep:tokio-rustls"] +tls-client-auth = ["tonic/tls-ring"] +types = ["dep:tonic-types"] +h2c = ["dep:hyper", "dep:tower", "dep:http", "dep:hyper-util"] +cancellation = ["dep:tokio-util"] + +full = ["gcp", "routeguide", "reflection", "autoreload", "health", "grpc-web", "tracing", "uds", "streaming", "mock", "tower", "json-codec", "compression", "tls", "tls-rustls", "tls-client-auth", "types", "cancellation", "h2c"] +default = ["full"] + +[dependencies] +# Common dependencies +tokio = { version = "1.0", features = ["rt-multi-thread", "macros"] } +prost = "0.14" +tonic = { git = "https://github.com/arjan-bal/tonic.git", branch = "grpc-codegen" } +tonic-protobuf = {git = "https://github.com/arjan-bal/tonic.git", branch = "grpc-codegen", package = "tonic-protobuf" } +grpc = {git = "https://github.com/arjan-bal/tonic.git", branch = "grpc-codegen", 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 } +tonic-web = { git = "https://github.com/arjan-bal/tonic.git", branch = "grpc-codegen", package = "tonic-web", optional = true } +tonic-health = { git = "https://github.com/arjan-bal/tonic.git", branch = "grpc-codegen", package = "tonic-health", optional = true } +tonic-reflection = { git = "https://github.com/arjan-bal/tonic.git", branch = "grpc-codegen", package = "tonic-reflection", optional = true } +tonic-types = { git = "https://github.com/arjan-bal/tonic.git", branch = "grpc-codegen", package = "tonic-types", 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"} +listenfd = { version = "1.0", optional = true } +bytes = { version = "1", optional = true } +h2 = { version = "0.4", optional = true } +tracing = { version = "0.1.16", optional = true } +tracing-subscriber = { version = "0.3", features = ["tracing-log", "fmt"], optional = true } + +[build-dependencies] +protobuf-codegen = { version = "4.31.1-release"} \ No newline at end of file diff --git a/codelabs/grpc-rust-streaming/completed/build.rs b/codelabs/grpc-rust-streaming/completed/build.rs new file mode 100644 index 00000000..ecf15526 --- /dev/null +++ b/codelabs/grpc-rust-streaming/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-streaming/completed/generated/crate_mapping.txt b/codelabs/grpc-rust-streaming/completed/generated/crate_mapping.txt new file mode 100644 index 00000000..e69de29b diff --git a/codelabs/grpc-rust-streaming/completed/generated/generated.rs b/codelabs/grpc-rust-streaming/completed/generated/generated.rs new file mode 100644 index 00000000..3bd5dfb0 --- /dev/null +++ b/codelabs/grpc-rust-streaming/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-streaming/completed/generated/routeguide.u.pb.rs b/codelabs/grpc-rust-streaming/completed/generated/routeguide.u.pb.rs new file mode 100644 index 00000000..b212c947 --- /dev/null +++ b/codelabs/grpc-rust-streaming/completed/generated/routeguide.u.pb.rs @@ -0,0 +1,4686 @@ +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 Rectangle { + inner: ::protobuf::__internal::runtime::MessageInner, +} +impl ::protobuf::Message for Rectangle {} +impl ::std::default::Default for Rectangle { + fn default() -> Self { + Self::new() + } +} +impl ::protobuf::Parse for Rectangle { + fn parse(serialized: &[u8]) -> ::std::result::Result { + Self::parse(serialized) + } +} +impl ::std::fmt::Debug for Rectangle { + 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 Rectangle { + 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 Rectangle { + 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 Rectangle { + 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 Rectangle { + fn serialize(&self) -> ::std::result::Result, ::protobuf::SerializeError> { + ::protobuf::AsView::as_view(self).serialize() + } +} +impl ::protobuf::Clear for Rectangle { + fn clear(&mut self) { + let mut m = self.as_mut(); + ::protobuf::Clear::clear(&mut m) + } +} +impl ::protobuf::ClearAndParse for Rectangle { + 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 Rectangle {} +unsafe impl Send for Rectangle {} +impl ::protobuf::Proxied for Rectangle { + type View<'msg> = RectangleView<'msg>; +} +impl ::protobuf::__internal::SealedInternal for Rectangle {} +impl ::protobuf::MutProxied for Rectangle { + type Mut<'msg> = RectangleMut<'msg>; +} +#[derive(Copy, Clone)] +#[allow(dead_code)] +pub struct RectangleView<'msg> { + msg: ::protobuf::__internal::runtime::RawMessage, + _phantom: ::std::marker::PhantomData<&'msg ()>, +} +impl<'msg> ::protobuf::__internal::SealedInternal for RectangleView<'msg> {} +impl<'msg> ::protobuf::MessageView<'msg> for RectangleView<'msg> { + type Message = Rectangle; +} +impl ::std::fmt::Debug for RectangleView<'_> { + 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 RectangleView<'_> { + 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 RectangleView<'_> { + fn default() -> RectangleView<'static> { + RectangleView::new( + ::protobuf::__internal::Private, + ::protobuf::__internal::runtime::ScratchSpace::zeroed_block(), + ) + } +} +#[allow(dead_code)] +impl<'msg> RectangleView<'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) -> Rectangle { + ::protobuf::IntoProxied::into_proxied(*self, ::protobuf::__internal::Private) + } + pub fn has_lo(self) -> bool { + unsafe { + let f = ::protobuf::__internal::runtime::upb_MiniTable_GetFieldByIndex( + ::mini_table(), + 0, + ); + ::protobuf::__internal::runtime::upb_Message_HasBaseField(self.raw_msg(), f) + } + } + pub fn lo_opt(self) -> ::protobuf::Optional> { + ::protobuf::Optional::new(self.lo(), self.has_lo()) + } + pub fn lo(self) -> super::PointView<'msg> { + let submsg = unsafe { + let f = ::protobuf::__internal::runtime::upb_MiniTable_GetFieldByIndex( + ::mini_table(), + 0, + ); + ::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 has_hi(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 hi_opt(self) -> ::protobuf::Optional> { + ::protobuf::Optional::new(self.hi(), self.has_hi()) + } + pub fn hi(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 RectangleView<'_> {} +unsafe impl Send for RectangleView<'_> {} +impl<'msg> ::protobuf::Proxy<'msg> for RectangleView<'msg> {} +impl<'msg> ::protobuf::ViewProxy<'msg> for RectangleView<'msg> {} +impl<'msg> ::protobuf::AsView for RectangleView<'msg> { + type Proxied = Rectangle; + fn as_view(&self) -> ::protobuf::View<'msg, Rectangle> { + *self + } +} +impl<'msg> ::protobuf::IntoView<'msg> for RectangleView<'msg> { + fn into_view<'shorter>(self) -> RectangleView<'shorter> + where + 'msg: 'shorter, + { + self + } +} +impl<'msg> ::protobuf::IntoProxied for RectangleView<'msg> { + fn into_proxied(self, _private: ::protobuf::__internal::Private) -> Rectangle { + let dst = Rectangle::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 RectangleMut<'msg> { + fn into_proxied(self, _private: ::protobuf::__internal::Private) -> Rectangle { + ::protobuf::IntoProxied::into_proxied( + ::protobuf::IntoView::into_view(self), + _private, + ) + } +} +unsafe impl ::protobuf::ProxiedInRepeated for Rectangle { + 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 Rectangle { + 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> { + RectangleView::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, + ) -> RectangleMut<'msg> { + RectangleMut { + 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 RectangleMut<'msg> { + inner: ::protobuf::__internal::runtime::MutatorMessageRef<'msg>, +} +impl<'msg> ::protobuf::__internal::SealedInternal for RectangleMut<'msg> {} +impl<'msg> ::protobuf::MessageMut<'msg> for RectangleMut<'msg> { + type Message = Rectangle; +} +impl ::std::fmt::Debug for RectangleMut<'_> { + 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 RectangleMut<'_> { + fn serialize(&self) -> ::std::result::Result, ::protobuf::SerializeError> { + ::protobuf::AsView::as_view(self).serialize() + } +} +impl ::protobuf::Clear for RectangleMut<'_> { + fn clear(&mut self) { + unsafe { + ::protobuf::__internal::runtime::upb_Message_Clear( + self.raw_msg(), + ::mini_table(), + ) + } + } +} +impl ::protobuf::ClearAndParse for RectangleMut<'_> { + 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 RectangleMut<'_> { + 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 RectangleMut<'_> { + 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 RectangleMut<'_> { + 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> RectangleMut<'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) -> Rectangle { + ::protobuf::AsView::as_view(self).to_owned() + } + fn arena(&self) -> &::protobuf::__internal::runtime::Arena { + self.inner.arena() + } + pub fn has_lo(&self) -> bool { + unsafe { + let f = ::protobuf::__internal::runtime::upb_MiniTable_GetFieldByIndex( + ::mini_table(), + 0, + ); + ::protobuf::__internal::runtime::upb_Message_HasBaseField(self.raw_msg(), f) + } + } + pub fn clear_lo(&mut self) { + unsafe { + let mt = ::mini_table(); + let f = ::protobuf::__internal::runtime::upb_MiniTable_GetFieldByIndex( + mt, + 0, + ); + ::protobuf::__internal::runtime::upb_Message_ClearBaseField( + self.raw_msg(), + f, + ); + } + } + pub fn lo_opt(&self) -> ::protobuf::Optional> { + ::protobuf::Optional::new(self.lo(), self.has_lo()) + } + pub fn lo(&self) -> super::PointView<'_> { + let submsg = unsafe { + let f = ::protobuf::__internal::runtime::upb_MiniTable_GetFieldByIndex( + ::mini_table(), + 0, + ); + ::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 lo_mut(&mut self) -> super::PointMut<'_> { + let raw_msg = unsafe { + let mt = ::mini_table(); + let f = ::protobuf::__internal::runtime::upb_MiniTable_GetFieldByIndex( + mt, + 0, + ); + ::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_lo(&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(), + 0, + ); + ::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(), + ); + } + } + pub fn has_hi(&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_hi(&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 hi_opt(&self) -> ::protobuf::Optional> { + ::protobuf::Optional::new(self.hi(), self.has_hi()) + } + pub fn hi(&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 hi_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_hi(&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 RectangleMut<'_> {} +impl<'msg> ::protobuf::Proxy<'msg> for RectangleMut<'msg> {} +impl<'msg> ::protobuf::MutProxy<'msg> for RectangleMut<'msg> {} +impl<'msg> ::protobuf::AsView for RectangleMut<'msg> { + type Proxied = Rectangle; + fn as_view(&self) -> ::protobuf::View<'_, Rectangle> { + RectangleView { + msg: self.raw_msg(), + _phantom: ::std::marker::PhantomData, + } + } +} +impl<'msg> ::protobuf::IntoView<'msg> for RectangleMut<'msg> { + fn into_view<'shorter>(self) -> ::protobuf::View<'shorter, Rectangle> + where + 'msg: 'shorter, + { + RectangleView { + msg: self.raw_msg(), + _phantom: ::std::marker::PhantomData, + } + } +} +impl<'msg> ::protobuf::AsMut for RectangleMut<'msg> { + type MutProxied = Rectangle; + fn as_mut(&mut self) -> RectangleMut<'msg> { + RectangleMut { inner: self.inner } + } +} +impl<'msg> ::protobuf::IntoMut<'msg> for RectangleMut<'msg> { + fn into_mut<'shorter>(self) -> RectangleMut<'shorter> + where + 'msg: 'shorter, + { + self + } +} +#[allow(dead_code)] +impl Rectangle { + 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) -> RectangleView { + RectangleView::new(::protobuf::__internal::Private, self.inner.msg) + } + pub fn as_mut(&mut self) -> RectangleMut { + RectangleMut::new(::protobuf::__internal::Private, &mut self.inner) + } + pub fn has_lo(&self) -> bool { + unsafe { + let f = ::protobuf::__internal::runtime::upb_MiniTable_GetFieldByIndex( + ::mini_table(), + 0, + ); + ::protobuf::__internal::runtime::upb_Message_HasBaseField(self.raw_msg(), f) + } + } + pub fn clear_lo(&mut self) { + unsafe { + let mt = ::mini_table(); + let f = ::protobuf::__internal::runtime::upb_MiniTable_GetFieldByIndex( + mt, + 0, + ); + ::protobuf::__internal::runtime::upb_Message_ClearBaseField( + self.raw_msg(), + f, + ); + } + } + pub fn lo_opt(&self) -> ::protobuf::Optional> { + ::protobuf::Optional::new(self.lo(), self.has_lo()) + } + pub fn lo(&self) -> super::PointView<'_> { + let submsg = unsafe { + let f = ::protobuf::__internal::runtime::upb_MiniTable_GetFieldByIndex( + ::mini_table(), + 0, + ); + ::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 lo_mut(&mut self) -> super::PointMut<'_> { + let raw_msg = unsafe { + let mt = ::mini_table(); + let f = ::protobuf::__internal::runtime::upb_MiniTable_GetFieldByIndex( + mt, + 0, + ); + ::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_lo(&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(), + 0, + ); + ::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(), + ); + } + } + pub fn has_hi(&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_hi(&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 hi_opt(&self) -> ::protobuf::Optional> { + ::protobuf::Optional::new(self.hi(), self.has_hi()) + } + pub fn hi(&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 hi_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_hi(&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 Rectangle { + fn drop(&mut self) {} +} +impl ::std::clone::Clone for Rectangle { + fn clone(&self) -> Self { + self.as_view().to_owned() + } +} +impl ::protobuf::AsView for Rectangle { + type Proxied = Self; + fn as_view(&self) -> RectangleView { + self.as_view() + } +} +impl ::protobuf::AsMut for Rectangle { + type MutProxied = Self; + fn as_mut(&mut self) -> RectangleMut { + self.as_mut() + } +} +unsafe impl ::protobuf::__internal::runtime::AssociatedMiniTable for Rectangle { + #[inline(always)] + fn mini_table() -> *const ::protobuf::__internal::runtime::upb_MiniTable { + #[allow(unused_unsafe)] + unsafe { ::std::ptr::addr_of!(routeguide__Rectangle_msg_init) } + } +} +unsafe impl ::protobuf::__internal::runtime::AssociatedMiniTable for RectangleView<'_> { + #[inline(always)] + fn mini_table() -> *const ::protobuf::__internal::runtime::upb_MiniTable { + #[allow(unused_unsafe)] + unsafe { ::std::ptr::addr_of!(routeguide__Rectangle_msg_init) } + } +} +unsafe impl ::protobuf::__internal::runtime::AssociatedMiniTable for RectangleMut<'_> { + #[inline(always)] + fn mini_table() -> *const ::protobuf::__internal::runtime::upb_MiniTable { + #[allow(unused_unsafe)] + unsafe { ::std::ptr::addr_of!(routeguide__Rectangle_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__Rectangle_msg_init: ::protobuf::__internal::runtime::upb_MiniTable; +} +impl ::protobuf::OwnedMessageInterop for Rectangle {} +impl<'a> ::protobuf::MessageMutInterop<'a> for RectangleMut<'a> {} +impl<'a> ::protobuf::MessageViewInterop<'a> for RectangleView<'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 Rectangle { + 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 RectangleMut<'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 RectangleView<'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, + ) + } + } +} +#[allow(non_camel_case_types)] +pub struct RouteNote { + inner: ::protobuf::__internal::runtime::MessageInner, +} +impl ::protobuf::Message for RouteNote {} +impl ::std::default::Default for RouteNote { + fn default() -> Self { + Self::new() + } +} +impl ::protobuf::Parse for RouteNote { + fn parse(serialized: &[u8]) -> ::std::result::Result { + Self::parse(serialized) + } +} +impl ::std::fmt::Debug for RouteNote { + 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 RouteNote { + 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 RouteNote { + 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 RouteNote { + 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 RouteNote { + fn serialize(&self) -> ::std::result::Result, ::protobuf::SerializeError> { + ::protobuf::AsView::as_view(self).serialize() + } +} +impl ::protobuf::Clear for RouteNote { + fn clear(&mut self) { + let mut m = self.as_mut(); + ::protobuf::Clear::clear(&mut m) + } +} +impl ::protobuf::ClearAndParse for RouteNote { + 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 RouteNote {} +unsafe impl Send for RouteNote {} +impl ::protobuf::Proxied for RouteNote { + type View<'msg> = RouteNoteView<'msg>; +} +impl ::protobuf::__internal::SealedInternal for RouteNote {} +impl ::protobuf::MutProxied for RouteNote { + type Mut<'msg> = RouteNoteMut<'msg>; +} +#[derive(Copy, Clone)] +#[allow(dead_code)] +pub struct RouteNoteView<'msg> { + msg: ::protobuf::__internal::runtime::RawMessage, + _phantom: ::std::marker::PhantomData<&'msg ()>, +} +impl<'msg> ::protobuf::__internal::SealedInternal for RouteNoteView<'msg> {} +impl<'msg> ::protobuf::MessageView<'msg> for RouteNoteView<'msg> { + type Message = RouteNote; +} +impl ::std::fmt::Debug for RouteNoteView<'_> { + 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 RouteNoteView<'_> { + 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 RouteNoteView<'_> { + fn default() -> RouteNoteView<'static> { + RouteNoteView::new( + ::protobuf::__internal::Private, + ::protobuf::__internal::runtime::ScratchSpace::zeroed_block(), + ) + } +} +#[allow(dead_code)] +impl<'msg> RouteNoteView<'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) -> RouteNote { + ::protobuf::IntoProxied::into_proxied(*self, ::protobuf::__internal::Private) + } + pub fn has_location(self) -> bool { + unsafe { + let f = ::protobuf::__internal::runtime::upb_MiniTable_GetFieldByIndex( + ::mini_table(), + 0, + ); + ::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(), + 0, + ); + ::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 message(self) -> ::protobuf::View<'msg, ::protobuf::ProtoString> { + let str_view = unsafe { + let f = ::protobuf::__internal::runtime::upb_MiniTable_GetFieldByIndex( + ::mini_table(), + 1, + ); + ::protobuf::__internal::runtime::upb_Message_GetString( + self.raw_msg(), + f, + (b"").into(), + ) + }; + unsafe { ::protobuf::ProtoStr::from_utf8_unchecked(str_view.as_ref()) } + } +} +unsafe impl Sync for RouteNoteView<'_> {} +unsafe impl Send for RouteNoteView<'_> {} +impl<'msg> ::protobuf::Proxy<'msg> for RouteNoteView<'msg> {} +impl<'msg> ::protobuf::ViewProxy<'msg> for RouteNoteView<'msg> {} +impl<'msg> ::protobuf::AsView for RouteNoteView<'msg> { + type Proxied = RouteNote; + fn as_view(&self) -> ::protobuf::View<'msg, RouteNote> { + *self + } +} +impl<'msg> ::protobuf::IntoView<'msg> for RouteNoteView<'msg> { + fn into_view<'shorter>(self) -> RouteNoteView<'shorter> + where + 'msg: 'shorter, + { + self + } +} +impl<'msg> ::protobuf::IntoProxied for RouteNoteView<'msg> { + fn into_proxied(self, _private: ::protobuf::__internal::Private) -> RouteNote { + let dst = RouteNote::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 RouteNoteMut<'msg> { + fn into_proxied(self, _private: ::protobuf::__internal::Private) -> RouteNote { + ::protobuf::IntoProxied::into_proxied( + ::protobuf::IntoView::into_view(self), + _private, + ) + } +} +unsafe impl ::protobuf::ProxiedInRepeated for RouteNote { + 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 RouteNote { + 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> { + RouteNoteView::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, + ) -> RouteNoteMut<'msg> { + RouteNoteMut { + 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 RouteNoteMut<'msg> { + inner: ::protobuf::__internal::runtime::MutatorMessageRef<'msg>, +} +impl<'msg> ::protobuf::__internal::SealedInternal for RouteNoteMut<'msg> {} +impl<'msg> ::protobuf::MessageMut<'msg> for RouteNoteMut<'msg> { + type Message = RouteNote; +} +impl ::std::fmt::Debug for RouteNoteMut<'_> { + 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 RouteNoteMut<'_> { + fn serialize(&self) -> ::std::result::Result, ::protobuf::SerializeError> { + ::protobuf::AsView::as_view(self).serialize() + } +} +impl ::protobuf::Clear for RouteNoteMut<'_> { + fn clear(&mut self) { + unsafe { + ::protobuf::__internal::runtime::upb_Message_Clear( + self.raw_msg(), + ::mini_table(), + ) + } + } +} +impl ::protobuf::ClearAndParse for RouteNoteMut<'_> { + 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 RouteNoteMut<'_> { + 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 RouteNoteMut<'_> { + 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 RouteNoteMut<'_> { + 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> RouteNoteMut<'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) -> RouteNote { + ::protobuf::AsView::as_view(self).to_owned() + } + fn arena(&self) -> &::protobuf::__internal::runtime::Arena { + self.inner.arena() + } + pub fn has_location(&self) -> bool { + unsafe { + let f = ::protobuf::__internal::runtime::upb_MiniTable_GetFieldByIndex( + ::mini_table(), + 0, + ); + ::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, + 0, + ); + ::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(), + 0, + ); + ::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, + 0, + ); + ::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(), + 0, + ); + ::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(), + ); + } + } + pub fn message(&self) -> ::protobuf::View<'_, ::protobuf::ProtoString> { + let str_view = unsafe { + let f = ::protobuf::__internal::runtime::upb_MiniTable_GetFieldByIndex( + ::mini_table(), + 1, + ); + ::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_message( + &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(), + 1, + ); + ::protobuf::__internal::runtime::upb_Message_SetBaseFieldString( + self.as_mutator_message_ref(::protobuf::__internal::Private).msg(), + f, + view, + ); + } + } +} +unsafe impl Sync for RouteNoteMut<'_> {} +impl<'msg> ::protobuf::Proxy<'msg> for RouteNoteMut<'msg> {} +impl<'msg> ::protobuf::MutProxy<'msg> for RouteNoteMut<'msg> {} +impl<'msg> ::protobuf::AsView for RouteNoteMut<'msg> { + type Proxied = RouteNote; + fn as_view(&self) -> ::protobuf::View<'_, RouteNote> { + RouteNoteView { + msg: self.raw_msg(), + _phantom: ::std::marker::PhantomData, + } + } +} +impl<'msg> ::protobuf::IntoView<'msg> for RouteNoteMut<'msg> { + fn into_view<'shorter>(self) -> ::protobuf::View<'shorter, RouteNote> + where + 'msg: 'shorter, + { + RouteNoteView { + msg: self.raw_msg(), + _phantom: ::std::marker::PhantomData, + } + } +} +impl<'msg> ::protobuf::AsMut for RouteNoteMut<'msg> { + type MutProxied = RouteNote; + fn as_mut(&mut self) -> RouteNoteMut<'msg> { + RouteNoteMut { inner: self.inner } + } +} +impl<'msg> ::protobuf::IntoMut<'msg> for RouteNoteMut<'msg> { + fn into_mut<'shorter>(self) -> RouteNoteMut<'shorter> + where + 'msg: 'shorter, + { + self + } +} +#[allow(dead_code)] +impl RouteNote { + 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) -> RouteNoteView { + RouteNoteView::new(::protobuf::__internal::Private, self.inner.msg) + } + pub fn as_mut(&mut self) -> RouteNoteMut { + RouteNoteMut::new(::protobuf::__internal::Private, &mut self.inner) + } + pub fn has_location(&self) -> bool { + unsafe { + let f = ::protobuf::__internal::runtime::upb_MiniTable_GetFieldByIndex( + ::mini_table(), + 0, + ); + ::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, + 0, + ); + ::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(), + 0, + ); + ::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, + 0, + ); + ::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(), + 0, + ); + ::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(), + ); + } + } + pub fn message(&self) -> ::protobuf::View<'_, ::protobuf::ProtoString> { + let str_view = unsafe { + let f = ::protobuf::__internal::runtime::upb_MiniTable_GetFieldByIndex( + ::mini_table(), + 1, + ); + ::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_message( + &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(), + 1, + ); + ::protobuf::__internal::runtime::upb_Message_SetBaseFieldString( + self.as_mutator_message_ref(::protobuf::__internal::Private).msg(), + f, + view, + ); + } + } +} +impl ::std::ops::Drop for RouteNote { + fn drop(&mut self) {} +} +impl ::std::clone::Clone for RouteNote { + fn clone(&self) -> Self { + self.as_view().to_owned() + } +} +impl ::protobuf::AsView for RouteNote { + type Proxied = Self; + fn as_view(&self) -> RouteNoteView { + self.as_view() + } +} +impl ::protobuf::AsMut for RouteNote { + type MutProxied = Self; + fn as_mut(&mut self) -> RouteNoteMut { + self.as_mut() + } +} +unsafe impl ::protobuf::__internal::runtime::AssociatedMiniTable for RouteNote { + #[inline(always)] + fn mini_table() -> *const ::protobuf::__internal::runtime::upb_MiniTable { + #[allow(unused_unsafe)] + unsafe { ::std::ptr::addr_of!(routeguide__RouteNote_msg_init) } + } +} +unsafe impl ::protobuf::__internal::runtime::AssociatedMiniTable for RouteNoteView<'_> { + #[inline(always)] + fn mini_table() -> *const ::protobuf::__internal::runtime::upb_MiniTable { + #[allow(unused_unsafe)] + unsafe { ::std::ptr::addr_of!(routeguide__RouteNote_msg_init) } + } +} +unsafe impl ::protobuf::__internal::runtime::AssociatedMiniTable for RouteNoteMut<'_> { + #[inline(always)] + fn mini_table() -> *const ::protobuf::__internal::runtime::upb_MiniTable { + #[allow(unused_unsafe)] + unsafe { ::std::ptr::addr_of!(routeguide__RouteNote_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__RouteNote_msg_init: ::protobuf::__internal::runtime::upb_MiniTable; +} +impl ::protobuf::OwnedMessageInterop for RouteNote {} +impl<'a> ::protobuf::MessageMutInterop<'a> for RouteNoteMut<'a> {} +impl<'a> ::protobuf::MessageViewInterop<'a> for RouteNoteView<'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 RouteNote { + 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 RouteNoteMut<'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 RouteNoteView<'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 RouteSummary { + inner: ::protobuf::__internal::runtime::MessageInner, +} +impl ::protobuf::Message for RouteSummary {} +impl ::std::default::Default for RouteSummary { + fn default() -> Self { + Self::new() + } +} +impl ::protobuf::Parse for RouteSummary { + fn parse(serialized: &[u8]) -> ::std::result::Result { + Self::parse(serialized) + } +} +impl ::std::fmt::Debug for RouteSummary { + 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 RouteSummary { + 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 RouteSummary { + 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 RouteSummary { + 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 RouteSummary { + fn serialize(&self) -> ::std::result::Result, ::protobuf::SerializeError> { + ::protobuf::AsView::as_view(self).serialize() + } +} +impl ::protobuf::Clear for RouteSummary { + fn clear(&mut self) { + let mut m = self.as_mut(); + ::protobuf::Clear::clear(&mut m) + } +} +impl ::protobuf::ClearAndParse for RouteSummary { + 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 RouteSummary {} +unsafe impl Send for RouteSummary {} +impl ::protobuf::Proxied for RouteSummary { + type View<'msg> = RouteSummaryView<'msg>; +} +impl ::protobuf::__internal::SealedInternal for RouteSummary {} +impl ::protobuf::MutProxied for RouteSummary { + type Mut<'msg> = RouteSummaryMut<'msg>; +} +#[derive(Copy, Clone)] +#[allow(dead_code)] +pub struct RouteSummaryView<'msg> { + msg: ::protobuf::__internal::runtime::RawMessage, + _phantom: ::std::marker::PhantomData<&'msg ()>, +} +impl<'msg> ::protobuf::__internal::SealedInternal for RouteSummaryView<'msg> {} +impl<'msg> ::protobuf::MessageView<'msg> for RouteSummaryView<'msg> { + type Message = RouteSummary; +} +impl ::std::fmt::Debug for RouteSummaryView<'_> { + 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 RouteSummaryView<'_> { + 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 RouteSummaryView<'_> { + fn default() -> RouteSummaryView<'static> { + RouteSummaryView::new( + ::protobuf::__internal::Private, + ::protobuf::__internal::runtime::ScratchSpace::zeroed_block(), + ) + } +} +#[allow(dead_code)] +impl<'msg> RouteSummaryView<'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) -> RouteSummary { + ::protobuf::IntoProxied::into_proxied(*self, ::protobuf::__internal::Private) + } + pub fn point_count(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 feature_count(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 distance(self) -> i32 { + unsafe { + let mt = ::mini_table(); + let f = ::protobuf::__internal::runtime::upb_MiniTable_GetFieldByIndex( + mt, + 2, + ); + ::protobuf::__internal::runtime::upb_Message_GetInt32( + self.raw_msg(), + f, + (0i32).into(), + ) + .try_into() + .unwrap() + } + } + pub fn elapsed_time(self) -> i32 { + unsafe { + let mt = ::mini_table(); + let f = ::protobuf::__internal::runtime::upb_MiniTable_GetFieldByIndex( + mt, + 3, + ); + ::protobuf::__internal::runtime::upb_Message_GetInt32( + self.raw_msg(), + f, + (0i32).into(), + ) + .try_into() + .unwrap() + } + } +} +unsafe impl Sync for RouteSummaryView<'_> {} +unsafe impl Send for RouteSummaryView<'_> {} +impl<'msg> ::protobuf::Proxy<'msg> for RouteSummaryView<'msg> {} +impl<'msg> ::protobuf::ViewProxy<'msg> for RouteSummaryView<'msg> {} +impl<'msg> ::protobuf::AsView for RouteSummaryView<'msg> { + type Proxied = RouteSummary; + fn as_view(&self) -> ::protobuf::View<'msg, RouteSummary> { + *self + } +} +impl<'msg> ::protobuf::IntoView<'msg> for RouteSummaryView<'msg> { + fn into_view<'shorter>(self) -> RouteSummaryView<'shorter> + where + 'msg: 'shorter, + { + self + } +} +impl<'msg> ::protobuf::IntoProxied for RouteSummaryView<'msg> { + fn into_proxied(self, _private: ::protobuf::__internal::Private) -> RouteSummary { + let dst = RouteSummary::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 RouteSummaryMut<'msg> { + fn into_proxied(self, _private: ::protobuf::__internal::Private) -> RouteSummary { + ::protobuf::IntoProxied::into_proxied( + ::protobuf::IntoView::into_view(self), + _private, + ) + } +} +unsafe impl ::protobuf::ProxiedInRepeated for RouteSummary { + 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 RouteSummary { + 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> { + RouteSummaryView::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, + ) -> RouteSummaryMut<'msg> { + RouteSummaryMut { + 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 RouteSummaryMut<'msg> { + inner: ::protobuf::__internal::runtime::MutatorMessageRef<'msg>, +} +impl<'msg> ::protobuf::__internal::SealedInternal for RouteSummaryMut<'msg> {} +impl<'msg> ::protobuf::MessageMut<'msg> for RouteSummaryMut<'msg> { + type Message = RouteSummary; +} +impl ::std::fmt::Debug for RouteSummaryMut<'_> { + 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 RouteSummaryMut<'_> { + fn serialize(&self) -> ::std::result::Result, ::protobuf::SerializeError> { + ::protobuf::AsView::as_view(self).serialize() + } +} +impl ::protobuf::Clear for RouteSummaryMut<'_> { + fn clear(&mut self) { + unsafe { + ::protobuf::__internal::runtime::upb_Message_Clear( + self.raw_msg(), + ::mini_table(), + ) + } + } +} +impl ::protobuf::ClearAndParse for RouteSummaryMut<'_> { + 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 RouteSummaryMut<'_> { + 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 RouteSummaryMut<'_> { + 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 RouteSummaryMut<'_> { + 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> RouteSummaryMut<'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) -> RouteSummary { + ::protobuf::AsView::as_view(self).to_owned() + } + fn arena(&self) -> &::protobuf::__internal::runtime::Arena { + self.inner.arena() + } + pub fn point_count(&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_point_count(&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 feature_count(&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_feature_count(&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(), + ); + } + } + pub fn distance(&self) -> i32 { + unsafe { + let mt = ::mini_table(); + let f = ::protobuf::__internal::runtime::upb_MiniTable_GetFieldByIndex( + mt, + 2, + ); + ::protobuf::__internal::runtime::upb_Message_GetInt32( + self.raw_msg(), + f, + (0i32).into(), + ) + .try_into() + .unwrap() + } + } + pub fn set_distance(&mut self, val: i32) { + unsafe { + let mt = ::mini_table(); + let f = ::protobuf::__internal::runtime::upb_MiniTable_GetFieldByIndex( + mt, + 2, + ); + ::protobuf::__internal::runtime::upb_Message_SetBaseFieldInt32( + self.raw_msg(), + f, + val.into(), + ); + } + } + pub fn elapsed_time(&self) -> i32 { + unsafe { + let mt = ::mini_table(); + let f = ::protobuf::__internal::runtime::upb_MiniTable_GetFieldByIndex( + mt, + 3, + ); + ::protobuf::__internal::runtime::upb_Message_GetInt32( + self.raw_msg(), + f, + (0i32).into(), + ) + .try_into() + .unwrap() + } + } + pub fn set_elapsed_time(&mut self, val: i32) { + unsafe { + let mt = ::mini_table(); + let f = ::protobuf::__internal::runtime::upb_MiniTable_GetFieldByIndex( + mt, + 3, + ); + ::protobuf::__internal::runtime::upb_Message_SetBaseFieldInt32( + self.raw_msg(), + f, + val.into(), + ); + } + } +} +unsafe impl Sync for RouteSummaryMut<'_> {} +impl<'msg> ::protobuf::Proxy<'msg> for RouteSummaryMut<'msg> {} +impl<'msg> ::protobuf::MutProxy<'msg> for RouteSummaryMut<'msg> {} +impl<'msg> ::protobuf::AsView for RouteSummaryMut<'msg> { + type Proxied = RouteSummary; + fn as_view(&self) -> ::protobuf::View<'_, RouteSummary> { + RouteSummaryView { + msg: self.raw_msg(), + _phantom: ::std::marker::PhantomData, + } + } +} +impl<'msg> ::protobuf::IntoView<'msg> for RouteSummaryMut<'msg> { + fn into_view<'shorter>(self) -> ::protobuf::View<'shorter, RouteSummary> + where + 'msg: 'shorter, + { + RouteSummaryView { + msg: self.raw_msg(), + _phantom: ::std::marker::PhantomData, + } + } +} +impl<'msg> ::protobuf::AsMut for RouteSummaryMut<'msg> { + type MutProxied = RouteSummary; + fn as_mut(&mut self) -> RouteSummaryMut<'msg> { + RouteSummaryMut { + inner: self.inner, + } + } +} +impl<'msg> ::protobuf::IntoMut<'msg> for RouteSummaryMut<'msg> { + fn into_mut<'shorter>(self) -> RouteSummaryMut<'shorter> + where + 'msg: 'shorter, + { + self + } +} +#[allow(dead_code)] +impl RouteSummary { + 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) -> RouteSummaryView { + RouteSummaryView::new(::protobuf::__internal::Private, self.inner.msg) + } + pub fn as_mut(&mut self) -> RouteSummaryMut { + RouteSummaryMut::new(::protobuf::__internal::Private, &mut self.inner) + } + pub fn point_count(&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_point_count(&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 feature_count(&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_feature_count(&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(), + ); + } + } + pub fn distance(&self) -> i32 { + unsafe { + let mt = ::mini_table(); + let f = ::protobuf::__internal::runtime::upb_MiniTable_GetFieldByIndex( + mt, + 2, + ); + ::protobuf::__internal::runtime::upb_Message_GetInt32( + self.raw_msg(), + f, + (0i32).into(), + ) + .try_into() + .unwrap() + } + } + pub fn set_distance(&mut self, val: i32) { + unsafe { + let mt = ::mini_table(); + let f = ::protobuf::__internal::runtime::upb_MiniTable_GetFieldByIndex( + mt, + 2, + ); + ::protobuf::__internal::runtime::upb_Message_SetBaseFieldInt32( + self.raw_msg(), + f, + val.into(), + ); + } + } + pub fn elapsed_time(&self) -> i32 { + unsafe { + let mt = ::mini_table(); + let f = ::protobuf::__internal::runtime::upb_MiniTable_GetFieldByIndex( + mt, + 3, + ); + ::protobuf::__internal::runtime::upb_Message_GetInt32( + self.raw_msg(), + f, + (0i32).into(), + ) + .try_into() + .unwrap() + } + } + pub fn set_elapsed_time(&mut self, val: i32) { + unsafe { + let mt = ::mini_table(); + let f = ::protobuf::__internal::runtime::upb_MiniTable_GetFieldByIndex( + mt, + 3, + ); + ::protobuf::__internal::runtime::upb_Message_SetBaseFieldInt32( + self.raw_msg(), + f, + val.into(), + ); + } + } +} +impl ::std::ops::Drop for RouteSummary { + fn drop(&mut self) {} +} +impl ::std::clone::Clone for RouteSummary { + fn clone(&self) -> Self { + self.as_view().to_owned() + } +} +impl ::protobuf::AsView for RouteSummary { + type Proxied = Self; + fn as_view(&self) -> RouteSummaryView { + self.as_view() + } +} +impl ::protobuf::AsMut for RouteSummary { + type MutProxied = Self; + fn as_mut(&mut self) -> RouteSummaryMut { + self.as_mut() + } +} +unsafe impl ::protobuf::__internal::runtime::AssociatedMiniTable for RouteSummary { + #[inline(always)] + fn mini_table() -> *const ::protobuf::__internal::runtime::upb_MiniTable { + #[allow(unused_unsafe)] + unsafe { ::std::ptr::addr_of!(routeguide__RouteSummary_msg_init) } + } +} +unsafe impl ::protobuf::__internal::runtime::AssociatedMiniTable +for RouteSummaryView<'_> { + #[inline(always)] + fn mini_table() -> *const ::protobuf::__internal::runtime::upb_MiniTable { + #[allow(unused_unsafe)] + unsafe { ::std::ptr::addr_of!(routeguide__RouteSummary_msg_init) } + } +} +unsafe impl ::protobuf::__internal::runtime::AssociatedMiniTable +for RouteSummaryMut<'_> { + #[inline(always)] + fn mini_table() -> *const ::protobuf::__internal::runtime::upb_MiniTable { + #[allow(unused_unsafe)] + unsafe { ::std::ptr::addr_of!(routeguide__RouteSummary_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__RouteSummary_msg_init: ::protobuf::__internal::runtime::upb_MiniTable; +} +impl ::protobuf::OwnedMessageInterop for RouteSummary {} +impl<'a> ::protobuf::MessageMutInterop<'a> for RouteSummaryMut<'a> {} +impl<'a> ::protobuf::MessageViewInterop<'a> for RouteSummaryView<'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 RouteSummary { + 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 RouteSummaryMut<'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 RouteSummaryView<'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-streaming/completed/generated/routeguide.upb_minitable.c b/codelabs/grpc-rust-streaming/completed/generated/routeguide.upb_minitable.c new file mode 100644 index 00000000..f3ebd220 --- /dev/null +++ b/codelabs/grpc-rust-streaming/completed/generated/routeguide.upb_minitable.c @@ -0,0 +1,151 @@ +/* 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_Rectangle__submsgs[2] = { + {.UPB_PRIVATE(submsg) = &routeguide__Point_msg_init_ptr}, + {.UPB_PRIVATE(submsg) = &routeguide__Point_msg_init_ptr}, +}; + +static const upb_MiniTableField routeguide_Rectangle__fields[2] = { + {1, UPB_SIZE(12, 16), 64, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, + {2, UPB_SIZE(16, 24), 65, 1, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, +}; + +const upb_MiniTable routeguide__Rectangle_msg_init = { + &routeguide_Rectangle__submsgs[0], + &routeguide_Rectangle__fields[0], + UPB_SIZE(24, 32), 2, kUpb_ExtMode_NonExtendable, 2, UPB_FASTTABLE_MASK(255), 0, +#ifdef UPB_TRACING_ENABLED + "routeguide.Rectangle", +#endif +}; + +const upb_MiniTable* routeguide__Rectangle_msg_init_ptr = &routeguide__Rectangle_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_MiniTableSubInternal routeguide_RouteNote__submsgs[1] = { + {.UPB_PRIVATE(submsg) = &routeguide__Point_msg_init_ptr}, +}; + +static const upb_MiniTableField routeguide_RouteNote__fields[2] = { + {1, UPB_SIZE(12, 32), 64, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, + {2, 16, 0, kUpb_NoSub, 9, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, +}; + +const upb_MiniTable routeguide__RouteNote_msg_init = { + &routeguide_RouteNote__submsgs[0], + &routeguide_RouteNote__fields[0], + UPB_SIZE(24, 40), 2, kUpb_ExtMode_NonExtendable, 2, UPB_FASTTABLE_MASK(24), 0, +#ifdef UPB_TRACING_ENABLED + "routeguide.RouteNote", +#endif + UPB_FASTTABLE_INIT({ + {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, + {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, + {0x001000003f000012, &upb_pss_1bt}, + {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, + }) +}; + +const upb_MiniTable* routeguide__RouteNote_msg_init_ptr = &routeguide__RouteNote_msg_init; +static const upb_MiniTableField routeguide_RouteSummary__fields[4] = { + {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)}, + {3, 16, 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}, + {4, 20, 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}, +}; + +const upb_MiniTable routeguide__RouteSummary_msg_init = { + NULL, + &routeguide_RouteSummary__fields[0], + 24, 4, kUpb_ExtMode_NonExtendable, 4, UPB_FASTTABLE_MASK(56), 0, +#ifdef UPB_TRACING_ENABLED + "routeguide.RouteSummary", +#endif + UPB_FASTTABLE_INIT({ + {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, + {0x000800003f000008, &upb_psv4_1bt}, + {0x000c00003f000010, &upb_psv4_1bt}, + {0x001000003f000018, &upb_psv4_1bt}, + {0x001400003f000020, &upb_psv4_1bt}, + {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, + {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, + {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, + }) +}; + +const upb_MiniTable* routeguide__RouteSummary_msg_init_ptr = &routeguide__RouteSummary_msg_init; +static const upb_MiniTable *messages_layout[5] = { + &routeguide__Point_msg_init, + &routeguide__Rectangle_msg_init, + &routeguide__Feature_msg_init, + &routeguide__RouteNote_msg_init, + &routeguide__RouteSummary_msg_init, +}; + +const upb_MiniTableFile routeguide_proto_upb_file_layout = { + messages_layout, + NULL, + NULL, + 5, + 0, + 0, +}; + +#include "upb/port/undef.inc" + diff --git a/codelabs/grpc-rust-streaming/completed/generated/routeguide.upb_minitable.h b/codelabs/grpc-rust-streaming/completed/generated/routeguide.upb_minitable.h new file mode 100644 index 00000000..3372a4da --- /dev/null +++ b/codelabs/grpc-rust-streaming/completed/generated/routeguide.upb_minitable.h @@ -0,0 +1,40 @@ +/* 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__Rectangle_msg_init; +extern const upb_MiniTable* routeguide__Rectangle_msg_init_ptr; +extern const upb_MiniTable routeguide__Feature_msg_init; +extern const upb_MiniTable* routeguide__Feature_msg_init_ptr; +extern const upb_MiniTable routeguide__RouteNote_msg_init; +extern const upb_MiniTable* routeguide__RouteNote_msg_init_ptr; +extern const upb_MiniTable routeguide__RouteSummary_msg_init; +extern const upb_MiniTable* routeguide__RouteSummary_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-streaming/completed/generated/routeguide_grpc.pb.rs b/codelabs/grpc-rust-streaming/completed/generated/routeguide_grpc.pb.rs new file mode 100644 index 00000000..9c31adfc --- /dev/null +++ b/codelabs/grpc-rust-streaming/completed/generated/routeguide_grpc.pb.rs @@ -0,0 +1,470 @@ +/// 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 server-to-client streaming RPC. + /// + /// Obtains the Features available within the given Rectangle. Results are + /// streamed rather than returned at once (e.g. in a response message with a + /// repeated field), as the rectangle may cover a large area and contain a + /// huge number of features. + pub async fn list_features( + &mut self, + request: impl tonic::IntoRequest, + ) -> std::result::Result< + tonic::Response>, + 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/ListFeatures", + ); + let mut req = request.into_request(); + req.extensions_mut() + .insert(GrpcMethod::new("routeguide.RouteGuide", "ListFeatures")); + self.inner.server_streaming(req, path, codec).await + } + /// A client-to-server streaming RPC. + /// + /// Accepts a stream of Points on a route being traversed, returning a + /// RouteSummary when traversal is completed. + pub async fn record_route( + &mut self, + request: impl tonic::IntoStreamingRequest, + ) -> 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/RecordRoute", + ); + let mut req = request.into_streaming_request(); + req.extensions_mut() + .insert(GrpcMethod::new("routeguide.RouteGuide", "RecordRoute")); + self.inner.client_streaming(req, path, codec).await + } + /// A Bidirectional streaming RPC. + /// + /// Accepts a stream of RouteNotes sent while a route is being traversed, + /// while receiving other RouteNotes (e.g. from other users). + pub async fn route_chat( + &mut self, + request: impl tonic::IntoStreamingRequest, + ) -> std::result::Result< + tonic::Response>, + 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/RouteChat", + ); + let mut req = request.into_streaming_request(); + req.extensions_mut() + .insert(GrpcMethod::new("routeguide.RouteGuide", "RouteChat")); + self.inner.streaming(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 server-to-client streaming RPC. + /// + /// Obtains the Features available within the given Rectangle. Results are + /// streamed rather than returned at once (e.g. in a response message with a + /// repeated field), as the rectangle may cover a large area and contain a + /// huge number of features. + async fn list_features( + &self, + request: tonic::Request, + ) -> std::result::Result< + tonic::Response>, + tonic::Status, + > { + Err(tonic::Status::unimplemented("Not yet implemented")) + } + /// A client-to-server streaming RPC. + /// + /// Accepts a stream of Points on a route being traversed, returning a + /// RouteSummary when traversal is completed. + async fn record_route( + &self, + request: tonic::Request>, + ) -> std::result::Result, tonic::Status> { + Err(tonic::Status::unimplemented("Not yet implemented")) + } + /// A Bidirectional streaming RPC. + /// + /// Accepts a stream of RouteNotes sent while a route is being traversed, + /// while receiving other RouteNotes (e.g. from other users). + async fn route_chat( + &self, + request: tonic::Request>, + ) -> std::result::Result< + tonic::Response>, + 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/ListFeatures" => { + #[allow(non_camel_case_types)] + struct list_featuresSvc(pub Arc); + impl< + T: RouteGuide, + > tonic::server::ServerStreamingService + for list_featuresSvc { + type Response = super::Feature; + type ResponseStream = BoxStream; + 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 { + ::list_features(&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 = list_featuresSvc(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.server_streaming(method, req).await; + Ok(res) + }; + Box::pin(fut) + } + "/routeguide.RouteGuide/RecordRoute" => { + #[allow(non_camel_case_types)] + struct record_routeSvc(pub Arc); + impl< + T: RouteGuide, + > tonic::server::ClientStreamingService + for record_routeSvc { + type Response = super::RouteSummary; + 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 { + ::record_route(&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 = record_routeSvc(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.client_streaming(method, req).await; + Ok(res) + }; + Box::pin(fut) + } + "/routeguide.RouteGuide/RouteChat" => { + #[allow(non_camel_case_types)] + struct route_chatSvc(pub Arc); + impl tonic::server::StreamingService + for route_chatSvc { + type Response = super::RouteNote; + type ResponseStream = BoxStream; + 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 { + ::route_chat(&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 = route_chatSvc(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.streaming(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-streaming/completed/proto/routeguide.proto b/codelabs/grpc-rust-streaming/completed/proto/routeguide.proto new file mode 100644 index 00000000..42ccf5ea --- /dev/null +++ b/codelabs/grpc-rust-streaming/completed/proto/routeguide.proto @@ -0,0 +1,101 @@ +// Copyright 2024 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 server-to-client streaming RPC. + // + // Obtains the Features available within the given Rectangle. Results are + // streamed rather than returned at once (e.g. in a response message with a + // repeated field), as the rectangle may cover a large area and contain a + // huge number of features. + rpc ListFeatures(Rectangle) returns (stream Feature) {} + + // A client-to-server streaming RPC. + // + // Accepts a stream of Points on a route being traversed, returning a + // RouteSummary when traversal is completed. + rpc RecordRoute(stream Point) returns (RouteSummary) {} + + // A Bidirectional streaming RPC. + // + // Accepts a stream of RouteNotes sent while a route is being traversed, + // while receiving other RouteNotes (e.g. from other users). + rpc RouteChat(stream RouteNote) returns (stream RouteNote) {} +} + +// Points are represented as latitude-longitude pairs in the E7 representation +// (degrees multiplied by 10**7 and rounded to the nearest integer). +// Latitudes should be in the range +/- 90 degrees and longitude should be in +// the range +/- 180 degrees (inclusive). +message Point { + int32 latitude = 1; + int32 longitude = 2; +} + +// A latitude-longitude rectangle, represented as two diagonally opposite +// points "lo" and "hi". +message Rectangle { + // One corner of the rectangle. + Point lo = 1; + + // The other corner of the rectangle. + Point hi = 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; +} + +// A RouteNote is a message sent while at a given point. +message RouteNote { + // The location from which the message is sent. + Point location = 1; + + // The message to be sent. + string message = 2; +} + +// A RouteSummary is received in response to a RecordRoute rpc. +// +// It contains the number of individual points received, the number of +// detected features, and the total distance covered as the cumulative sum of +// the distance between each point. +message RouteSummary { + // The number of points received. + int32 point_count = 1; + + // The number of known features passed while traversing the route. + int32 feature_count = 2; + + // The distance covered in metres. + int32 distance = 3; + + // The duration of the traversal in seconds. + int32 elapsed_time = 4; +} \ No newline at end of file diff --git a/codelabs/grpc-rust-streaming/completed/src/client/client.rs b/codelabs/grpc-rust-streaming/completed/src/client/client.rs new file mode 100644 index 00000000..ecb9d685 --- /dev/null +++ b/codelabs/grpc-rust-streaming/completed/src/client/client.rs @@ -0,0 +1,132 @@ +use std::error::Error; +use std::time::Duration; + +use rand::rngs::ThreadRng; +use rand::Rng; +use tokio::time; +use tonic::transport::{Channel, Endpoint}; +use tonic::Request; +use protobuf::proto; + +mod grpc_pb { + // Include message code. + include!(concat!( + env!("CARGO_MANIFEST_DIR"), + "/generated/generated.rs" + )); + include!(concat!( + env!("CARGO_MANIFEST_DIR"), + "/generated/routeguide_grpc.pb.rs" + )); +} + +use grpc_pb::route_guide_client::RouteGuideClient; +use grpc_pb::{Point, Rectangle, RouteNote}; + + +async fn print_features(client: &mut RouteGuideClient) -> Result<(), Box> { + let rectangle = proto!(Rectangle { + lo: proto!(Point { + latitude: 400_000_000, + longitude: -750_000_000, + }), + hi: proto!(Point { + latitude: 420_000_000, + longitude: -730_000_000, + }), + }); + + let mut stream = client + .list_features(Request::new(rectangle)) + .await? + .into_inner(); + + while let Some(feature) = stream.message().await? { + println!("FEATURE: Name = \"{}\", Lat = {}, Lon = {}", + feature.name(), + feature.location().latitude(), + feature.location().longitude()); + } + Ok(()) +} + +async fn run_record_route(client: &mut RouteGuideClient) -> Result<(), Box> { + let mut rng = rand::rng(); + let point_count: i32 = rng.random_range(2..100); + + let mut points = vec![]; + for _ in 0..=point_count { + points.push(random_point(&mut rng)) + } + + println!("Traversing {} points", points.len()); + let request = Request::new(tokio_stream::iter(points)); + + match client.record_route(request).await { + Ok(response) => { + let response = response.into_inner(); + println!("SUMMARY: Feature Count = {}, Distance = {}", response.feature_count(), response.distance())}, + Err(e) => println!("something went wrong: {e:?}"), + } + + Ok(()) +} + +async fn run_route_chat(client: &mut RouteGuideClient) -> Result<(), Box> { + let start = time::Instant::now(); + let outbound = async_stream::stream! { + let mut interval = time::interval(Duration::from_secs(1)); + loop { + let time = interval.tick().await; + let elapsed = time.duration_since(start); + let note = proto!(RouteNote { + location: proto!(Point { + latitude: 409146138 + elapsed.as_secs() as i32, + longitude: -746188906, + }), + message: format!("at {elapsed:?}"), + }); + yield note; + } + }; + let response = client.route_chat(Request::new(outbound)).await?; + let mut inbound = response.into_inner(); + while let Some(note) = inbound.message().await? { + println!("Note: Latitude = {}, Longitude = {}, Message = \"{}\"", + note.location().latitude(), + note.location().longitude(), + note.message()); + } + Ok(()) +} + +#[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!("\n*** SERVER STREAMING ***"); + print_features(&mut client).await?; + + println!("\n*** CLIENT STREAMING ***"); + run_record_route(&mut client).await?; + + println!("\n*** BIDIRECTIONAL STREAMING ***"); + run_route_chat(&mut client).await?; + + Ok(()) +} + +fn random_point(rng: &mut ThreadRng) -> Point { + let latitude = (rng.random_range(0..180) - 90) * 10_000_000; + let longitude = (rng.random_range(0..360) - 180) * 10_000_000; + proto!(Point { + latitude: latitude, + longitude: longitude + }) +} + diff --git a/codelabs/grpc-rust-streaming/completed/src/data/route_guide_db.json b/codelabs/grpc-rust-streaming/completed/src/data/route_guide_db.json new file mode 100644 index 00000000..732f0997 --- /dev/null +++ b/codelabs/grpc-rust-streaming/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-streaming/completed/src/server/server.rs b/codelabs/grpc-rust-streaming/completed/src/server/server.rs new file mode 100644 index 00000000..957192eb --- /dev/null +++ b/codelabs/grpc-rust-streaming/completed/src/server/server.rs @@ -0,0 +1,218 @@ +use std::collections::HashMap; +use std::pin::Pin; +use std::sync::Arc; +use std::time::Instant; + +use tokio::sync::mpsc; +use tokio_stream::{wrappers::ReceiverStream, Stream, StreamExt}; +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" + )); +} + +#[derive(Debug, Deserialize)] +struct JsonFeature { + location: Location, + name: String, +} + +#[derive(Debug, Deserialize)] +struct Location { + latitude: i32, + longitude: i32, +} + +pub use grpc_pb::{ + route_guide_server::{RouteGuideServer, RouteGuide}, + Point, Feature, Rectangle, RouteNote, RouteSummary +}; + +#[derive(Debug)] +pub struct RouteGuideService { + features: Arc>, +} + +type ListFeaturesStream = Pin> + Send + 'static>>; +type RouteChatStream = Pin> + Send + 'static>>; + +#[tonic::async_trait] +impl RouteGuide for RouteGuideService { + + async fn list_features( + &self, + request: Request, + ) -> Result, Status> { + println!("ListFeatures = {:?}", request); + + let (tx, rx) = mpsc::channel(4); + let features = self.features.clone(); + + tokio::spawn(async move { + for feature in &features[..] { + if in_range(&feature.location().to_owned(), request.get_ref()) { + println!(" => send {feature:?}"); + tx.send(Ok(feature.clone())).await.unwrap(); + } + } + println!(" /// done sending"); + }); + + let output_stream = ReceiverStream::new(rx); + Ok(Response::new(Box::pin(output_stream))) + } + + async fn record_route( + &self, + request: Request>, + ) -> Result, Status> { + println!("RecordRoute"); + let mut stream = request.into_inner(); + let mut summary = RouteSummary::default(); + let mut last_point = None; + let now = Instant::now(); + + while let Some(point) = stream.next().await { + let point = point?; + println!(" ==> Point = {point:?}"); + + // Increment the point count + summary.set_point_count(summary.point_count() + 1); + + // Find features + for feature in &self.features[..] { + if feature.location().latitude() == point.latitude() { + if feature.location().longitude() == point.longitude(){ + summary.set_feature_count(summary.feature_count() + 1); + } + } + } + + // Calculate the distance + if let Some(ref last_point) = last_point { + let new_dist = summary.distance() + calc_distance(last_point, &point); + summary.set_distance(new_dist); + } + last_point = Some(point); + } + summary.set_elapsed_time(now.elapsed().as_secs() as i32); + Ok(Response::new(summary)) + } + + async fn route_chat( + &self, + request: Request>, + ) -> Result, Status> { + println!("RouteChat"); + + let mut notes: HashMap<(i32, i32), Vec> = HashMap::new(); + let mut stream = request.into_inner(); + + let output = async_stream::try_stream! { + while let Some(note) = stream.next().await { + let note = note?; + let location = note.location(); + let key = (location.latitude(), location.longitude()); + let location_notes = notes.entry(key).or_insert(vec![]); + location_notes.push(note); + for note in location_notes { + yield note.clone(); + } + } + }; + Ok(Response::new(Box::pin(output))) + } +} + +#[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(()) +} + +fn in_range(point: &Point, rect: &Rectangle) -> bool { + use std::cmp; + + let lo = rect.lo(); + let hi = rect.hi(); + + let left = cmp::min(lo.longitude(), hi.longitude()); + let right = cmp::max(lo.longitude(), hi.longitude()); + let top = cmp::max(lo.latitude(), hi.latitude()); + let bottom = cmp::min(lo.latitude(), hi.latitude()); + + point.longitude() >= left + && point.longitude() <= right + && point.latitude() >= bottom + && point.latitude() <= top +} + +/// Calculates the distance between two points using the "haversine" formula. +/// This code was taken from http://www.movable-type.co.uk/scripts/latlong.html. +fn calc_distance(p1: &Point, p2: &Point) -> i32 { + const CORD_FACTOR: f64 = 1e7; + const R: f64 = 6_371_000.0; // meters + + let lat1 = p1.latitude() as f64 / CORD_FACTOR; + let lat2 = p2.latitude() as f64 / CORD_FACTOR; + let lng1 = p1.longitude() as f64 / CORD_FACTOR; + let lng2 = p2.longitude() as f64 / CORD_FACTOR; + + let lat_rad1 = lat1.to_radians(); + let lat_rad2 = lat2.to_radians(); + + let delta_lat = (lat2 - lat1).to_radians(); + let delta_lng = (lng2 - lng1).to_radians(); + + let a = (delta_lat / 2f64).sin() * (delta_lat / 2f64).sin() + + (lat_rad1).cos() * (lat_rad2).cos() * (delta_lng / 2f64).sin() * (delta_lng / 2f64).sin(); + + let c = 2f64 * a.sqrt().atan2((1f64 - a).sqrt()); + + (R * c) as 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-streaming/start_here/Cargo.toml b/codelabs/grpc-rust-streaming/start_here/Cargo.toml new file mode 100644 index 00000000..3e4015b2 --- /dev/null +++ b/codelabs/grpc-rust-streaming/start_here/Cargo.toml @@ -0,0 +1,76 @@ +[package] +authors = ["Lucio Franco "] +edition = "2021" +license = "MIT" +name = "examples" + +[[bin]] +name = "routeguide-server" +path = "src/server/server.rs" +required-features = ["routeguide"] + +[[bin]] +name = "routeguide-client" +path = "src/client/client.rs" +required-features = ["routeguide"] + +[features] +gcp = ["dep:prost-types", "tonic/tls-ring"] +routeguide = ["dep:async-stream", "dep:tokio-stream", "dep:rand", "dep:serde", "dep:serde_json"] +reflection = ["dep:tonic-reflection"] +autoreload = ["dep:tokio-stream", "tokio-stream?/net", "dep:listenfd"] +health = ["dep:tonic-health"] +grpc-web = ["dep:tonic-web", "dep:bytes", "dep:http", "dep:hyper", "dep:hyper-util", "dep:tracing-subscriber", "dep:tower", "dep:tower-http", "tower-http?/cors"] +tracing = ["dep:tracing", "dep:tracing-subscriber"] +uds = ["dep:tokio-stream", "tokio-stream?/net", "dep:tower", "dep:hyper", "dep:hyper-util"] +streaming = ["dep:tokio-stream", "dep:h2"] +mock = ["dep:tokio-stream", "dep:tower", "dep:hyper-util"] +tower = ["dep:tower", "dep:http"] +json-codec = ["dep:serde", "dep:serde_json", "dep:bytes"] +compression = ["tonic/gzip"] +tls = ["tonic/tls-ring"] +tls-rustls = ["dep:http", "dep:hyper", "dep:hyper-util", "dep:hyper-rustls", "dep:tower", "tower-http/util", "tower-http/add-extension", "dep:tokio-rustls"] +tls-client-auth = ["tonic/tls-ring"] +types = ["dep:tonic-types"] +h2c = ["dep:hyper", "dep:tower", "dep:http", "dep:hyper-util"] +cancellation = ["dep:tokio-util"] + +full = ["gcp", "routeguide", "reflection", "autoreload", "health", "grpc-web", "tracing", "uds", "streaming", "mock", "tower", "json-codec", "compression", "tls", "tls-rustls", "tls-client-auth", "types", "cancellation", "h2c"] +default = ["full"] + +[dependencies] +# Common dependencies +tokio = { version = "1.0", features = ["rt-multi-thread", "macros"] } +prost = "0.14" +tonic = { git = "https://github.com/arjan-bal/tonic.git", branch = "grpc-codegen" } +tonic-protobuf = {git = "https://github.com/arjan-bal/tonic.git", branch = "grpc-codegen", package = "tonic-protobuf" } +grpc = {git = "https://github.com/arjan-bal/tonic.git", branch = "grpc-codegen", 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 } +tonic-web = { git = "https://github.com/arjan-bal/tonic.git", branch = "grpc-codegen", package = "tonic-web", optional = true } +tonic-health = { git = "https://github.com/arjan-bal/tonic.git", branch = "grpc-codegen", package = "tonic-health", optional = true } +tonic-reflection = { git = "https://github.com/arjan-bal/tonic.git", branch = "grpc-codegen", package = "tonic-reflection", optional = true } +tonic-types = { git = "https://github.com/arjan-bal/tonic.git", branch = "grpc-codegen", package = "tonic-types", 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"} +listenfd = { version = "1.0", optional = true } +bytes = { version = "1", optional = true } +h2 = { version = "0.4", optional = true } +tracing = { version = "0.1.16", optional = true } +tracing-subscriber = { version = "0.3", features = ["tracing-log", "fmt"], optional = true } + +[build-dependencies] +protobuf-codegen = { version = "4.31.1-release"} \ No newline at end of file diff --git a/codelabs/grpc-rust-streaming/start_here/build.rs b/codelabs/grpc-rust-streaming/start_here/build.rs new file mode 100644 index 00000000..11854630 --- /dev/null +++ b/codelabs/grpc-rust-streaming/start_here/build.rs @@ -0,0 +1,8 @@ +fn main() { + protobuf_codegen::CodeGen::new() + .include("proto") + .inputs(["routeguide.proto"]) + .output_dir("generated") + .compile_only() + .unwrap(); +} \ No newline at end of file diff --git a/codelabs/grpc-rust-streaming/start_here/generated/crate_mapping.txt b/codelabs/grpc-rust-streaming/start_here/generated/crate_mapping.txt new file mode 100644 index 00000000..e69de29b diff --git a/codelabs/grpc-rust-streaming/start_here/generated/generated.rs b/codelabs/grpc-rust-streaming/start_here/generated/generated.rs new file mode 100644 index 00000000..3bd5dfb0 --- /dev/null +++ b/codelabs/grpc-rust-streaming/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-streaming/start_here/generated/routeguide.u.pb.rs b/codelabs/grpc-rust-streaming/start_here/generated/routeguide.u.pb.rs new file mode 100644 index 00000000..b212c947 --- /dev/null +++ b/codelabs/grpc-rust-streaming/start_here/generated/routeguide.u.pb.rs @@ -0,0 +1,4686 @@ +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 Rectangle { + inner: ::protobuf::__internal::runtime::MessageInner, +} +impl ::protobuf::Message for Rectangle {} +impl ::std::default::Default for Rectangle { + fn default() -> Self { + Self::new() + } +} +impl ::protobuf::Parse for Rectangle { + fn parse(serialized: &[u8]) -> ::std::result::Result { + Self::parse(serialized) + } +} +impl ::std::fmt::Debug for Rectangle { + 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 Rectangle { + 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 Rectangle { + 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 Rectangle { + 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 Rectangle { + fn serialize(&self) -> ::std::result::Result, ::protobuf::SerializeError> { + ::protobuf::AsView::as_view(self).serialize() + } +} +impl ::protobuf::Clear for Rectangle { + fn clear(&mut self) { + let mut m = self.as_mut(); + ::protobuf::Clear::clear(&mut m) + } +} +impl ::protobuf::ClearAndParse for Rectangle { + 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 Rectangle {} +unsafe impl Send for Rectangle {} +impl ::protobuf::Proxied for Rectangle { + type View<'msg> = RectangleView<'msg>; +} +impl ::protobuf::__internal::SealedInternal for Rectangle {} +impl ::protobuf::MutProxied for Rectangle { + type Mut<'msg> = RectangleMut<'msg>; +} +#[derive(Copy, Clone)] +#[allow(dead_code)] +pub struct RectangleView<'msg> { + msg: ::protobuf::__internal::runtime::RawMessage, + _phantom: ::std::marker::PhantomData<&'msg ()>, +} +impl<'msg> ::protobuf::__internal::SealedInternal for RectangleView<'msg> {} +impl<'msg> ::protobuf::MessageView<'msg> for RectangleView<'msg> { + type Message = Rectangle; +} +impl ::std::fmt::Debug for RectangleView<'_> { + 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 RectangleView<'_> { + 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 RectangleView<'_> { + fn default() -> RectangleView<'static> { + RectangleView::new( + ::protobuf::__internal::Private, + ::protobuf::__internal::runtime::ScratchSpace::zeroed_block(), + ) + } +} +#[allow(dead_code)] +impl<'msg> RectangleView<'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) -> Rectangle { + ::protobuf::IntoProxied::into_proxied(*self, ::protobuf::__internal::Private) + } + pub fn has_lo(self) -> bool { + unsafe { + let f = ::protobuf::__internal::runtime::upb_MiniTable_GetFieldByIndex( + ::mini_table(), + 0, + ); + ::protobuf::__internal::runtime::upb_Message_HasBaseField(self.raw_msg(), f) + } + } + pub fn lo_opt(self) -> ::protobuf::Optional> { + ::protobuf::Optional::new(self.lo(), self.has_lo()) + } + pub fn lo(self) -> super::PointView<'msg> { + let submsg = unsafe { + let f = ::protobuf::__internal::runtime::upb_MiniTable_GetFieldByIndex( + ::mini_table(), + 0, + ); + ::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 has_hi(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 hi_opt(self) -> ::protobuf::Optional> { + ::protobuf::Optional::new(self.hi(), self.has_hi()) + } + pub fn hi(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 RectangleView<'_> {} +unsafe impl Send for RectangleView<'_> {} +impl<'msg> ::protobuf::Proxy<'msg> for RectangleView<'msg> {} +impl<'msg> ::protobuf::ViewProxy<'msg> for RectangleView<'msg> {} +impl<'msg> ::protobuf::AsView for RectangleView<'msg> { + type Proxied = Rectangle; + fn as_view(&self) -> ::protobuf::View<'msg, Rectangle> { + *self + } +} +impl<'msg> ::protobuf::IntoView<'msg> for RectangleView<'msg> { + fn into_view<'shorter>(self) -> RectangleView<'shorter> + where + 'msg: 'shorter, + { + self + } +} +impl<'msg> ::protobuf::IntoProxied for RectangleView<'msg> { + fn into_proxied(self, _private: ::protobuf::__internal::Private) -> Rectangle { + let dst = Rectangle::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 RectangleMut<'msg> { + fn into_proxied(self, _private: ::protobuf::__internal::Private) -> Rectangle { + ::protobuf::IntoProxied::into_proxied( + ::protobuf::IntoView::into_view(self), + _private, + ) + } +} +unsafe impl ::protobuf::ProxiedInRepeated for Rectangle { + 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 Rectangle { + 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> { + RectangleView::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, + ) -> RectangleMut<'msg> { + RectangleMut { + 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 RectangleMut<'msg> { + inner: ::protobuf::__internal::runtime::MutatorMessageRef<'msg>, +} +impl<'msg> ::protobuf::__internal::SealedInternal for RectangleMut<'msg> {} +impl<'msg> ::protobuf::MessageMut<'msg> for RectangleMut<'msg> { + type Message = Rectangle; +} +impl ::std::fmt::Debug for RectangleMut<'_> { + 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 RectangleMut<'_> { + fn serialize(&self) -> ::std::result::Result, ::protobuf::SerializeError> { + ::protobuf::AsView::as_view(self).serialize() + } +} +impl ::protobuf::Clear for RectangleMut<'_> { + fn clear(&mut self) { + unsafe { + ::protobuf::__internal::runtime::upb_Message_Clear( + self.raw_msg(), + ::mini_table(), + ) + } + } +} +impl ::protobuf::ClearAndParse for RectangleMut<'_> { + 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 RectangleMut<'_> { + 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 RectangleMut<'_> { + 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 RectangleMut<'_> { + 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> RectangleMut<'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) -> Rectangle { + ::protobuf::AsView::as_view(self).to_owned() + } + fn arena(&self) -> &::protobuf::__internal::runtime::Arena { + self.inner.arena() + } + pub fn has_lo(&self) -> bool { + unsafe { + let f = ::protobuf::__internal::runtime::upb_MiniTable_GetFieldByIndex( + ::mini_table(), + 0, + ); + ::protobuf::__internal::runtime::upb_Message_HasBaseField(self.raw_msg(), f) + } + } + pub fn clear_lo(&mut self) { + unsafe { + let mt = ::mini_table(); + let f = ::protobuf::__internal::runtime::upb_MiniTable_GetFieldByIndex( + mt, + 0, + ); + ::protobuf::__internal::runtime::upb_Message_ClearBaseField( + self.raw_msg(), + f, + ); + } + } + pub fn lo_opt(&self) -> ::protobuf::Optional> { + ::protobuf::Optional::new(self.lo(), self.has_lo()) + } + pub fn lo(&self) -> super::PointView<'_> { + let submsg = unsafe { + let f = ::protobuf::__internal::runtime::upb_MiniTable_GetFieldByIndex( + ::mini_table(), + 0, + ); + ::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 lo_mut(&mut self) -> super::PointMut<'_> { + let raw_msg = unsafe { + let mt = ::mini_table(); + let f = ::protobuf::__internal::runtime::upb_MiniTable_GetFieldByIndex( + mt, + 0, + ); + ::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_lo(&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(), + 0, + ); + ::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(), + ); + } + } + pub fn has_hi(&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_hi(&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 hi_opt(&self) -> ::protobuf::Optional> { + ::protobuf::Optional::new(self.hi(), self.has_hi()) + } + pub fn hi(&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 hi_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_hi(&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 RectangleMut<'_> {} +impl<'msg> ::protobuf::Proxy<'msg> for RectangleMut<'msg> {} +impl<'msg> ::protobuf::MutProxy<'msg> for RectangleMut<'msg> {} +impl<'msg> ::protobuf::AsView for RectangleMut<'msg> { + type Proxied = Rectangle; + fn as_view(&self) -> ::protobuf::View<'_, Rectangle> { + RectangleView { + msg: self.raw_msg(), + _phantom: ::std::marker::PhantomData, + } + } +} +impl<'msg> ::protobuf::IntoView<'msg> for RectangleMut<'msg> { + fn into_view<'shorter>(self) -> ::protobuf::View<'shorter, Rectangle> + where + 'msg: 'shorter, + { + RectangleView { + msg: self.raw_msg(), + _phantom: ::std::marker::PhantomData, + } + } +} +impl<'msg> ::protobuf::AsMut for RectangleMut<'msg> { + type MutProxied = Rectangle; + fn as_mut(&mut self) -> RectangleMut<'msg> { + RectangleMut { inner: self.inner } + } +} +impl<'msg> ::protobuf::IntoMut<'msg> for RectangleMut<'msg> { + fn into_mut<'shorter>(self) -> RectangleMut<'shorter> + where + 'msg: 'shorter, + { + self + } +} +#[allow(dead_code)] +impl Rectangle { + 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) -> RectangleView { + RectangleView::new(::protobuf::__internal::Private, self.inner.msg) + } + pub fn as_mut(&mut self) -> RectangleMut { + RectangleMut::new(::protobuf::__internal::Private, &mut self.inner) + } + pub fn has_lo(&self) -> bool { + unsafe { + let f = ::protobuf::__internal::runtime::upb_MiniTable_GetFieldByIndex( + ::mini_table(), + 0, + ); + ::protobuf::__internal::runtime::upb_Message_HasBaseField(self.raw_msg(), f) + } + } + pub fn clear_lo(&mut self) { + unsafe { + let mt = ::mini_table(); + let f = ::protobuf::__internal::runtime::upb_MiniTable_GetFieldByIndex( + mt, + 0, + ); + ::protobuf::__internal::runtime::upb_Message_ClearBaseField( + self.raw_msg(), + f, + ); + } + } + pub fn lo_opt(&self) -> ::protobuf::Optional> { + ::protobuf::Optional::new(self.lo(), self.has_lo()) + } + pub fn lo(&self) -> super::PointView<'_> { + let submsg = unsafe { + let f = ::protobuf::__internal::runtime::upb_MiniTable_GetFieldByIndex( + ::mini_table(), + 0, + ); + ::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 lo_mut(&mut self) -> super::PointMut<'_> { + let raw_msg = unsafe { + let mt = ::mini_table(); + let f = ::protobuf::__internal::runtime::upb_MiniTable_GetFieldByIndex( + mt, + 0, + ); + ::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_lo(&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(), + 0, + ); + ::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(), + ); + } + } + pub fn has_hi(&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_hi(&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 hi_opt(&self) -> ::protobuf::Optional> { + ::protobuf::Optional::new(self.hi(), self.has_hi()) + } + pub fn hi(&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 hi_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_hi(&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 Rectangle { + fn drop(&mut self) {} +} +impl ::std::clone::Clone for Rectangle { + fn clone(&self) -> Self { + self.as_view().to_owned() + } +} +impl ::protobuf::AsView for Rectangle { + type Proxied = Self; + fn as_view(&self) -> RectangleView { + self.as_view() + } +} +impl ::protobuf::AsMut for Rectangle { + type MutProxied = Self; + fn as_mut(&mut self) -> RectangleMut { + self.as_mut() + } +} +unsafe impl ::protobuf::__internal::runtime::AssociatedMiniTable for Rectangle { + #[inline(always)] + fn mini_table() -> *const ::protobuf::__internal::runtime::upb_MiniTable { + #[allow(unused_unsafe)] + unsafe { ::std::ptr::addr_of!(routeguide__Rectangle_msg_init) } + } +} +unsafe impl ::protobuf::__internal::runtime::AssociatedMiniTable for RectangleView<'_> { + #[inline(always)] + fn mini_table() -> *const ::protobuf::__internal::runtime::upb_MiniTable { + #[allow(unused_unsafe)] + unsafe { ::std::ptr::addr_of!(routeguide__Rectangle_msg_init) } + } +} +unsafe impl ::protobuf::__internal::runtime::AssociatedMiniTable for RectangleMut<'_> { + #[inline(always)] + fn mini_table() -> *const ::protobuf::__internal::runtime::upb_MiniTable { + #[allow(unused_unsafe)] + unsafe { ::std::ptr::addr_of!(routeguide__Rectangle_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__Rectangle_msg_init: ::protobuf::__internal::runtime::upb_MiniTable; +} +impl ::protobuf::OwnedMessageInterop for Rectangle {} +impl<'a> ::protobuf::MessageMutInterop<'a> for RectangleMut<'a> {} +impl<'a> ::protobuf::MessageViewInterop<'a> for RectangleView<'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 Rectangle { + 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 RectangleMut<'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 RectangleView<'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, + ) + } + } +} +#[allow(non_camel_case_types)] +pub struct RouteNote { + inner: ::protobuf::__internal::runtime::MessageInner, +} +impl ::protobuf::Message for RouteNote {} +impl ::std::default::Default for RouteNote { + fn default() -> Self { + Self::new() + } +} +impl ::protobuf::Parse for RouteNote { + fn parse(serialized: &[u8]) -> ::std::result::Result { + Self::parse(serialized) + } +} +impl ::std::fmt::Debug for RouteNote { + 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 RouteNote { + 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 RouteNote { + 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 RouteNote { + 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 RouteNote { + fn serialize(&self) -> ::std::result::Result, ::protobuf::SerializeError> { + ::protobuf::AsView::as_view(self).serialize() + } +} +impl ::protobuf::Clear for RouteNote { + fn clear(&mut self) { + let mut m = self.as_mut(); + ::protobuf::Clear::clear(&mut m) + } +} +impl ::protobuf::ClearAndParse for RouteNote { + 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 RouteNote {} +unsafe impl Send for RouteNote {} +impl ::protobuf::Proxied for RouteNote { + type View<'msg> = RouteNoteView<'msg>; +} +impl ::protobuf::__internal::SealedInternal for RouteNote {} +impl ::protobuf::MutProxied for RouteNote { + type Mut<'msg> = RouteNoteMut<'msg>; +} +#[derive(Copy, Clone)] +#[allow(dead_code)] +pub struct RouteNoteView<'msg> { + msg: ::protobuf::__internal::runtime::RawMessage, + _phantom: ::std::marker::PhantomData<&'msg ()>, +} +impl<'msg> ::protobuf::__internal::SealedInternal for RouteNoteView<'msg> {} +impl<'msg> ::protobuf::MessageView<'msg> for RouteNoteView<'msg> { + type Message = RouteNote; +} +impl ::std::fmt::Debug for RouteNoteView<'_> { + 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 RouteNoteView<'_> { + 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 RouteNoteView<'_> { + fn default() -> RouteNoteView<'static> { + RouteNoteView::new( + ::protobuf::__internal::Private, + ::protobuf::__internal::runtime::ScratchSpace::zeroed_block(), + ) + } +} +#[allow(dead_code)] +impl<'msg> RouteNoteView<'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) -> RouteNote { + ::protobuf::IntoProxied::into_proxied(*self, ::protobuf::__internal::Private) + } + pub fn has_location(self) -> bool { + unsafe { + let f = ::protobuf::__internal::runtime::upb_MiniTable_GetFieldByIndex( + ::mini_table(), + 0, + ); + ::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(), + 0, + ); + ::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 message(self) -> ::protobuf::View<'msg, ::protobuf::ProtoString> { + let str_view = unsafe { + let f = ::protobuf::__internal::runtime::upb_MiniTable_GetFieldByIndex( + ::mini_table(), + 1, + ); + ::protobuf::__internal::runtime::upb_Message_GetString( + self.raw_msg(), + f, + (b"").into(), + ) + }; + unsafe { ::protobuf::ProtoStr::from_utf8_unchecked(str_view.as_ref()) } + } +} +unsafe impl Sync for RouteNoteView<'_> {} +unsafe impl Send for RouteNoteView<'_> {} +impl<'msg> ::protobuf::Proxy<'msg> for RouteNoteView<'msg> {} +impl<'msg> ::protobuf::ViewProxy<'msg> for RouteNoteView<'msg> {} +impl<'msg> ::protobuf::AsView for RouteNoteView<'msg> { + type Proxied = RouteNote; + fn as_view(&self) -> ::protobuf::View<'msg, RouteNote> { + *self + } +} +impl<'msg> ::protobuf::IntoView<'msg> for RouteNoteView<'msg> { + fn into_view<'shorter>(self) -> RouteNoteView<'shorter> + where + 'msg: 'shorter, + { + self + } +} +impl<'msg> ::protobuf::IntoProxied for RouteNoteView<'msg> { + fn into_proxied(self, _private: ::protobuf::__internal::Private) -> RouteNote { + let dst = RouteNote::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 RouteNoteMut<'msg> { + fn into_proxied(self, _private: ::protobuf::__internal::Private) -> RouteNote { + ::protobuf::IntoProxied::into_proxied( + ::protobuf::IntoView::into_view(self), + _private, + ) + } +} +unsafe impl ::protobuf::ProxiedInRepeated for RouteNote { + 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 RouteNote { + 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> { + RouteNoteView::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, + ) -> RouteNoteMut<'msg> { + RouteNoteMut { + 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 RouteNoteMut<'msg> { + inner: ::protobuf::__internal::runtime::MutatorMessageRef<'msg>, +} +impl<'msg> ::protobuf::__internal::SealedInternal for RouteNoteMut<'msg> {} +impl<'msg> ::protobuf::MessageMut<'msg> for RouteNoteMut<'msg> { + type Message = RouteNote; +} +impl ::std::fmt::Debug for RouteNoteMut<'_> { + 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 RouteNoteMut<'_> { + fn serialize(&self) -> ::std::result::Result, ::protobuf::SerializeError> { + ::protobuf::AsView::as_view(self).serialize() + } +} +impl ::protobuf::Clear for RouteNoteMut<'_> { + fn clear(&mut self) { + unsafe { + ::protobuf::__internal::runtime::upb_Message_Clear( + self.raw_msg(), + ::mini_table(), + ) + } + } +} +impl ::protobuf::ClearAndParse for RouteNoteMut<'_> { + 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 RouteNoteMut<'_> { + 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 RouteNoteMut<'_> { + 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 RouteNoteMut<'_> { + 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> RouteNoteMut<'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) -> RouteNote { + ::protobuf::AsView::as_view(self).to_owned() + } + fn arena(&self) -> &::protobuf::__internal::runtime::Arena { + self.inner.arena() + } + pub fn has_location(&self) -> bool { + unsafe { + let f = ::protobuf::__internal::runtime::upb_MiniTable_GetFieldByIndex( + ::mini_table(), + 0, + ); + ::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, + 0, + ); + ::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(), + 0, + ); + ::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, + 0, + ); + ::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(), + 0, + ); + ::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(), + ); + } + } + pub fn message(&self) -> ::protobuf::View<'_, ::protobuf::ProtoString> { + let str_view = unsafe { + let f = ::protobuf::__internal::runtime::upb_MiniTable_GetFieldByIndex( + ::mini_table(), + 1, + ); + ::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_message( + &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(), + 1, + ); + ::protobuf::__internal::runtime::upb_Message_SetBaseFieldString( + self.as_mutator_message_ref(::protobuf::__internal::Private).msg(), + f, + view, + ); + } + } +} +unsafe impl Sync for RouteNoteMut<'_> {} +impl<'msg> ::protobuf::Proxy<'msg> for RouteNoteMut<'msg> {} +impl<'msg> ::protobuf::MutProxy<'msg> for RouteNoteMut<'msg> {} +impl<'msg> ::protobuf::AsView for RouteNoteMut<'msg> { + type Proxied = RouteNote; + fn as_view(&self) -> ::protobuf::View<'_, RouteNote> { + RouteNoteView { + msg: self.raw_msg(), + _phantom: ::std::marker::PhantomData, + } + } +} +impl<'msg> ::protobuf::IntoView<'msg> for RouteNoteMut<'msg> { + fn into_view<'shorter>(self) -> ::protobuf::View<'shorter, RouteNote> + where + 'msg: 'shorter, + { + RouteNoteView { + msg: self.raw_msg(), + _phantom: ::std::marker::PhantomData, + } + } +} +impl<'msg> ::protobuf::AsMut for RouteNoteMut<'msg> { + type MutProxied = RouteNote; + fn as_mut(&mut self) -> RouteNoteMut<'msg> { + RouteNoteMut { inner: self.inner } + } +} +impl<'msg> ::protobuf::IntoMut<'msg> for RouteNoteMut<'msg> { + fn into_mut<'shorter>(self) -> RouteNoteMut<'shorter> + where + 'msg: 'shorter, + { + self + } +} +#[allow(dead_code)] +impl RouteNote { + 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) -> RouteNoteView { + RouteNoteView::new(::protobuf::__internal::Private, self.inner.msg) + } + pub fn as_mut(&mut self) -> RouteNoteMut { + RouteNoteMut::new(::protobuf::__internal::Private, &mut self.inner) + } + pub fn has_location(&self) -> bool { + unsafe { + let f = ::protobuf::__internal::runtime::upb_MiniTable_GetFieldByIndex( + ::mini_table(), + 0, + ); + ::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, + 0, + ); + ::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(), + 0, + ); + ::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, + 0, + ); + ::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(), + 0, + ); + ::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(), + ); + } + } + pub fn message(&self) -> ::protobuf::View<'_, ::protobuf::ProtoString> { + let str_view = unsafe { + let f = ::protobuf::__internal::runtime::upb_MiniTable_GetFieldByIndex( + ::mini_table(), + 1, + ); + ::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_message( + &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(), + 1, + ); + ::protobuf::__internal::runtime::upb_Message_SetBaseFieldString( + self.as_mutator_message_ref(::protobuf::__internal::Private).msg(), + f, + view, + ); + } + } +} +impl ::std::ops::Drop for RouteNote { + fn drop(&mut self) {} +} +impl ::std::clone::Clone for RouteNote { + fn clone(&self) -> Self { + self.as_view().to_owned() + } +} +impl ::protobuf::AsView for RouteNote { + type Proxied = Self; + fn as_view(&self) -> RouteNoteView { + self.as_view() + } +} +impl ::protobuf::AsMut for RouteNote { + type MutProxied = Self; + fn as_mut(&mut self) -> RouteNoteMut { + self.as_mut() + } +} +unsafe impl ::protobuf::__internal::runtime::AssociatedMiniTable for RouteNote { + #[inline(always)] + fn mini_table() -> *const ::protobuf::__internal::runtime::upb_MiniTable { + #[allow(unused_unsafe)] + unsafe { ::std::ptr::addr_of!(routeguide__RouteNote_msg_init) } + } +} +unsafe impl ::protobuf::__internal::runtime::AssociatedMiniTable for RouteNoteView<'_> { + #[inline(always)] + fn mini_table() -> *const ::protobuf::__internal::runtime::upb_MiniTable { + #[allow(unused_unsafe)] + unsafe { ::std::ptr::addr_of!(routeguide__RouteNote_msg_init) } + } +} +unsafe impl ::protobuf::__internal::runtime::AssociatedMiniTable for RouteNoteMut<'_> { + #[inline(always)] + fn mini_table() -> *const ::protobuf::__internal::runtime::upb_MiniTable { + #[allow(unused_unsafe)] + unsafe { ::std::ptr::addr_of!(routeguide__RouteNote_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__RouteNote_msg_init: ::protobuf::__internal::runtime::upb_MiniTable; +} +impl ::protobuf::OwnedMessageInterop for RouteNote {} +impl<'a> ::protobuf::MessageMutInterop<'a> for RouteNoteMut<'a> {} +impl<'a> ::protobuf::MessageViewInterop<'a> for RouteNoteView<'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 RouteNote { + 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 RouteNoteMut<'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 RouteNoteView<'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 RouteSummary { + inner: ::protobuf::__internal::runtime::MessageInner, +} +impl ::protobuf::Message for RouteSummary {} +impl ::std::default::Default for RouteSummary { + fn default() -> Self { + Self::new() + } +} +impl ::protobuf::Parse for RouteSummary { + fn parse(serialized: &[u8]) -> ::std::result::Result { + Self::parse(serialized) + } +} +impl ::std::fmt::Debug for RouteSummary { + 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 RouteSummary { + 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 RouteSummary { + 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 RouteSummary { + 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 RouteSummary { + fn serialize(&self) -> ::std::result::Result, ::protobuf::SerializeError> { + ::protobuf::AsView::as_view(self).serialize() + } +} +impl ::protobuf::Clear for RouteSummary { + fn clear(&mut self) { + let mut m = self.as_mut(); + ::protobuf::Clear::clear(&mut m) + } +} +impl ::protobuf::ClearAndParse for RouteSummary { + 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 RouteSummary {} +unsafe impl Send for RouteSummary {} +impl ::protobuf::Proxied for RouteSummary { + type View<'msg> = RouteSummaryView<'msg>; +} +impl ::protobuf::__internal::SealedInternal for RouteSummary {} +impl ::protobuf::MutProxied for RouteSummary { + type Mut<'msg> = RouteSummaryMut<'msg>; +} +#[derive(Copy, Clone)] +#[allow(dead_code)] +pub struct RouteSummaryView<'msg> { + msg: ::protobuf::__internal::runtime::RawMessage, + _phantom: ::std::marker::PhantomData<&'msg ()>, +} +impl<'msg> ::protobuf::__internal::SealedInternal for RouteSummaryView<'msg> {} +impl<'msg> ::protobuf::MessageView<'msg> for RouteSummaryView<'msg> { + type Message = RouteSummary; +} +impl ::std::fmt::Debug for RouteSummaryView<'_> { + 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 RouteSummaryView<'_> { + 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 RouteSummaryView<'_> { + fn default() -> RouteSummaryView<'static> { + RouteSummaryView::new( + ::protobuf::__internal::Private, + ::protobuf::__internal::runtime::ScratchSpace::zeroed_block(), + ) + } +} +#[allow(dead_code)] +impl<'msg> RouteSummaryView<'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) -> RouteSummary { + ::protobuf::IntoProxied::into_proxied(*self, ::protobuf::__internal::Private) + } + pub fn point_count(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 feature_count(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 distance(self) -> i32 { + unsafe { + let mt = ::mini_table(); + let f = ::protobuf::__internal::runtime::upb_MiniTable_GetFieldByIndex( + mt, + 2, + ); + ::protobuf::__internal::runtime::upb_Message_GetInt32( + self.raw_msg(), + f, + (0i32).into(), + ) + .try_into() + .unwrap() + } + } + pub fn elapsed_time(self) -> i32 { + unsafe { + let mt = ::mini_table(); + let f = ::protobuf::__internal::runtime::upb_MiniTable_GetFieldByIndex( + mt, + 3, + ); + ::protobuf::__internal::runtime::upb_Message_GetInt32( + self.raw_msg(), + f, + (0i32).into(), + ) + .try_into() + .unwrap() + } + } +} +unsafe impl Sync for RouteSummaryView<'_> {} +unsafe impl Send for RouteSummaryView<'_> {} +impl<'msg> ::protobuf::Proxy<'msg> for RouteSummaryView<'msg> {} +impl<'msg> ::protobuf::ViewProxy<'msg> for RouteSummaryView<'msg> {} +impl<'msg> ::protobuf::AsView for RouteSummaryView<'msg> { + type Proxied = RouteSummary; + fn as_view(&self) -> ::protobuf::View<'msg, RouteSummary> { + *self + } +} +impl<'msg> ::protobuf::IntoView<'msg> for RouteSummaryView<'msg> { + fn into_view<'shorter>(self) -> RouteSummaryView<'shorter> + where + 'msg: 'shorter, + { + self + } +} +impl<'msg> ::protobuf::IntoProxied for RouteSummaryView<'msg> { + fn into_proxied(self, _private: ::protobuf::__internal::Private) -> RouteSummary { + let dst = RouteSummary::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 RouteSummaryMut<'msg> { + fn into_proxied(self, _private: ::protobuf::__internal::Private) -> RouteSummary { + ::protobuf::IntoProxied::into_proxied( + ::protobuf::IntoView::into_view(self), + _private, + ) + } +} +unsafe impl ::protobuf::ProxiedInRepeated for RouteSummary { + 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 RouteSummary { + 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> { + RouteSummaryView::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, + ) -> RouteSummaryMut<'msg> { + RouteSummaryMut { + 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 RouteSummaryMut<'msg> { + inner: ::protobuf::__internal::runtime::MutatorMessageRef<'msg>, +} +impl<'msg> ::protobuf::__internal::SealedInternal for RouteSummaryMut<'msg> {} +impl<'msg> ::protobuf::MessageMut<'msg> for RouteSummaryMut<'msg> { + type Message = RouteSummary; +} +impl ::std::fmt::Debug for RouteSummaryMut<'_> { + 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 RouteSummaryMut<'_> { + fn serialize(&self) -> ::std::result::Result, ::protobuf::SerializeError> { + ::protobuf::AsView::as_view(self).serialize() + } +} +impl ::protobuf::Clear for RouteSummaryMut<'_> { + fn clear(&mut self) { + unsafe { + ::protobuf::__internal::runtime::upb_Message_Clear( + self.raw_msg(), + ::mini_table(), + ) + } + } +} +impl ::protobuf::ClearAndParse for RouteSummaryMut<'_> { + 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 RouteSummaryMut<'_> { + 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 RouteSummaryMut<'_> { + 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 RouteSummaryMut<'_> { + 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> RouteSummaryMut<'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) -> RouteSummary { + ::protobuf::AsView::as_view(self).to_owned() + } + fn arena(&self) -> &::protobuf::__internal::runtime::Arena { + self.inner.arena() + } + pub fn point_count(&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_point_count(&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 feature_count(&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_feature_count(&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(), + ); + } + } + pub fn distance(&self) -> i32 { + unsafe { + let mt = ::mini_table(); + let f = ::protobuf::__internal::runtime::upb_MiniTable_GetFieldByIndex( + mt, + 2, + ); + ::protobuf::__internal::runtime::upb_Message_GetInt32( + self.raw_msg(), + f, + (0i32).into(), + ) + .try_into() + .unwrap() + } + } + pub fn set_distance(&mut self, val: i32) { + unsafe { + let mt = ::mini_table(); + let f = ::protobuf::__internal::runtime::upb_MiniTable_GetFieldByIndex( + mt, + 2, + ); + ::protobuf::__internal::runtime::upb_Message_SetBaseFieldInt32( + self.raw_msg(), + f, + val.into(), + ); + } + } + pub fn elapsed_time(&self) -> i32 { + unsafe { + let mt = ::mini_table(); + let f = ::protobuf::__internal::runtime::upb_MiniTable_GetFieldByIndex( + mt, + 3, + ); + ::protobuf::__internal::runtime::upb_Message_GetInt32( + self.raw_msg(), + f, + (0i32).into(), + ) + .try_into() + .unwrap() + } + } + pub fn set_elapsed_time(&mut self, val: i32) { + unsafe { + let mt = ::mini_table(); + let f = ::protobuf::__internal::runtime::upb_MiniTable_GetFieldByIndex( + mt, + 3, + ); + ::protobuf::__internal::runtime::upb_Message_SetBaseFieldInt32( + self.raw_msg(), + f, + val.into(), + ); + } + } +} +unsafe impl Sync for RouteSummaryMut<'_> {} +impl<'msg> ::protobuf::Proxy<'msg> for RouteSummaryMut<'msg> {} +impl<'msg> ::protobuf::MutProxy<'msg> for RouteSummaryMut<'msg> {} +impl<'msg> ::protobuf::AsView for RouteSummaryMut<'msg> { + type Proxied = RouteSummary; + fn as_view(&self) -> ::protobuf::View<'_, RouteSummary> { + RouteSummaryView { + msg: self.raw_msg(), + _phantom: ::std::marker::PhantomData, + } + } +} +impl<'msg> ::protobuf::IntoView<'msg> for RouteSummaryMut<'msg> { + fn into_view<'shorter>(self) -> ::protobuf::View<'shorter, RouteSummary> + where + 'msg: 'shorter, + { + RouteSummaryView { + msg: self.raw_msg(), + _phantom: ::std::marker::PhantomData, + } + } +} +impl<'msg> ::protobuf::AsMut for RouteSummaryMut<'msg> { + type MutProxied = RouteSummary; + fn as_mut(&mut self) -> RouteSummaryMut<'msg> { + RouteSummaryMut { + inner: self.inner, + } + } +} +impl<'msg> ::protobuf::IntoMut<'msg> for RouteSummaryMut<'msg> { + fn into_mut<'shorter>(self) -> RouteSummaryMut<'shorter> + where + 'msg: 'shorter, + { + self + } +} +#[allow(dead_code)] +impl RouteSummary { + 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) -> RouteSummaryView { + RouteSummaryView::new(::protobuf::__internal::Private, self.inner.msg) + } + pub fn as_mut(&mut self) -> RouteSummaryMut { + RouteSummaryMut::new(::protobuf::__internal::Private, &mut self.inner) + } + pub fn point_count(&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_point_count(&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 feature_count(&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_feature_count(&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(), + ); + } + } + pub fn distance(&self) -> i32 { + unsafe { + let mt = ::mini_table(); + let f = ::protobuf::__internal::runtime::upb_MiniTable_GetFieldByIndex( + mt, + 2, + ); + ::protobuf::__internal::runtime::upb_Message_GetInt32( + self.raw_msg(), + f, + (0i32).into(), + ) + .try_into() + .unwrap() + } + } + pub fn set_distance(&mut self, val: i32) { + unsafe { + let mt = ::mini_table(); + let f = ::protobuf::__internal::runtime::upb_MiniTable_GetFieldByIndex( + mt, + 2, + ); + ::protobuf::__internal::runtime::upb_Message_SetBaseFieldInt32( + self.raw_msg(), + f, + val.into(), + ); + } + } + pub fn elapsed_time(&self) -> i32 { + unsafe { + let mt = ::mini_table(); + let f = ::protobuf::__internal::runtime::upb_MiniTable_GetFieldByIndex( + mt, + 3, + ); + ::protobuf::__internal::runtime::upb_Message_GetInt32( + self.raw_msg(), + f, + (0i32).into(), + ) + .try_into() + .unwrap() + } + } + pub fn set_elapsed_time(&mut self, val: i32) { + unsafe { + let mt = ::mini_table(); + let f = ::protobuf::__internal::runtime::upb_MiniTable_GetFieldByIndex( + mt, + 3, + ); + ::protobuf::__internal::runtime::upb_Message_SetBaseFieldInt32( + self.raw_msg(), + f, + val.into(), + ); + } + } +} +impl ::std::ops::Drop for RouteSummary { + fn drop(&mut self) {} +} +impl ::std::clone::Clone for RouteSummary { + fn clone(&self) -> Self { + self.as_view().to_owned() + } +} +impl ::protobuf::AsView for RouteSummary { + type Proxied = Self; + fn as_view(&self) -> RouteSummaryView { + self.as_view() + } +} +impl ::protobuf::AsMut for RouteSummary { + type MutProxied = Self; + fn as_mut(&mut self) -> RouteSummaryMut { + self.as_mut() + } +} +unsafe impl ::protobuf::__internal::runtime::AssociatedMiniTable for RouteSummary { + #[inline(always)] + fn mini_table() -> *const ::protobuf::__internal::runtime::upb_MiniTable { + #[allow(unused_unsafe)] + unsafe { ::std::ptr::addr_of!(routeguide__RouteSummary_msg_init) } + } +} +unsafe impl ::protobuf::__internal::runtime::AssociatedMiniTable +for RouteSummaryView<'_> { + #[inline(always)] + fn mini_table() -> *const ::protobuf::__internal::runtime::upb_MiniTable { + #[allow(unused_unsafe)] + unsafe { ::std::ptr::addr_of!(routeguide__RouteSummary_msg_init) } + } +} +unsafe impl ::protobuf::__internal::runtime::AssociatedMiniTable +for RouteSummaryMut<'_> { + #[inline(always)] + fn mini_table() -> *const ::protobuf::__internal::runtime::upb_MiniTable { + #[allow(unused_unsafe)] + unsafe { ::std::ptr::addr_of!(routeguide__RouteSummary_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__RouteSummary_msg_init: ::protobuf::__internal::runtime::upb_MiniTable; +} +impl ::protobuf::OwnedMessageInterop for RouteSummary {} +impl<'a> ::protobuf::MessageMutInterop<'a> for RouteSummaryMut<'a> {} +impl<'a> ::protobuf::MessageViewInterop<'a> for RouteSummaryView<'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 RouteSummary { + 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 RouteSummaryMut<'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 RouteSummaryView<'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-streaming/start_here/generated/routeguide.upb_minitable.c b/codelabs/grpc-rust-streaming/start_here/generated/routeguide.upb_minitable.c new file mode 100644 index 00000000..f3ebd220 --- /dev/null +++ b/codelabs/grpc-rust-streaming/start_here/generated/routeguide.upb_minitable.c @@ -0,0 +1,151 @@ +/* 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_Rectangle__submsgs[2] = { + {.UPB_PRIVATE(submsg) = &routeguide__Point_msg_init_ptr}, + {.UPB_PRIVATE(submsg) = &routeguide__Point_msg_init_ptr}, +}; + +static const upb_MiniTableField routeguide_Rectangle__fields[2] = { + {1, UPB_SIZE(12, 16), 64, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, + {2, UPB_SIZE(16, 24), 65, 1, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, +}; + +const upb_MiniTable routeguide__Rectangle_msg_init = { + &routeguide_Rectangle__submsgs[0], + &routeguide_Rectangle__fields[0], + UPB_SIZE(24, 32), 2, kUpb_ExtMode_NonExtendable, 2, UPB_FASTTABLE_MASK(255), 0, +#ifdef UPB_TRACING_ENABLED + "routeguide.Rectangle", +#endif +}; + +const upb_MiniTable* routeguide__Rectangle_msg_init_ptr = &routeguide__Rectangle_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_MiniTableSubInternal routeguide_RouteNote__submsgs[1] = { + {.UPB_PRIVATE(submsg) = &routeguide__Point_msg_init_ptr}, +}; + +static const upb_MiniTableField routeguide_RouteNote__fields[2] = { + {1, UPB_SIZE(12, 32), 64, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, + {2, 16, 0, kUpb_NoSub, 9, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, +}; + +const upb_MiniTable routeguide__RouteNote_msg_init = { + &routeguide_RouteNote__submsgs[0], + &routeguide_RouteNote__fields[0], + UPB_SIZE(24, 40), 2, kUpb_ExtMode_NonExtendable, 2, UPB_FASTTABLE_MASK(24), 0, +#ifdef UPB_TRACING_ENABLED + "routeguide.RouteNote", +#endif + UPB_FASTTABLE_INIT({ + {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, + {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, + {0x001000003f000012, &upb_pss_1bt}, + {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, + }) +}; + +const upb_MiniTable* routeguide__RouteNote_msg_init_ptr = &routeguide__RouteNote_msg_init; +static const upb_MiniTableField routeguide_RouteSummary__fields[4] = { + {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)}, + {3, 16, 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}, + {4, 20, 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}, +}; + +const upb_MiniTable routeguide__RouteSummary_msg_init = { + NULL, + &routeguide_RouteSummary__fields[0], + 24, 4, kUpb_ExtMode_NonExtendable, 4, UPB_FASTTABLE_MASK(56), 0, +#ifdef UPB_TRACING_ENABLED + "routeguide.RouteSummary", +#endif + UPB_FASTTABLE_INIT({ + {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, + {0x000800003f000008, &upb_psv4_1bt}, + {0x000c00003f000010, &upb_psv4_1bt}, + {0x001000003f000018, &upb_psv4_1bt}, + {0x001400003f000020, &upb_psv4_1bt}, + {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, + {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, + {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, + }) +}; + +const upb_MiniTable* routeguide__RouteSummary_msg_init_ptr = &routeguide__RouteSummary_msg_init; +static const upb_MiniTable *messages_layout[5] = { + &routeguide__Point_msg_init, + &routeguide__Rectangle_msg_init, + &routeguide__Feature_msg_init, + &routeguide__RouteNote_msg_init, + &routeguide__RouteSummary_msg_init, +}; + +const upb_MiniTableFile routeguide_proto_upb_file_layout = { + messages_layout, + NULL, + NULL, + 5, + 0, + 0, +}; + +#include "upb/port/undef.inc" + diff --git a/codelabs/grpc-rust-streaming/start_here/generated/routeguide.upb_minitable.h b/codelabs/grpc-rust-streaming/start_here/generated/routeguide.upb_minitable.h new file mode 100644 index 00000000..3372a4da --- /dev/null +++ b/codelabs/grpc-rust-streaming/start_here/generated/routeguide.upb_minitable.h @@ -0,0 +1,40 @@ +/* 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__Rectangle_msg_init; +extern const upb_MiniTable* routeguide__Rectangle_msg_init_ptr; +extern const upb_MiniTable routeguide__Feature_msg_init; +extern const upb_MiniTable* routeguide__Feature_msg_init_ptr; +extern const upb_MiniTable routeguide__RouteNote_msg_init; +extern const upb_MiniTable* routeguide__RouteNote_msg_init_ptr; +extern const upb_MiniTable routeguide__RouteSummary_msg_init; +extern const upb_MiniTable* routeguide__RouteSummary_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-streaming/start_here/generated/routeguide_grpc.pb.rs b/codelabs/grpc-rust-streaming/start_here/generated/routeguide_grpc.pb.rs new file mode 100644 index 00000000..9c31adfc --- /dev/null +++ b/codelabs/grpc-rust-streaming/start_here/generated/routeguide_grpc.pb.rs @@ -0,0 +1,470 @@ +/// 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 server-to-client streaming RPC. + /// + /// Obtains the Features available within the given Rectangle. Results are + /// streamed rather than returned at once (e.g. in a response message with a + /// repeated field), as the rectangle may cover a large area and contain a + /// huge number of features. + pub async fn list_features( + &mut self, + request: impl tonic::IntoRequest, + ) -> std::result::Result< + tonic::Response>, + 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/ListFeatures", + ); + let mut req = request.into_request(); + req.extensions_mut() + .insert(GrpcMethod::new("routeguide.RouteGuide", "ListFeatures")); + self.inner.server_streaming(req, path, codec).await + } + /// A client-to-server streaming RPC. + /// + /// Accepts a stream of Points on a route being traversed, returning a + /// RouteSummary when traversal is completed. + pub async fn record_route( + &mut self, + request: impl tonic::IntoStreamingRequest, + ) -> 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/RecordRoute", + ); + let mut req = request.into_streaming_request(); + req.extensions_mut() + .insert(GrpcMethod::new("routeguide.RouteGuide", "RecordRoute")); + self.inner.client_streaming(req, path, codec).await + } + /// A Bidirectional streaming RPC. + /// + /// Accepts a stream of RouteNotes sent while a route is being traversed, + /// while receiving other RouteNotes (e.g. from other users). + pub async fn route_chat( + &mut self, + request: impl tonic::IntoStreamingRequest, + ) -> std::result::Result< + tonic::Response>, + 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/RouteChat", + ); + let mut req = request.into_streaming_request(); + req.extensions_mut() + .insert(GrpcMethod::new("routeguide.RouteGuide", "RouteChat")); + self.inner.streaming(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 server-to-client streaming RPC. + /// + /// Obtains the Features available within the given Rectangle. Results are + /// streamed rather than returned at once (e.g. in a response message with a + /// repeated field), as the rectangle may cover a large area and contain a + /// huge number of features. + async fn list_features( + &self, + request: tonic::Request, + ) -> std::result::Result< + tonic::Response>, + tonic::Status, + > { + Err(tonic::Status::unimplemented("Not yet implemented")) + } + /// A client-to-server streaming RPC. + /// + /// Accepts a stream of Points on a route being traversed, returning a + /// RouteSummary when traversal is completed. + async fn record_route( + &self, + request: tonic::Request>, + ) -> std::result::Result, tonic::Status> { + Err(tonic::Status::unimplemented("Not yet implemented")) + } + /// A Bidirectional streaming RPC. + /// + /// Accepts a stream of RouteNotes sent while a route is being traversed, + /// while receiving other RouteNotes (e.g. from other users). + async fn route_chat( + &self, + request: tonic::Request>, + ) -> std::result::Result< + tonic::Response>, + 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/ListFeatures" => { + #[allow(non_camel_case_types)] + struct list_featuresSvc(pub Arc); + impl< + T: RouteGuide, + > tonic::server::ServerStreamingService + for list_featuresSvc { + type Response = super::Feature; + type ResponseStream = BoxStream; + 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 { + ::list_features(&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 = list_featuresSvc(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.server_streaming(method, req).await; + Ok(res) + }; + Box::pin(fut) + } + "/routeguide.RouteGuide/RecordRoute" => { + #[allow(non_camel_case_types)] + struct record_routeSvc(pub Arc); + impl< + T: RouteGuide, + > tonic::server::ClientStreamingService + for record_routeSvc { + type Response = super::RouteSummary; + 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 { + ::record_route(&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 = record_routeSvc(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.client_streaming(method, req).await; + Ok(res) + }; + Box::pin(fut) + } + "/routeguide.RouteGuide/RouteChat" => { + #[allow(non_camel_case_types)] + struct route_chatSvc(pub Arc); + impl tonic::server::StreamingService + for route_chatSvc { + type Response = super::RouteNote; + type ResponseStream = BoxStream; + 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 { + ::route_chat(&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 = route_chatSvc(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.streaming(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-streaming/start_here/proto/routeguide.proto b/codelabs/grpc-rust-streaming/start_here/proto/routeguide.proto new file mode 100644 index 00000000..630e25d5 --- /dev/null +++ b/codelabs/grpc-rust-streaming/start_here/proto/routeguide.proto @@ -0,0 +1,60 @@ +// Copyright 2024 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 features.field_presence = IMPLICIT; +option go_package = "github.com/grpc-ecosystem/codelabs/getting_started_streaming/routeguide"; +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 streaming RPC methods here + ///////////////////////////////////////////////////////////////////////////// +} + +message Point { + ///////////////////////////////////////////////////////////////////////////// + // Codelab Hint: Define the Point messages here + ///////////////////////////////////////////////////////////////////////////// +} + +message Rectangle { + ///////////////////////////////////////////////////////////////////////////// + // Codelab Hint: Define the Rectangle messages here + ///////////////////////////////////////////////////////////////////////////// +} + +message Feature { + ///////////////////////////////////////////////////////////////////////////// + // Codelab Hint: Define the Feature messages here + ///////////////////////////////////////////////////////////////////////////// +} + + +message RouteNote { + ///////////////////////////////////////////////////////////////////////////// + // Codelab Hint: Define the RouteNote messages here + ///////////////////////////////////////////////////////////////////////////// +} + +message RouteSummary { + ///////////////////////////////////////////////////////////////////////////// + // Codelab Hint: Define the RouteSummary messages here + ///////////////////////////////////////////////////////////////////////////// +} \ No newline at end of file diff --git a/codelabs/grpc-rust-streaming/start_here/src/client/client.rs b/codelabs/grpc-rust-streaming/start_here/src/client/client.rs new file mode 100644 index 00000000..4139f757 --- /dev/null +++ b/codelabs/grpc-rust-streaming/start_here/src/client/client.rs @@ -0,0 +1,78 @@ +use std::error::Error; +use std::time::Duration; + +use rand::rngs::ThreadRng; +use rand::Rng; +use tokio::time; +use tonic::transport::{Channel, Endpoint}; +use tonic::Request; +use protobuf::proto; + +// ///////////////////////////////////////////////////////////////////////// +// Codelab Hint: Bring the generated code into scope. +// ///////////////////////////////////////////////////////////////////////// + +use grpc_pb::route_guide_client::RouteGuideClient; +use grpc_pb::{Point, Rectangle, RouteNote}; + +async fn print_features(client: &mut RouteGuideClient) -> Result<(), Box> { + // --- Add logic for calling ListFeatures method on the client here. --- + // + // Steps include: + // - Call ListFeatures method on the client by passing in rect. + // - Loop through the features that are within the bounding Rectangle. + // - Print the features that are within the bounding Rectangle. + + /////////////////////////////////////////////////////////////////////////// + // Client-to-Server Streaming RPC + // + // Call RecordRoute method on the client. + /////////////////////////////////////////////////////////////////////////// +} + +async fn run_record_route(client: &mut RouteGuideClient) -> Result<(), Box> { + // --- Add logic for calling RecordRoute method on the client here. --- + // + // Steps include: + // - Create a stream to send a sequence of points. (Hint: use rand.New() and randomPoint()) + // to create a new random number generator.) + // - Send points to the server. + // - Receive the response from the server. + // - Print the response from the server. + + /////////////////////////////////////////////////////////////////////////// + // Bidirectional Streaming RPC + // + // Call RouteChat method on the client. + /////////////////////////////////////////////////////////////////////////// +} + +async fn run_route_chat(client: &mut RouteGuideClient) -> Result<(), Box> { + // --- Add logic for calling RouteChat method on the client here. --- + // + // Steps include: + // - Create a stream to send and receive a sequence of RouteNotes(`notes`). (Hint: client.RouteChat(ctx)) + // - Create a goroutine which loops to receive RouteNotes from the server until the stream is closed. + // - In the main goroutine, send a sequence of RouteNotes to the server. Close the stream when done. + // - Wait for the receiving goroutine to finish. (Hint: use a channel to signal when the receiving goroutine is done.) +} + +fn random_point(rng: &mut ThreadRng) -> Point { + let latitude = (rng.random_range(0..180) - 90) * 10_000_000; + let longitude = (rng.random_range(0..360) - 180) * 10_000_000; + let mut point = Point::new(); + point.set_latitude(latitude); + point.set_longitude(longitude); + point +} + +#[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::new(). + // - Call service methods on the client to interact with the server. + /////////////////////////////////////////////////////////////////////////// +} diff --git a/codelabs/grpc-rust-streaming/start_here/src/data/route_guide_db.json b/codelabs/grpc-rust-streaming/start_here/src/data/route_guide_db.json new file mode 100644 index 00000000..732f0997 --- /dev/null +++ b/codelabs/grpc-rust-streaming/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-streaming/start_here/src/server/server.rs b/codelabs/grpc-rust-streaming/start_here/src/server/server.rs new file mode 100644 index 00000000..6befee03 --- /dev/null +++ b/codelabs/grpc-rust-streaming/start_here/src/server/server.rs @@ -0,0 +1,169 @@ +use std::collections::HashMap; +use std::pin::Pin; +use std::sync::Arc; +use std::time::Instant; + +use tokio::sync::mpsc; +use tokio_stream::{wrappers::ReceiverStream, Stream, StreamExt}; +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, +} + +pub use grpc_pb::{ + route_guide_server::{RouteGuideServer, RouteGuide}, + Point, Feature, Rectangle, RouteNote, RouteSummary +}; + +#[derive(Debug)] +pub struct RouteGuideService { + features: Arc>, +} +type ListFeaturesStream = Pin> + Send + 'static>>; +type RouteChatStream = Pin> + Send + 'static>>; + +#[tonic::async_trait] +impl RouteGuide for RouteGuideService { + + async fn list_features( + &self, + request: Request, + ) -> Result, Status> { + /////////////////////////////////////////////////////////////////////////// + // Codelab Hint: Logic for ListFeature will be added here. + // + // Steps include: + // - Loop through the features to find the features that are within + // the given bounding Rectangle. + // - Send the features that are within the bounding Rectangle to the + // client. + // - Return an error if there is an issue sending the feature. + /////////////////////////////////////////////////////////////////////////// + } + + async fn record_route( + &self, + request: Request>, + ) -> Result, Status> { + // ///////////////////////////////////////////////////////////////////////// + // Codelab Hint: Logic for RecordRoute will be added here. + // Steps include: + // - Loop until the end of the stream + // - Calculate the distance between the last point and the current point. + // - Update the point_count, feature_count, and distance. + // - Calculate the total time spent. + // - Send the RouteSummary to the client. + // ///////////////////////////////////////////////////////////////////////// + } + + async fn route_chat( + &self, + request: Request>, + ) -> Result, Status> { + /////////////////////////////////////////////////////////////////////////// + // Codelab Hint: Logic for RouteChat will be added here. + // + // Steps include: + // - Loop until the end of the stream. + // - Append the message to the notes map. + // - Send all previous messages at each of those locations to the client. + // - Return the stream. + /////////////////////////////////////////////////////////////////////////// + } +} + +#[tokio::main] +async fn main() -> Result<(), Box> { + /////////////////////////////////////////////////////////////////////////// + // 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 + // - Create an instance of the gRPC server using RouteGuideServer.new(...). + // - Register our service implementation with the gRPC server. + // - Call serve() on the server with our port details to do a blocking + // wait until the process is killed or Stop() is called. + /////////////////////////////////////////////////////////////////////////// +} + +fn in_range(point: &Point, rect: &Rectangle) -> bool { + use std::cmp; + + let lo = rect.lo(); + let hi = rect.hi(); + + let left = cmp::min(lo.longitude(), hi.longitude()); + let right = cmp::max(lo.longitude(), hi.longitude()); + let top = cmp::max(lo.latitude(), hi.latitude()); + let bottom = cmp::min(lo.latitude(), hi.latitude()); + + point.longitude() >= left + && point.longitude() <= right + && point.latitude() >= bottom + && point.latitude() <= top +} + +/// Calculates the distance between two points using the "haversine" formula. +/// This code was taken from http://www.movable-type.co.uk/scripts/latlong.html. +fn calc_distance(p1: &Point, p2: &Point) -> i32 { + const CORD_FACTOR: f64 = 1e7; + const R: f64 = 6_371_000.0; // meters + + let lat1 = p1.latitude() as f64 / CORD_FACTOR; + let lat2 = p2.latitude() as f64 / CORD_FACTOR; + let lng1 = p1.longitude() as f64 / CORD_FACTOR; + let lng2 = p2.longitude() as f64 / CORD_FACTOR; + + let lat_rad1 = lat1.to_radians(); + let lat_rad2 = lat2.to_radians(); + + let delta_lat = (lat2 - lat1).to_radians(); + let delta_lng = (lng2 - lng1).to_radians(); + + let a = (delta_lat / 2f64).sin() * (delta_lat / 2f64).sin() + + (lat_rad1).cos() * (lat_rad2).cos() * (delta_lng / 2f64).sin() * (delta_lng / 2f64).sin(); + + let c = 2f64 * a.sqrt().atan2((1f64 - a).sqrt()); + + (R * c) as 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