Skip to content

Commit

Permalink
tonic-reflection: Restructure crate to prep reintroducing v1alpha (#1802
Browse files Browse the repository at this point in the history
)

To simplify API verification, this is a prepatory change to shift
around the v1 support to allow for a cleaner v1alpha reintroduction.

* Created a multi-file version of the server.rs module
* Added mod.rs containing the base error with associated imports
* Added v1.rs containing the v1 version of the reflection server
  • Loading branch information
ttkjesper authored Jul 15, 2024
1 parent ad1a95d commit aa57ffe
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 30 deletions.
36 changes: 36 additions & 0 deletions tonic-reflection/src/server/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
pub use crate::pb::v1::server_reflection_server::{ServerReflection, ServerReflectionServer};

use prost::DecodeError;
use std::fmt::{Display, Formatter};

mod v1;

pub use v1::Builder;

/// Represents an error in the construction of a gRPC Reflection Service.
#[derive(Debug)]
pub enum Error {
/// An error was encountered decoding a `prost_types::FileDescriptorSet` from a buffer.
DecodeError(prost::DecodeError),
/// An invalid `prost_types::FileDescriptorProto` was encountered.
InvalidFileDescriptorSet(String),
}

impl From<DecodeError> for Error {
fn from(e: DecodeError) -> Self {
Error::DecodeError(e)
}
}

impl std::error::Error for Error {}

impl Display for Error {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
Error::DecodeError(_) => f.write_str("error decoding FileDescriptorSet from buffer"),
Error::InvalidFileDescriptorSet(s) => {
write!(f, "invalid FileDescriptorSet - {}", s)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,50 +1,23 @@
pub use crate::pb::v1::server_reflection_server::{ServerReflection, ServerReflectionServer};
use crate::pb::v1::server_reflection_server::{ServerReflection, ServerReflectionServer};

use crate::pb::v1::server_reflection_request::MessageRequest;
use crate::pb::v1::server_reflection_response::MessageResponse;
use crate::pb::v1::{
ExtensionNumberResponse, FileDescriptorResponse, ListServiceResponse, ServerReflectionRequest,
ServerReflectionResponse, ServiceResponse,
};
use prost::{DecodeError, Message};
use prost::Message;
use prost_types::{
DescriptorProto, EnumDescriptorProto, FieldDescriptorProto, FileDescriptorProto,
FileDescriptorSet,
};
use std::collections::HashMap;
use std::fmt::{Display, Formatter};
use std::sync::Arc;
use tokio::sync::mpsc;
use tokio_stream::{wrappers::ReceiverStream, StreamExt};
use tonic::{Request, Response, Status, Streaming};

/// Represents an error in the construction of a gRPC Reflection Service.
#[derive(Debug)]
pub enum Error {
/// An error was encountered decoding a `prost_types::FileDescriptorSet` from a buffer.
DecodeError(prost::DecodeError),
/// An invalid `prost_types::FileDescriptorProto` was encountered.
InvalidFileDescriptorSet(String),
}

impl From<DecodeError> for Error {
fn from(e: DecodeError) -> Self {
Error::DecodeError(e)
}
}

impl std::error::Error for Error {}

impl Display for Error {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
Error::DecodeError(_) => f.write_str("error decoding FileDescriptorSet from buffer"),
Error::InvalidFileDescriptorSet(s) => {
write!(f, "invalid FileDescriptorSet - {}", s)
}
}
}
}
use crate::server::Error;

/// A builder used to construct a gRPC Reflection Service.
#[derive(Debug)]
Expand Down

0 comments on commit aa57ffe

Please sign in to comment.