Skip to content

Commit

Permalink
generate vald gRPC code for Rust
Browse files Browse the repository at this point in the history
Signed-off-by: Kosuke Morimoto <[email protected]>
  • Loading branch information
kmrmt committed Jan 10, 2024
1 parent 727c5ef commit f72d151
Show file tree
Hide file tree
Showing 25 changed files with 11,288 additions and 0 deletions.
879 changes: 879 additions & 0 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[workspace]
members = ["vald-client-rs", "vald-agent-rs"]
14 changes: 14 additions & 0 deletions buf.gen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,17 @@ plugins:
out: apis/swagger
opt:
- json_names_for_fields=true
- plugin: buf.build/community/neoeinstein-prost
out: vald-client-rs/src
- plugin: buf.build/community/neoeinstein-tonic
out: vald-client-rs/src
opt:
- no_include
- no_server
- plugin: buf.build/community/neoeinstein-prost
out: vald-agent-rs/src
- plugin: buf.build/community/neoeinstein-tonic
out: vald-agent-rs/src
opt:
- no_include
- no_client
11 changes: 11 additions & 0 deletions vald-agent-rs/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "vald-agent-rs"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
prost = "0.12.3"
tonic = "0.10.2"
tonic-types = "0.10.2"
417 changes: 417 additions & 0 deletions vald-agent-rs/src/core.v1.tonic.rs

Large diffs are not rendered by default.

301 changes: 301 additions & 0 deletions vald-agent-rs/src/discoverer.v1.tonic.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,301 @@
// @generated
/// Generated server implementations.
pub mod discoverer_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 DiscovererServer.
#[async_trait]
pub trait Discoverer: Send + Sync + 'static {
async fn pods(
&self,
request: tonic::Request<
super::super::super::payload::v1::discoverer::Request,
>,
) -> std::result::Result<
tonic::Response<super::super::super::payload::v1::info::Pods>,
tonic::Status,
>;
/** Represent the RPC to get the node information.
*/
async fn nodes(
&self,
request: tonic::Request<
super::super::super::payload::v1::discoverer::Request,
>,
) -> std::result::Result<
tonic::Response<super::super::super::payload::v1::info::Nodes>,
tonic::Status,
>;
/** Represent the RPC to get the readreplica svc information.
*/
async fn services(
&self,
request: tonic::Request<
super::super::super::payload::v1::discoverer::Request,
>,
) -> std::result::Result<
tonic::Response<super::super::super::payload::v1::info::Services>,
tonic::Status,
>;
}
#[derive(Debug)]
pub struct DiscovererServer<T: Discoverer> {
inner: _Inner<T>,
accept_compression_encodings: EnabledCompressionEncodings,
send_compression_encodings: EnabledCompressionEncodings,
max_decoding_message_size: Option<usize>,
max_encoding_message_size: Option<usize>,
}
struct _Inner<T>(Arc<T>);
impl<T: Discoverer> DiscovererServer<T> {
pub fn new(inner: T) -> Self {
Self::from_arc(Arc::new(inner))
}
pub fn from_arc(inner: Arc<T>) -> 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<F>(
inner: T,
interceptor: F,
) -> InterceptedService<Self, F>
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<T, B> tonic::codegen::Service<http::Request<B>> for DiscovererServer<T>
where
T: Discoverer,
B: Body + Send + 'static,
B::Error: Into<StdError> + Send + 'static,
{
type Response = http::Response<tonic::body::BoxBody>;
type Error = std::convert::Infallible;
type Future = BoxFuture<Self::Response, Self::Error>;
fn poll_ready(
&mut self,
_cx: &mut Context<'_>,
) -> Poll<std::result::Result<(), Self::Error>> {
Poll::Ready(Ok(()))
}
fn call(&mut self, req: http::Request<B>) -> Self::Future {
let inner = self.inner.clone();
match req.uri().path() {
"/discoverer.v1.Discoverer/Pods" => {
#[allow(non_camel_case_types)]
struct PodsSvc<T: Discoverer>(pub Arc<T>);
impl<
T: Discoverer,
> tonic::server::UnaryService<
super::super::super::payload::v1::discoverer::Request,
> for PodsSvc<T> {
type Response = super::super::super::payload::v1::info::Pods;
type Future = BoxFuture<
tonic::Response<Self::Response>,
tonic::Status,
>;
fn call(
&mut self,
request: tonic::Request<
super::super::super::payload::v1::discoverer::Request,
>,
) -> Self::Future {
let inner = Arc::clone(&self.0);
let fut = async move { (*inner).pods(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 = PodsSvc(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)
}
"/discoverer.v1.Discoverer/Nodes" => {
#[allow(non_camel_case_types)]
struct NodesSvc<T: Discoverer>(pub Arc<T>);
impl<
T: Discoverer,
> tonic::server::UnaryService<
super::super::super::payload::v1::discoverer::Request,
> for NodesSvc<T> {
type Response = super::super::super::payload::v1::info::Nodes;
type Future = BoxFuture<
tonic::Response<Self::Response>,
tonic::Status,
>;
fn call(
&mut self,
request: tonic::Request<
super::super::super::payload::v1::discoverer::Request,
>,
) -> Self::Future {
let inner = Arc::clone(&self.0);
let fut = async move { (*inner).nodes(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 = NodesSvc(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)
}
"/discoverer.v1.Discoverer/Services" => {
#[allow(non_camel_case_types)]
struct ServicesSvc<T: Discoverer>(pub Arc<T>);
impl<
T: Discoverer,
> tonic::server::UnaryService<
super::super::super::payload::v1::discoverer::Request,
> for ServicesSvc<T> {
type Response = super::super::super::payload::v1::info::Services;
type Future = BoxFuture<
tonic::Response<Self::Response>,
tonic::Status,
>;
fn call(
&mut self,
request: tonic::Request<
super::super::super::payload::v1::discoverer::Request,
>,
) -> Self::Future {
let inner = Arc::clone(&self.0);
let fut = async move { (*inner).services(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 = ServicesSvc(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<T: Discoverer> Clone for DiscovererServer<T> {
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<T: Discoverer> Clone for _Inner<T> {
fn clone(&self) -> Self {
Self(Arc::clone(&self.0))
}
}
impl<T: std::fmt::Debug> std::fmt::Debug for _Inner<T> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{:?}", self.0)
}
}
impl<T: Discoverer> tonic::server::NamedService for DiscovererServer<T> {
const NAME: &'static str = "discoverer.v1.Discoverer";
}
}
Loading

0 comments on commit f72d151

Please sign in to comment.