@@ -36,6 +36,7 @@ import (
3636 "google.golang.org/grpc/internal/grpctest"
3737 "google.golang.org/grpc/internal/grpcutil"
3838 "google.golang.org/grpc/internal/stubserver"
39+ "google.golang.org/grpc/mem"
3940 "google.golang.org/grpc/metadata"
4041 "google.golang.org/grpc/status"
4142
@@ -90,18 +91,18 @@ type errProtoCodec struct {
9091 decodingErr error
9192}
9293
93- func (c * errProtoCodec ) Marshal (v any ) ([] byte , error ) {
94+ func (c * errProtoCodec ) Marshal (v any ) (mem. BufferSlice , error ) {
9495 if c .encodingErr != nil {
9596 return nil , c .encodingErr
9697 }
97- return encoding .GetCodec (proto .Name ).Marshal (v )
98+ return encoding .GetCodecV2 (proto .Name ).Marshal (v )
9899}
99100
100- func (c * errProtoCodec ) Unmarshal (data [] byte , v any ) error {
101+ func (c * errProtoCodec ) Unmarshal (data mem. BufferSlice , v any ) error {
101102 if c .decodingErr != nil {
102103 return c .decodingErr
103104 }
104- return encoding .GetCodec (proto .Name ).Unmarshal (data , v )
105+ return encoding .GetCodecV2 (proto .Name ).Unmarshal (data , v )
105106}
106107
107108func (c * errProtoCodec ) Name () string {
@@ -118,7 +119,7 @@ func (s) TestEncodeDoesntPanicOnServer(t *testing.T) {
118119 ec := & errProtoCodec {name : t .Name (), encodingErr : encodingErr }
119120
120121 // Start a server with the above codec.
121- backend := stubserver .StartTestService (t , nil , grpc .ForceServerCodec (ec ))
122+ backend := stubserver .StartTestService (t , nil , grpc .ForceServerCodecV2 (ec ))
122123 defer backend .Stop ()
123124
124125 // Create a channel to the above server.
@@ -154,7 +155,7 @@ func (s) TestDecodeDoesntPanicOnServer(t *testing.T) {
154155 ec := & errProtoCodec {name : t .Name (), decodingErr : decodingErr }
155156
156157 // Start a server with the above codec.
157- backend := stubserver .StartTestService (t , nil , grpc .ForceServerCodec (ec ))
158+ backend := stubserver .StartTestService (t , nil , grpc .ForceServerCodecV2 (ec ))
158159 defer backend .Stop ()
159160
160161 // Create a channel to the above server. Since we do not specify any codec
@@ -206,15 +207,15 @@ func (s) TestEncodeDoesntPanicOnClient(t *testing.T) {
206207 ctx , cancel := context .WithTimeout (context .Background (), defaultTestTimeout )
207208 defer cancel ()
208209 client := testgrpc .NewTestServiceClient (cc )
209- _ , err = client .EmptyCall (ctx , & testpb.Empty {}, grpc .ForceCodec (ec ))
210+ _ , err = client .EmptyCall (ctx , & testpb.Empty {}, grpc .ForceCodecV2 (ec ))
210211 if err == nil || ! strings .Contains (err .Error (), encodingErr .Error ()) {
211212 t .Fatalf ("RPC failed with error: %v, want: %v" , err , encodingErr )
212213 }
213214
214215 // Configure the codec on the client to not return errors anymore and expect
215216 // the RPC to succeed.
216217 ec .encodingErr = nil
217- if _ , err := client .EmptyCall (ctx , & testpb.Empty {}, grpc .ForceCodec (ec )); err != nil {
218+ if _ , err := client .EmptyCall (ctx , & testpb.Empty {}, grpc .ForceCodecV2 (ec )); err != nil {
218219 t .Fatalf ("RPC failed with error: %v" , err )
219220 }
220221}
@@ -242,15 +243,15 @@ func (s) TestDecodeDoesntPanicOnClient(t *testing.T) {
242243 ctx , cancel := context .WithTimeout (context .Background (), defaultTestTimeout )
243244 defer cancel ()
244245 client := testgrpc .NewTestServiceClient (cc )
245- _ , err = client .EmptyCall (ctx , & testpb.Empty {}, grpc .ForceCodec (ec ))
246+ _ , err = client .EmptyCall (ctx , & testpb.Empty {}, grpc .ForceCodecV2 (ec ))
246247 if err == nil || ! strings .Contains (err .Error (), decodingErr .Error ()) {
247248 t .Fatalf ("RPC failed with error: %v, want: %v" , err , decodingErr )
248249 }
249250
250251 // Configure the codec on the client to not return errors anymore and expect
251252 // the RPC to succeed.
252253 ec .decodingErr = nil
253- if _ , err := client .EmptyCall (ctx , & testpb.Empty {}, grpc .ForceCodec (ec )); err != nil {
254+ if _ , err := client .EmptyCall (ctx , & testpb.Empty {}, grpc .ForceCodecV2 (ec )); err != nil {
254255 t .Fatalf ("RPC failed with error: %v" , err )
255256 }
256257}
@@ -265,14 +266,14 @@ type countingProtoCodec struct {
265266 unmarshalCount int32
266267}
267268
268- func (p * countingProtoCodec ) Marshal (v any ) ([] byte , error ) {
269+ func (p * countingProtoCodec ) Marshal (v any ) (mem. BufferSlice , error ) {
269270 atomic .AddInt32 (& p .marshalCount , 1 )
270- return encoding .GetCodec (proto .Name ).Marshal (v )
271+ return encoding .GetCodecV2 (proto .Name ).Marshal (v )
271272}
272273
273- func (p * countingProtoCodec ) Unmarshal (data [] byte , v any ) error {
274+ func (p * countingProtoCodec ) Unmarshal (data mem. BufferSlice , v any ) error {
274275 atomic .AddInt32 (& p .unmarshalCount , 1 )
275- return encoding .GetCodec (proto .Name ).Unmarshal (data , v )
276+ return encoding .GetCodecV2 (proto .Name ).Unmarshal (data , v )
276277}
277278
278279func (p * countingProtoCodec ) Name () string {
@@ -284,7 +285,7 @@ func (p *countingProtoCodec) Name() string {
284285func (s ) TestForceServerCodec (t * testing.T ) {
285286 // Create an server with the counting proto codec.
286287 codec := & countingProtoCodec {name : t .Name ()}
287- backend := stubserver .StartTestService (t , nil , grpc .ForceServerCodec (codec ))
288+ backend := stubserver .StartTestService (t , nil , grpc .ForceServerCodecV2 (codec ))
288289 defer backend .Stop ()
289290
290291 // Create a channel to the above server.
@@ -317,7 +318,7 @@ func (s) TestForceServerCodec(t *testing.T) {
317318
318319// renameProtoCodec wraps the proto codec and allows customizing the Name().
319320type renameProtoCodec struct {
320- encoding.Codec
321+ encoding.CodecV2
321322 name string
322323}
323324
@@ -356,9 +357,9 @@ func (s) TestForceCodecName(t *testing.T) {
356357
357358 // Force the use of the custom codec on the client with the ForceCodec call
358359 // option. Confirm the name is converted to lowercase before transmitting.
359- codec := & renameProtoCodec {Codec : encoding .GetCodec (proto .Name ), name : t .Name ()}
360+ codec := & renameProtoCodec {CodecV2 : encoding .GetCodecV2 (proto .Name ), name : t .Name ()}
360361 wantContentTypeCh <- []string {fmt .Sprintf ("application/grpc+%s" , strings .ToLower (t .Name ()))}
361- if _ , err := ss .Client .EmptyCall (ctx , & testpb.Empty {}, grpc .ForceCodec (codec )); err != nil {
362+ if _ , err := ss .Client .EmptyCall (ctx , & testpb.Empty {}, grpc .ForceCodecV2 (codec )); err != nil {
362363 t .Fatalf ("ss.Client.EmptyCall(_, _) = _, %v; want _, nil" , err )
363364 }
364365}
0 commit comments