feat: Rename api related to protobuf (#1224)

This commit is contained in:
tottoto
2023-01-11 01:16:57 +09:00
committed by GitHub
parent 0d35d7fbaf
commit d2542dc034
5 changed files with 25 additions and 24 deletions
+9 -9
View File
@@ -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();
}
}
}
@@ -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,
}
}
}
+8 -8
View File
@@ -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;
@@ -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,
})),
}
}
@@ -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 };
}
};
@@ -167,8 +167,8 @@ 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;
@@ -176,7 +176,7 @@ mod tests {
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);
}
+2 -1
View File
@@ -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)]
+5 -5
View File
@@ -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,
};
@@ -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 {
+1 -1
View File
@@ -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,