Skip to content

Commit

Permalink
change empty type to PbEmpty type
Browse files Browse the repository at this point in the history
  • Loading branch information
andeya committed Feb 11, 2018
1 parent d3d9852 commit 5ddca02
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 44 deletions.
80 changes: 39 additions & 41 deletions codec/empty.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion codec/empty.proto
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
syntax = "proto3";
package codec;
message empty {}
message PbEmpty {}
8 changes: 6 additions & 2 deletions codec/protobuf_codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,19 @@ func (ProtoCodec) Unmarshal(data []byte, v interface{}) error {
return ProtoUnmarshal(data, v)
}

var emptyStruct = struct{}{}
var (
// EmptyStruct empty struct for protobuf
EmptyStruct = new(PbEmpty)
emptyStruct = struct{}{}
)

// ProtoMarshal returns the Protobuf encoding of v.
func ProtoMarshal(v interface{}) ([]byte, error) {
if p, ok := v.(proto.Message); ok {
return proto.Marshal(p)
}
if v == nil || v == emptyStruct {
return proto.Marshal(Empty)
return proto.Marshal(EmptyStruct)
}
return nil, fmt.Errorf("%T does not implement proto.Message", v)
}
Expand Down

0 comments on commit 5ddca02

Please sign in to comment.