forked from cockroachdb/cockroach
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This change enables future upgrades of google.golang.org/grpc. Recent changes to google.golang.org/grpc have changed the default proto codec such that it is incompatible with gogoproto: grpc/grpc-go#3958 While `proto.Marshal` does do a check for the Marshal/Unmarshal it appears to do this through reflection methods that will panic on fields using gogoproto.nullable. To avoid this, we install a proto codec that does an interface check before dispatching to proto.Marshal/proto.Unmarshal. Note that I haven't replicated the protobuffer caching that previously existed in google.golang.org/grpc. The referenced change claims removing the caching may be a small performance win; however, they also removed the typecheck that we need to do, so it is unclear. Fixes cockroachdb#60531 Release note: None
- Loading branch information
1 parent
1a43d11
commit 3e3d61c
Showing
4 changed files
with
47 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Copyright 2020 The Cockroach Authors. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
package rpc | ||
|
||
import ( | ||
"github.com/cockroachdb/cockroach/pkg/util/protoutil" | ||
"github.com/gogo/protobuf/proto" | ||
"google.golang.org/grpc/encoding" | ||
) | ||
|
||
const name = "proto" | ||
|
||
type codec struct{} | ||
|
||
var _ encoding.Codec = codec{} | ||
|
||
func (codec) Marshal(v interface{}) ([]byte, error) { | ||
if pm, ok := v.(proto.Marshaler); ok { | ||
return pm.Marshal() | ||
} | ||
return protoutil.Marshal(v.(protoutil.Message)) | ||
} | ||
|
||
func (codec) Unmarshal(data []byte, v interface{}) error { | ||
if pm, ok := v.(proto.Unmarshaler); ok { | ||
return pm.Unmarshal(data) | ||
} | ||
return protoutil.Unmarshal(data, v.(protoutil.Message)) | ||
} | ||
|
||
func (codec) Name() string { | ||
return name | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters