Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Rename protobuf api #1224

Merged
merged 1 commit into from
Jan 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions tonic-health/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,22 @@
use std::fmt::{Display, Formatter};

/// Generated protobuf types from the `grpc.health.v1` package.
pub mod proto {
pub mod pb {
#![allow(unreachable_pub)]
#![allow(missing_docs)]
include!("generated/grpc.health.v1.rs");

pub const GRPC_HEALTH_V1_FILE_DESCRIPTOR_SET: &[u8] =
include_bytes!("generated/grpc_health_v1.bin");
/// Byte encoded FILE_DESCRIPTOR_SET.
pub const FILE_DESCRIPTOR_SET: &[u8] = include_bytes!("generated/grpc_health_v1.bin");

#[cfg(test)]
mod tests {
use super::GRPC_HEALTH_V1_FILE_DESCRIPTOR_SET;
use super::FILE_DESCRIPTOR_SET;
use prost::Message as _;

#[test]
fn file_descriptor_set_is_valid() {
prost_types::FileDescriptorSet::decode(GRPC_HEALTH_V1_FILE_DESCRIPTOR_SET).unwrap();
prost_types::FileDescriptorSet::decode(FILE_DESCRIPTOR_SET).unwrap();
}
}
}
Expand Down Expand Up @@ -67,12 +67,12 @@ impl Display for ServingStatus {
}
}

impl From<ServingStatus> for proto::health_check_response::ServingStatus {
impl From<ServingStatus> for pb::health_check_response::ServingStatus {
fn from(s: ServingStatus) -> Self {
match s {
ServingStatus::Unknown => proto::health_check_response::ServingStatus::Unknown,
ServingStatus::Serving => proto::health_check_response::ServingStatus::Serving,
ServingStatus::NotServing => proto::health_check_response::ServingStatus::NotServing,
ServingStatus::Unknown => pb::health_check_response::ServingStatus::Unknown,
ServingStatus::Serving => pb::health_check_response::ServingStatus::Serving,
ServingStatus::NotServing => pb::health_check_response::ServingStatus::NotServing,
}
}
}
16 changes: 8 additions & 8 deletions tonic-health/src/server.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Contains all healthcheck based server utilities.

use crate::proto::health_server::{Health, HealthServer};
use crate::proto::{HealthCheckRequest, HealthCheckResponse};
use crate::pb::health_server::{Health, HealthServer};
use crate::pb::{HealthCheckRequest, HealthCheckResponse};
use crate::ServingStatus;
use std::collections::HashMap;
use std::pin::Pin;
Expand Down Expand Up @@ -132,7 +132,7 @@ impl Health for HealthService {
match status {
None => Err(Status::not_found("service not registered")),
Some(status) => Ok(Response::new(HealthCheckResponse {
status: crate::proto::health_check_response::ServingStatus::from(status) as i32,
status: crate::pb::health_check_response::ServingStatus::from(status) as i32,
})),
}
}
Expand All @@ -152,11 +152,11 @@ impl Health for HealthService {

let output = async_stream::try_stream! {
// yield the current value
let status = crate::proto::health_check_response::ServingStatus::from(*status_rx.borrow()) as i32;
let status = crate::pb::health_check_response::ServingStatus::from(*status_rx.borrow()) as i32;
yield HealthCheckResponse { status };

while let Ok(_) = status_rx.changed().await {
let status = crate::proto::health_check_response::ServingStatus::from(*status_rx.borrow()) as i32;
let status = crate::pb::health_check_response::ServingStatus::from(*status_rx.borrow()) as i32;
yield HealthCheckResponse { status };
}
};
Expand All @@ -167,16 +167,16 @@ impl Health for HealthService {

#[cfg(test)]
mod tests {
use crate::proto::health_server::Health;
use crate::proto::HealthCheckRequest;
use crate::pb::health_server::Health;
use crate::pb::HealthCheckRequest;
use crate::server::{HealthReporter, HealthService};
use crate::ServingStatus;
use tokio::sync::watch;
use tokio_stream::StreamExt;
use tonic::{Code, Request, Status};

fn assert_serving_status(wire: i32, expected: ServingStatus) {
let expected = crate::proto::health_check_response::ServingStatus::from(expected) as i32;
let expected = crate::pb::health_check_response::ServingStatus::from(expected) as i32;
assert_eq!(wire, expected);
}

Expand Down
3 changes: 2 additions & 1 deletion tonic-reflection/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@
#![cfg_attr(docsrs, feature(doc_cfg))]

/// Generated protobuf types from the `grpc.reflection.v1alpha` package.
pub mod proto {
pub mod pb {
#![allow(unreachable_pub)]
#![allow(missing_docs)]
#![allow(rustdoc::invalid_html_tags)]
include!("generated/grpc.reflection.v1alpha.rs");

/// Byte encoded FILE_DESCRIPTOR_SET.
pub const FILE_DESCRIPTOR_SET: &[u8] = include_bytes!("generated/reflection_v1alpha1.bin");

#[cfg(test)]
Expand Down
10 changes: 5 additions & 5 deletions tonic-reflection/src/server.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::proto::server_reflection_request::MessageRequest;
use crate::proto::server_reflection_response::MessageResponse;
pub use crate::proto::server_reflection_server::{ServerReflection, ServerReflectionServer};
use crate::proto::{
use crate::pb::server_reflection_request::MessageRequest;
use crate::pb::server_reflection_response::MessageResponse;
pub use crate::pb::server_reflection_server::{ServerReflection, ServerReflectionServer};
use crate::pb::{
ExtensionNumberResponse, FileDescriptorResponse, ListServiceResponse, ServerReflectionRequest,
ServerReflectionResponse, ServiceResponse,
};
Expand Down Expand Up @@ -109,7 +109,7 @@ impl<'b> Builder<'b> {
/// Build a gRPC Reflection Service to be served via Tonic.
pub fn build(mut self) -> Result<ServerReflectionServer<impl ServerReflection>, Error> {
if self.include_reflection_service {
self = self.register_encoded_file_descriptor_set(crate::proto::FILE_DESCRIPTOR_SET);
self = self.register_encoded_file_descriptor_set(crate::pb::FILE_DESCRIPTOR_SET);
}

for encoded in &self.encoded_file_descriptor_sets {
Expand Down
2 changes: 1 addition & 1 deletion tonic-reflection/tests/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use tokio::sync::oneshot;
use tokio_stream::{wrappers::TcpListenerStream, StreamExt};
use tonic::{transport::Server, Request};
use tonic_reflection::{
proto::{
pb::{
server_reflection_client::ServerReflectionClient,
server_reflection_request::MessageRequest, server_reflection_response::MessageResponse,
ServerReflectionRequest, ServiceResponse, FILE_DESCRIPTOR_SET,
Expand Down