Implement oneof support.
This includes the code generation changes,
and the infrastructure to wire it up to the encode/decode machinery.
The overall API changes are these:
- oneofs in a message are replaced by a single interface field
- each field in a oneof gets a distinguished type that satisfies
the corresponding interface
- a type switch may be used to distinguish between oneof fields
Fixes #29.
diff --git a/proto/equal_test.go b/proto/equal_test.go
index b322f65..0e0db8a 100644
--- a/proto/equal_test.go
+++ b/proto/equal_test.go
@@ -180,6 +180,24 @@
&pb.MessageWithMap{NameMapping: map[int32]string{1: "Rob"}},
false,
},
+ {
+ "oneof same",
+ &pb.Communique{Union: &pb.Communique_Number{41}},
+ &pb.Communique{Union: &pb.Communique_Number{41}},
+ true,
+ },
+ {
+ "oneof one nil",
+ &pb.Communique{Union: &pb.Communique_Number{41}},
+ &pb.Communique{},
+ false,
+ },
+ {
+ "oneof different",
+ &pb.Communique{Union: &pb.Communique_Number{41}},
+ &pb.Communique{Union: &pb.Communique_Name{"Bobby Tables"}},
+ false,
+ },
}
func TestEqual(t *testing.T) {