diff --git a/crates/nodata/src/gen/nodata.rs b/crates/nodata/src/gen/nodata.v1.rs similarity index 97% rename from crates/nodata/src/gen/nodata.rs rename to crates/nodata/src/gen/nodata.v1.rs index 4a7329f..625a76f 100644 --- a/crates/nodata/src/gen/nodata.rs +++ b/crates/nodata/src/gen/nodata.v1.rs @@ -39,5 +39,5 @@ pub struct GetKeysResponse { #[prost(string, repeated, tag="1")] pub keys: ::prost::alloc::vec::Vec<::prost::alloc::string::String>, } -include!("nodata.tonic.rs"); +include!("nodata.v1.tonic.rs"); // @@protoc_insertion_point(module) \ No newline at end of file diff --git a/crates/nodata/src/gen/nodata.tonic.rs b/crates/nodata/src/gen/nodata.v1.tonic.rs similarity index 87% rename from crates/nodata/src/gen/nodata.tonic.rs rename to crates/nodata/src/gen/nodata.v1.tonic.rs index 75710ed..4542e66 100644 --- a/crates/nodata/src/gen/nodata.tonic.rs +++ b/crates/nodata/src/gen/nodata.v1.tonic.rs @@ -1,14 +1,14 @@ // @generated /// Generated client implementations. -pub mod no_data_client { +pub mod no_data_service_client { #![allow(unused_variables, dead_code, missing_docs, clippy::let_unit_value)] use tonic::codegen::*; use tonic::codegen::http::Uri; #[derive(Debug, Clone)] - pub struct NoDataClient { + pub struct NoDataServiceClient { inner: tonic::client::Grpc, } - impl NoDataClient { + impl NoDataServiceClient { /// Attempt to create a new client by connecting to a given endpoint. pub async fn connect(dst: D) -> Result where @@ -19,7 +19,7 @@ pub mod no_data_client { Ok(Self::new(conn)) } } - impl NoDataClient + impl NoDataServiceClient where T: tonic::client::GrpcService, T::Error: Into, @@ -37,7 +37,7 @@ pub mod no_data_client { pub fn with_interceptor( inner: T, interceptor: F, - ) -> NoDataClient> + ) -> NoDataServiceClient> where F: tonic::service::Interceptor, T::ResponseBody: Default, @@ -51,7 +51,7 @@ pub mod no_data_client { http::Request, >>::Error: Into + Send + Sync, { - NoDataClient::new(InterceptedService::new(inner, interceptor)) + NoDataServiceClient::new(InterceptedService::new(inner, interceptor)) } /// Compress requests with the given encoding. /// @@ -102,11 +102,11 @@ pub mod no_data_client { })?; let codec = tonic::codec::ProstCodec::default(); let path = http::uri::PathAndQuery::from_static( - "/nodata.NoData/PublishEvent", + "/nodata.v1.NoDataService/PublishEvent", ); let mut req = request.into_request(); req.extensions_mut() - .insert(GrpcMethod::new("nodata.NoData", "PublishEvent")); + .insert(GrpcMethod::new("nodata.v1.NoDataService", "PublishEvent")); self.inner.unary(req, path, codec).await } pub async fn get_topics( @@ -126,9 +126,12 @@ pub mod no_data_client { ) })?; let codec = tonic::codec::ProstCodec::default(); - let path = http::uri::PathAndQuery::from_static("/nodata.NoData/GetTopics"); + let path = http::uri::PathAndQuery::from_static( + "/nodata.v1.NoDataService/GetTopics", + ); let mut req = request.into_request(); - req.extensions_mut().insert(GrpcMethod::new("nodata.NoData", "GetTopics")); + req.extensions_mut() + .insert(GrpcMethod::new("nodata.v1.NoDataService", "GetTopics")); self.inner.unary(req, path, codec).await } pub async fn get_keys( @@ -148,20 +151,23 @@ pub mod no_data_client { ) })?; let codec = tonic::codec::ProstCodec::default(); - let path = http::uri::PathAndQuery::from_static("/nodata.NoData/GetKeys"); + let path = http::uri::PathAndQuery::from_static( + "/nodata.v1.NoDataService/GetKeys", + ); let mut req = request.into_request(); - req.extensions_mut().insert(GrpcMethod::new("nodata.NoData", "GetKeys")); + req.extensions_mut() + .insert(GrpcMethod::new("nodata.v1.NoDataService", "GetKeys")); self.inner.unary(req, path, codec).await } } } /// Generated server implementations. -pub mod no_data_server { +pub mod no_data_service_server { #![allow(unused_variables, dead_code, missing_docs, clippy::let_unit_value)] use tonic::codegen::*; - /// Generated trait containing gRPC methods that should be implemented for use with NoDataServer. + /// Generated trait containing gRPC methods that should be implemented for use with NoDataServiceServer. #[async_trait] - pub trait NoData: Send + Sync + 'static { + pub trait NoDataService: Send + Sync + 'static { async fn publish_event( &self, request: tonic::Request, @@ -182,7 +188,7 @@ pub mod no_data_server { ) -> std::result::Result, tonic::Status>; } #[derive(Debug)] - pub struct NoDataServer { + pub struct NoDataServiceServer { inner: _Inner, accept_compression_encodings: EnabledCompressionEncodings, send_compression_encodings: EnabledCompressionEncodings, @@ -190,7 +196,7 @@ pub mod no_data_server { max_encoding_message_size: Option, } struct _Inner(Arc); - impl NoDataServer { + impl NoDataServiceServer { pub fn new(inner: T) -> Self { Self::from_arc(Arc::new(inner)) } @@ -242,9 +248,9 @@ pub mod no_data_server { self } } - impl tonic::codegen::Service> for NoDataServer + impl tonic::codegen::Service> for NoDataServiceServer where - T: NoData, + T: NoDataService, B: Body + Send + 'static, B::Error: Into + Send + 'static, { @@ -260,11 +266,11 @@ pub mod no_data_server { fn call(&mut self, req: http::Request) -> Self::Future { let inner = self.inner.clone(); match req.uri().path() { - "/nodata.NoData/PublishEvent" => { + "/nodata.v1.NoDataService/PublishEvent" => { #[allow(non_camel_case_types)] - struct PublishEventSvc(pub Arc); + struct PublishEventSvc(pub Arc); impl< - T: NoData, + T: NoDataService, > tonic::server::UnaryService for PublishEventSvc { type Response = super::PublishEventResponse; @@ -278,7 +284,7 @@ pub mod no_data_server { ) -> Self::Future { let inner = Arc::clone(&self.0); let fut = async move { - ::publish_event(&inner, request).await + ::publish_event(&inner, request).await }; Box::pin(fut) } @@ -306,10 +312,12 @@ pub mod no_data_server { }; Box::pin(fut) } - "/nodata.NoData/GetTopics" => { + "/nodata.v1.NoDataService/GetTopics" => { #[allow(non_camel_case_types)] - struct GetTopicsSvc(pub Arc); - impl tonic::server::UnaryService + struct GetTopicsSvc(pub Arc); + impl< + T: NoDataService, + > tonic::server::UnaryService for GetTopicsSvc { type Response = super::GetTopicsResponse; type Future = BoxFuture< @@ -322,7 +330,7 @@ pub mod no_data_server { ) -> Self::Future { let inner = Arc::clone(&self.0); let fut = async move { - ::get_topics(&inner, request).await + ::get_topics(&inner, request).await }; Box::pin(fut) } @@ -350,10 +358,12 @@ pub mod no_data_server { }; Box::pin(fut) } - "/nodata.NoData/GetKeys" => { + "/nodata.v1.NoDataService/GetKeys" => { #[allow(non_camel_case_types)] - struct GetKeysSvc(pub Arc); - impl tonic::server::UnaryService + struct GetKeysSvc(pub Arc); + impl< + T: NoDataService, + > tonic::server::UnaryService for GetKeysSvc { type Response = super::GetKeysResponse; type Future = BoxFuture< @@ -366,7 +376,7 @@ pub mod no_data_server { ) -> Self::Future { let inner = Arc::clone(&self.0); let fut = async move { - ::get_keys(&inner, request).await + ::get_keys(&inner, request).await }; Box::pin(fut) } @@ -409,7 +419,7 @@ pub mod no_data_server { } } } - impl Clone for NoDataServer { + impl Clone for NoDataServiceServer { fn clone(&self) -> Self { let inner = self.inner.clone(); Self { @@ -421,7 +431,7 @@ pub mod no_data_server { } } } - impl Clone for _Inner { + impl Clone for _Inner { fn clone(&self) -> Self { Self(Arc::clone(&self.0)) } @@ -431,7 +441,7 @@ pub mod no_data_server { write!(f, "{:?}", self.0) } } - impl tonic::server::NamedService for NoDataServer { - const NAME: &'static str = "nodata.NoData"; + impl tonic::server::NamedService for NoDataServiceServer { + const NAME: &'static str = "nodata.v1.NoDataService"; } } diff --git a/crates/nodata/src/gen/nomicon.rs b/crates/nodata/src/gen/nomicon.rs deleted file mode 100644 index 3a69fca..0000000 --- a/crates/nodata/src/gen/nomicon.rs +++ /dev/null @@ -1,19 +0,0 @@ -// @generated -#[allow(clippy::derive_partial_eq_without_eq)] -#[derive(Clone, PartialEq, ::prost::Message)] -pub struct PublishEventRequest { - #[prost(string, tag="1")] - pub topic: ::prost::alloc::string::String, - #[prost(message, optional, tag="2")] - pub published: ::core::option::Option<::prost_types::Timestamp>, - #[prost(string, tag="3")] - pub key: ::prost::alloc::string::String, - #[prost(bytes="vec", tag="4")] - pub value: ::prost::alloc::vec::Vec, -} -#[allow(clippy::derive_partial_eq_without_eq)] -#[derive(Clone, PartialEq, ::prost::Message)] -pub struct PublishEventResponse { -} -include!("nomicon.tonic.rs"); -// @@protoc_insertion_point(module) \ No newline at end of file diff --git a/crates/nodata/src/gen/nomicon.tonic.rs b/crates/nodata/src/gen/nomicon.tonic.rs deleted file mode 100644 index 84e8c88..0000000 --- a/crates/nodata/src/gen/nomicon.tonic.rs +++ /dev/null @@ -1,294 +0,0 @@ -// @generated -/// Generated client implementations. -pub mod no_data_client { - #![allow(unused_variables, dead_code, missing_docs, clippy::let_unit_value)] - use tonic::codegen::*; - use tonic::codegen::http::Uri; - #[derive(Debug, Clone)] - pub struct NoDataClient { - inner: tonic::client::Grpc, - } - impl NoDataClient { - /// Attempt to create a new client by connecting to a given endpoint. - pub async fn connect(dst: D) -> Result - where - D: TryInto, - D::Error: Into, - { - let conn = tonic::transport::Endpoint::new(dst)?.connect().await?; - Ok(Self::new(conn)) - } - } - impl NoDataClient - where - T: tonic::client::GrpcService, - T::Error: Into, - T::ResponseBody: Body + Send + 'static, - ::Error: Into + 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, - ) -> NoDataClient> - where - F: tonic::service::Interceptor, - T::ResponseBody: Default, - T: tonic::codegen::Service< - http::Request, - Response = http::Response< - >::ResponseBody, - >, - >, - , - >>::Error: Into + Send + Sync, - { - NoDataClient::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 - } - pub async fn publish_event( - &mut self, - request: impl tonic::IntoRequest, - ) -> std::result::Result< - tonic::Response, - tonic::Status, - > { - self.inner - .ready() - .await - .map_err(|e| { - tonic::Status::new( - tonic::Code::Unknown, - format!("Service was not ready: {}", e.into()), - ) - })?; - let codec = tonic::codec::ProstCodec::default(); - let path = http::uri::PathAndQuery::from_static( - "/nomicon.NoData/PublishEvent", - ); - let mut req = request.into_request(); - req.extensions_mut() - .insert(GrpcMethod::new("nomicon.NoData", "PublishEvent")); - self.inner.unary(req, path, codec).await - } - } -} -/// Generated server implementations. -pub mod no_data_server { - #![allow(unused_variables, dead_code, missing_docs, clippy::let_unit_value)] - use tonic::codegen::*; - /// Generated trait containing gRPC methods that should be implemented for use with NoDataServer. - #[async_trait] - pub trait NoData: Send + Sync + 'static { - async fn publish_event( - &self, - request: tonic::Request, - ) -> std::result::Result< - tonic::Response, - tonic::Status, - >; - } - #[derive(Debug)] - pub struct NoDataServer { - inner: _Inner, - accept_compression_encodings: EnabledCompressionEncodings, - send_compression_encodings: EnabledCompressionEncodings, - max_decoding_message_size: Option, - max_encoding_message_size: Option, - } - struct _Inner(Arc); - impl NoDataServer { - pub fn new(inner: T) -> Self { - Self::from_arc(Arc::new(inner)) - } - pub fn from_arc(inner: Arc) -> Self { - let inner = _Inner(inner); - 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 NoDataServer - where - T: NoData, - B: Body + Send + 'static, - B::Error: Into + 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 { - let inner = self.inner.clone(); - match req.uri().path() { - "/nomicon.NoData/PublishEvent" => { - #[allow(non_camel_case_types)] - struct PublishEventSvc(pub Arc); - impl< - T: NoData, - > tonic::server::UnaryService - for PublishEventSvc { - type Response = super::PublishEventResponse; - 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 { - ::publish_event(&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 inner = inner.0; - let method = PublishEventSvc(inner); - let codec = tonic::codec::ProstCodec::default(); - let mut grpc = tonic::server::Grpc::new(codec) - .apply_compression_config( - accept_compression_encodings, - send_compression_encodings, - ) - .apply_max_message_size_config( - max_decoding_message_size, - max_encoding_message_size, - ); - let res = grpc.unary(method, req).await; - Ok(res) - }; - Box::pin(fut) - } - _ => { - Box::pin(async move { - Ok( - http::Response::builder() - .status(200) - .header("grpc-status", "12") - .header("content-type", "application/grpc") - .body(empty_body()) - .unwrap(), - ) - }) - } - } - } - } - impl Clone for NoDataServer { - 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, - } - } - } - impl Clone for _Inner { - fn clone(&self) -> Self { - Self(Arc::clone(&self.0)) - } - } - impl std::fmt::Debug for _Inner { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "{:?}", self.0) - } - } - impl tonic::server::NamedService for NoDataServer { - const NAME: &'static str = "nomicon.NoData"; - } -} diff --git a/crates/nodata/src/grpc.rs b/crates/nodata/src/grpc.rs index 2809d17..9727710 100644 --- a/crates/nodata/src/grpc.rs +++ b/crates/nodata/src/grpc.rs @@ -8,7 +8,7 @@ use crate::{ state::SharedState, }; -include!("gen/nodata.rs"); +include!("gen/nodata.v1.rs"); #[derive(Clone)] pub struct GrpcServer { @@ -26,7 +26,7 @@ impl GrpcServer { } #[tonic::async_trait] -impl no_data_server::NoData for GrpcServer { +impl no_data_service_server::NoDataService for GrpcServer { async fn publish_event( &self, request: tonic::Request, @@ -99,7 +99,9 @@ impl Component for GrpcServer { tracing::info!("grpc listening on: {}", self.host); tonic::transport::Server::builder() - .add_service(no_data_server::NoDataServer::new(self.clone())) + .add_service(no_data_service_server::NoDataServiceServer::new( + self.clone(), + )) .serve(self.host) .await .context("grpc server failed") diff --git a/crates/nodata/src/main.rs b/crates/nodata/src/main.rs index 836ba42..51026ba 100644 --- a/crates/nodata/src/main.rs +++ b/crates/nodata/src/main.rs @@ -7,7 +7,7 @@ mod services; use std::net::SocketAddr; use chrono::{Datelike, Timelike}; -use clap::{Parser, Subcommand, ValueEnum}; +use clap::{Parser, Subcommand}; use grpc::{GetKeysRequest, GetTopicsRequest, GrpcServer, PublishEventRequest}; use http::HttpServer; use mad::Mad; @@ -154,8 +154,11 @@ async fn main() -> anyhow::Result<()> { async fn create_client( grpc_host: String, -) -> anyhow::Result> { - let client = crate::grpc::no_data_client::NoDataClient::connect(grpc_host).await?; +) -> anyhow::Result< + crate::grpc::no_data_service_client::NoDataServiceClient, +> { + let client = + crate::grpc::no_data_service_client::NoDataServiceClient::connect(grpc_host).await?; Ok(client) } diff --git a/proto/nomicon.proto b/proto/nodata/v1/nomicon.proto similarity index 93% rename from proto/nomicon.proto rename to proto/nodata/v1/nomicon.proto index 9bf12ca..f2d7290 100644 --- a/proto/nomicon.proto +++ b/proto/nodata/v1/nomicon.proto @@ -2,9 +2,9 @@ syntax = "proto3"; import "google/protobuf/timestamp.proto"; -package nodata; +package nodata.v1; -service NoData { +service NoDataService { rpc PublishEvent(PublishEventRequest) returns (PublishEventResponse) {} rpc GetTopics(GetTopicsRequest) returns (GetTopicsResponse) {} rpc GetKeys(GetKeysRequest) returns (GetKeysResponse) {}