Skip to content

Expose tonic codegen paths #2104

@killzoner

Description

@killzoner

Feature Request

Expose all method paths as constants

Crates

tonic-build

Motivation

I have a use case where I need to send already marshalled proto data on the wire (and so send data without marshalling). I achieved that by partially implementing what the code gen is doing and wrapping some bytes in a type that implements Message trait (basically skipping encoding, directly sending the buffer as is). I fallback to tonic codegen for any route not matched.

That's great, it means tonic is the only implementation (to my knowledge) so far apart from cpp allowing this use case! (See cpp GenericStub and BytesBuffer at https://grpc.io/docs/guides/performance/#c)

But since path match is not fully using codegen, if I ever refacto some proto and the path changes (which is a breaking change to the proto definition but still), it couldn't be caught at all in my code at compile time (this would fallback to tonic codegen with unimplemented method)

Proposal

Expose each route as a constant in the generated package.

It's imposing some convention to be maintained which can be a burden and over complicate codegen

Alternatives

  • There are other ways to achieve binary marshalled data send with current state of tonic
  • No change since it's very specific use case

Side note

  • I'm willing to implement this if deemed useful
  • I'm willing to create an example to demonstrate the use case

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions