feat: Implement gRPC Reflection Service (#340)

Co-authored-by: Samani G. Gikandi <[email protected]>
This commit is contained in:
James Nugent
2021-02-16 11:07:51 -05:00
committed by GitHub
co-authored by Samani G. Gikandi
parent f49d4bdf99
commit c54f24721c
15 changed files with 1524 additions and 1 deletions
+12
View File
@@ -12,6 +12,7 @@ pub fn configure() -> Builder {
Builder {
build_client: true,
build_server: true,
file_descriptor_set_path: None,
out_dir: None,
extern_path: Vec::new(),
field_attributes: Vec::new(),
@@ -189,6 +190,7 @@ impl prost_build::ServiceGenerator for ServiceGenerator {
pub struct Builder {
pub(crate) build_client: bool,
pub(crate) build_server: bool,
pub(crate) file_descriptor_set_path: Option<PathBuf>,
pub(crate) extern_path: Vec<(String, String)>,
pub(crate) field_attributes: Vec<(String, String)>,
pub(crate) type_attributes: Vec<(String, String)>,
@@ -213,6 +215,13 @@ impl Builder {
self
}
/// Generate a file containing the encoded `prost_types::FileDescriptorSet` for protocol buffers
/// modules. This is required for implementing gRPC Server Reflection.
pub fn file_descriptor_set_path(mut self, path: impl AsRef<Path>) -> Self {
self.file_descriptor_set_path = Some(path.as_ref().to_path_buf());
self
}
/// Enable the output to be formated by rustfmt.
#[cfg(feature = "rustfmt")]
pub fn format(mut self, run: bool) -> Self {
@@ -305,6 +314,9 @@ impl Builder {
let format = self.format;
config.out_dir(out_dir.clone());
if let Some(path) = self.file_descriptor_set_path.as_ref() {
config.file_descriptor_set_path(path);
}
for (proto_path, rust_path) in self.extern_path.iter() {
config.extern_path(proto_path, rust_path);
}