vtprotobuf icon indicating copy to clipboard operation
vtprotobuf copied to clipboard

Duplicated code generated for GRPC client/server

Open gnagel opened this issue 2 years ago • 2 comments

Hi All, I'm running the vtproto generator on the proto below, we use both the go + go-grpc generators in addition to vtproto.

However when I run the vtproto generator it duplicates the grpc generated code.

What's the best way to deal with this type of proto to remove the duplicated code?

  1. Split the proto files into two files: messages.proto + grpc.proto?
  2. Ignore the generated gRPC types when running the vtproto generator?

Thanks! Glenn

Single proto

Attached are the generated files: gen.zip

syntax = "proto3";

package pingpong;
option go_package = "pingpong";

service PingPongService {
  rpc Pong(PingRequest) returns (PongResponse) {}
}

message PingRequest {
  string hello = 1;
}

message PongResponse {
  string world = 1;
}

Split protos

Attached are the split generated files: gen 2.zip

messages.proto

syntax = "proto3";

package pingpong;
option go_package = "gen";

message PingRequest {
  string hello = 1;
}

message PongResponse {
  string world = 1;
}

grpc.proto

syntax = "proto3";

package pingpong;
option go_package = "gen";
import "messages.proto";

service PingPongService {
  rpc Pong(PingRequest) returns (PongResponse) {}
}

gnagel avatar Oct 02 '23 14:10 gnagel

There seems to be an unfinished and undocumented feature that gets pulled in by default, conflicting with protoc-gen-go-grpc. Should this be excluded from the default feature list?

  • https://github.com/planetscale/vtprotobuf/tree/main/features/grpc

coxley avatar Oct 02 '23 15:10 coxley

To answer the original question, the plugin defaults to all generation "features", which I believe is something like:

features=pool+size+equal+clone+unmarshal+unmarshal_unsafe+grpc+marshal+marshal_strict

To fix the issue, explicitly set the necessary plugin options and omit the "grpc" plugin option to avoid duplication.

mfridman avatar Jan 22 '25 00:01 mfridman