Skip to content

Commit

Permalink
feat: cherry-pick improvements from gogo/protobuf (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
julienrbrt authored Sep 6, 2022
1 parent ed9594c commit c3a0399
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 322 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
Copyright (c) 2022, The Cosmos SDK Authors. All rights reserved.
Copyright (c) 2013, The GoGo Authors. All rights reserved.

Protocol Buffers for Go with Gadgets
Expand Down Expand Up @@ -32,4 +33,3 @@ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ errcheck:

drone:
sudo apt-get install protobuf-compiler
(cd $(GOPATH)/src/github.com/cosmos/gogoproto && make buildserverall)
(cd ./gogoproto && make buildserverall)

testall:
go get -u github.com/golang/protobuf/proto
Expand Down
308 changes: 0 additions & 308 deletions README

This file was deleted.

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ Cosmos's fork of [gogo/protobuf](https://github.com/gogo/protobuf).
[![Build Status](https://github.com/cosmos/gogoproto/workflows/Continuous%20Integration/badge.svg)](https://github.com/cosmos/gogoproto/actions)
[![GoDoc](https://godoc.org/github.com/cosmos/gogoproto?status.svg)](http://godoc.org/github.com/cosmos/gogoproto)

---

This code generation is used to achieve:

- fast marshalling and unmarshalling
Expand All @@ -15,3 +13,5 @@ This code generation is used to achieve:
- less typing by optionally generating extra helper code
- peace of mind by optionally generating test and benchmark code
- other serialization formats

More information in the [original readme](https://github.com/gogo/protobuf/blob/master/README).
5 changes: 3 additions & 2 deletions conformance/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,12 @@ test:
./test.sh $(PROTOBUF_ROOT)

regenerate:
protoc-min-version --version="3.0.0" --proto_path=$(GOPATH)/src:$(GOPATH)/src/github.com/cosmos/gogoproto/protobuf:. --gogo_out=\
protoc-min-version --version="3.0.0" --proto_path=../protobuf:. --gogo_out=\
Mgoogle/protobuf/any.proto=github.com/cosmos/gogoproto/types,\
Mgoogle/protobuf/duration.proto=github.com/cosmos/gogoproto/types,\
Mgoogle/protobuf/struct.proto=github.com/cosmos/gogoproto/types,\
Mgoogle/protobuf/timestamp.proto=github.com/cosmos/gogoproto/types,\
Mgoogle/protobuf/wrappers.proto=github.com/cosmos/gogoproto/types,\
Mgoogle/protobuf/field_mask.proto=github.com/cosmos/gogoproto/types\
:. ./internal/conformance_proto/conformance.proto
:. ./internal/conformance_proto/conformance.proto\
-I ../gogoproto -I ../protobuf
2 changes: 1 addition & 1 deletion gogoproto/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ The most complete way to see examples is to look at
github.com/cosmos/gogoproto/test/thetest.proto
Gogoprototest is a seperate project,
Gogoprototest is a separate project,
because we want to keep gogoprotobuf independent of goprotobuf,
but we still want to test it thoroughly.
Expand Down
16 changes: 10 additions & 6 deletions proto/clone.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,17 @@ func mergeStruct(out, in reflect.Value) {
// viaPtr indicates whether the values were indirected through a pointer (implying proto2).
// prop is set if this is a struct field (it may be nil).
func mergeAny(out, in reflect.Value, viaPtr bool, prop *Properties) {
if in.Type() == protoMessageType {
if !in.IsNil() {
if out.IsNil() {
out.Set(reflect.ValueOf(Clone(in.Interface().(Message))))
} else {
Merge(out.Interface().(Message), in.Interface().(Message))
if in.Type() == protoMessageType || (in.CanAddr() && in.Addr().Type().Implements(protoMessageType)) {
if in.Kind() == reflect.Ptr {
if !in.IsNil() {
if out.IsNil() {
out.Set(reflect.ValueOf(Clone(in.Interface().(Message))))
} else {
Merge(out.Interface().(Message), in.Interface().(Message))
}
}
} else {
Merge(out.Addr().Interface().(Message), in.Addr().Interface().(Message))
}
return
}
Expand Down
Loading

0 comments on commit c3a0399

Please sign in to comment.