Package equal
Overview ▹
Overview ▾
The equal plugin generates an Equal and a VerboseEqual method for each message. These equal methods are quite obvious. The only difference is that VerboseEqual returns a non nil error if it is not equal. This error contains more detail on exactly which part of the message was not equal to the other message. The idea is that this is useful for debugging.
Equal is enabled using the following extensions:
- equal - equal_all
While VerboseEqual is enable dusing the following extensions:
- verbose_equal - verbose_equal_all
The equal plugin also generates a test given it is enabled using one of the following extensions:
- testgen - testgen_all
Let us look at:
github.com/gogo/protobuf/test/example/example.proto
Btw all the output can be seen at:
github.com/gogo/protobuf/test/example/*
The following message:
option (gogoproto.equal_all) = true; option (gogoproto.verbose_equal_all) = true; message B { optional A A = 1 [(gogoproto.nullable) = false, (gogoproto.embed) = true]; repeated bytes G = 2 [(gogoproto.customtype) = "github.com/gogo/protobuf/test/custom.Uint128", (gogoproto.nullable) = false]; }
given to the equal plugin, will generate the following code:
func (this *B) VerboseEqual(that interface{}) error { if that == nil { if this == nil { return nil } return fmt2.Errorf("that == nil && this != nil") } that1, ok := that.(*B) if !ok { return fmt2.Errorf("that is not of type *B") } if that1 == nil { if this == nil { return nil } return fmt2.Errorf("that is type *B but is nil && this != nil") } else if this == nil { return fmt2.Errorf("that is type *B but is not nil && this == nil") } if !this.A.Equal(&that1.A) { return fmt2.Errorf("A this(%v) Not Equal that(%v)", this.A, that1.A) } if len(this.G) != len(that1.G) { return fmt2.Errorf("G this(%v) Not Equal that(%v)", len(this.G), len(that1.G)) } for i := range this.G { if !this.G[i].Equal(that1.G[i]) { return fmt2.Errorf("G this[%v](%v) Not Equal that[%v](%v)", i, this.G[i], i, that1.G[i]) } } if !bytes.Equal(this.XXX_unrecognized, that1.XXX_unrecognized) { return fmt2.Errorf("XXX_unrecognized this(%v) Not Equal that(%v)", this.XXX_unrecognized, that1.XXX_unrecognized) } return nil } func (this *B) Equal(that interface{}) bool { if that == nil { if this == nil { return true } return false } that1, ok := that.(*B) if !ok { return false } if that1 == nil { if this == nil { return true } return false } else if this == nil { return false } if !this.A.Equal(&that1.A) { return false } if len(this.G) != len(that1.G) { return false } for i := range this.G { if !this.G[i].Equal(that1.G[i]) { return false } } if !bytes.Equal(this.XXX_unrecognized, that1.XXX_unrecognized) { return false } return true }
and the following test code:
func TestBVerboseEqual(t *testing8.T) { popr := math_rand8.New(math_rand8.NewSource(time8.Now().UnixNano())) p := NewPopulatedB(popr, false) dAtA, err := github_com_gogo_protobuf_proto2.Marshal(p) if err != nil { panic(err) } msg := &B{} if err := github_com_gogo_protobuf_proto2.Unmarshal(dAtA, msg); err != nil { panic(err) } if err := p.VerboseEqual(msg); err != nil { t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) }
Index ▹
Index ▾
Package files
Internal call graph ▹
Internal call graph ▾
In the call graph viewer below, each node is a function belonging to this package and its children are the functions it calls—perhaps dynamically.
The root nodes are the entry points of the package: functions that may be called from outside the package. There may be non-exported or anonymous functions among them if they are called dynamically from another package.
Click a node to visit that function's source code.
From there you can visit its callers by
clicking its declaring func
token.
Functions may be omitted if they were determined to be unreachable in the particular programs or tests that were analyzed.
func NewPlugin ¶
func NewPlugin() *plugin
func NewTest ¶
func NewTest(g *generator.Generator) testgen.TestPlugin
Portions of this page are modifications based on work created and shared by Google
and used according to terms described in the Creative Commons 3.0 Attribution License.
© 2018 ActiveState Software Inc. All rights reserved. Trademarks.