Skip to main content

Reflector

Struct Reflector 

Source
pub struct Reflector { /* private fields */ }
Expand description

Descriptor index serving gRPC server reflection queries.

Build one from the wire bytes of a FileDescriptorSet (typically embedded with include_bytes! from connectrpc_build::Config::emit_descriptor_set output) or from an existing DescriptorPool, and hand it to ReflectionService.

use connectrpc_reflection::Reflector;

// In real code: include_bytes!(concat!(env!("OUT_DIR"), "/app.fds.bin"))
let reflector = Reflector::from_descriptor_set_bytes(descriptor_set_bytes()).unwrap();

§Multiple descriptor sets

add_descriptor_set_bytes merges further sets into the index. Files whose name is already registered are skipped (first registration wins), so sets that each carry their own copy of shared imports — google/protobuf/*.proto, common vendored protos — merge cleanly.

Implementations§

Source§

impl Reflector

Source

pub fn from_descriptor_set_bytes(bytes: &[u8]) -> Result<Self, ReflectionError>

Build a reflector from wire-format FileDescriptorSet bytes.

The set should carry the transitive import closure of the files it contains (both protoc --include_imports and Config::emit_descriptor_set guarantee this); imports missing from the set are silently omitted from file-closure responses.

§Errors

Returns ReflectionError when the bytes do not decode as a FileDescriptorSet, the descriptors do not link, or a contained file has no name.

Source

pub fn from_descriptor_pool( pool: Arc<DescriptorPool>, ) -> Result<Self, ReflectionError>

Serve reflection from an existing DescriptorPool — typically the lazily-built descriptor_pool() that a buffa-generated package exposes when reflection codegen is enabled, which spares the build script a separate emit_descriptor_set step.

The pool must cover every proto you want resolvable. Under buf generate’s default per-directory plugin strategy, each generated package embeds only its own package’s closure — set strategy: all on the buffa plugin so any one package’s pool spans the whole codegen run.

Response payloads are re-encoded from the pool’s parsed FileDescriptorProtos. buffa preserves unknown fields, so the bytes are semantically faithful to the compiler’s output but not guaranteed byte-identical (field ordering is canonicalized). For byte-exact responses, build from from_descriptor_set_bytes.

A reflector adopting a pool that other references point at — a generated package’s pool always qualifies, since the lazy static keeps one — cannot be extended with add_descriptor_set_bytes; build from bytes if you need to merge sets.

§Errors

Returns ReflectionError::UnnamedFile when a pool file has no name.

Source

pub fn add_descriptor_set_bytes( &mut self, bytes: &[u8], ) -> Result<(), ReflectionError>

Merge another wire-format FileDescriptorSet into the index.

Files whose name is already registered are skipped, so shared imports duplicated across sets do not conflict.

§Errors

Returns ReflectionError when the bytes do not decode or link, a contained file has no name, or any other reference to the backing pool exists (ReflectionError::SharedPool) — which is always the case for reflectors built with from_descriptor_pool from a long-lived pool. On error the reflector should be discarded: the pool may have absorbed part of the failed set.

Source

pub fn with_services<I, S>(self, names: I) -> Self
where I: IntoIterator<Item = S>, S: Into<String>,

Restrict the service list advertised by ListServices to the given fully-qualified names, in the given order.

Like the Go grpcreflect Namer, this affects only ListServices; files and symbols in the descriptor set stay resolvable. Use it when the set’s import closure carries services you do not actually mount. Names absent from the descriptor set are advertised as given — the protocol does not require the list to be resolvable.

Calling this more than once replaces the previous list; it does not accumulate (unlike tonic’s with_service_name).

Source

pub fn service_names(&self) -> Vec<String>

The fully-qualified service names ListServices will advertise: every service in the descriptor pool in registration order plus the reflection services themselves (matching grpc-go, which always lists them) — or, verbatim, the override installed by with_services.

Source

pub fn pool(&self) -> &DescriptorPool

The descriptor pool backing this reflector, for read-only inspection (listing files, resolving descriptors).

Trait Implementations§

Source§

impl Debug for Reflector

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more