Skip to content

Commit 0393e58

Browse files
authored
Merge pull request planetscale#135 from bhollis/patch-1
Update README with custom codec needed for usage in Connect
2 parents 54814e4 + 8aa4346 commit 0393e58

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ protoc --go_out=. --go-vtproto_out=. --go-drpc_out=. --go-drpc_opt=protolib=gith
180180
```
181181

182182
### Connect
183-
To use `vtprotobuf` with Connect simply pass in `connect.WithCodec(grpc.Codec{})` as a connect option to the client and handler constructors.
183+
To use `vtprotobuf` with Connect, first implement a custom codec in your own project that serializes messages based on their type (see [Mixing ProtoBuf implementations with GRPC](#mixing-protobuf-implementations-with-grpc)). This is required because Connect internally serializes some types such as `Status` that don't have `vtprotobuf` helpers. Then pass in `connect.WithCodec(mygrpc.Codec{})` as a connect option to the client and handler constructors.
184184

185185
```go
186186
package main
@@ -190,21 +190,21 @@ import (
190190

191191
"github.com/bufbuild/connect-go"
192192
"github.com/foo/bar/pingv1connect"
193-
"github.com/planetscale/vtprotobuf/codec/grpc"
193+
"github.com/myorg/myproject/codec/mygrpc"
194194
)
195195

196196
func main() {
197197
mux := http.NewServeMux()
198198
mux.Handle(pingv1connect.NewPingServiceHandler(
199199
&PingServer{},
200-
connect.WithCodec(grpc.Codec{}), // Add connect option to handler.
200+
connect.WithCodec(mygrpc.Codec{}), // Add connect option to handler.
201201
))
202202
// handler serving ...
203203

204204
client := pingv1connect.NewPingServiceClient(
205205
http.DefaultClient,
206206
"http://localhost:8080",
207-
connect.WithCodec(grpc.Codec{}), // Add connect option to client.
207+
connect.WithCodec(mygrpc.Codec{}), // Add connect option to client.
208208
)
209209
/// client code here ...
210210
}

0 commit comments

Comments
 (0)