MCPcopy
hub / github.com/gogo/protobuf / init

Function init

proto/equal_test.go:56–103  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

54var messageWithInt32Extension2 = &pb.MyMessage{Count: Int32(8)}
55
56func init() {
57 ext1 := &pb.Ext{Data: String("Kirk")}
58 ext2 := &pb.Ext{Data: String("Picard")}
59
60 // messageWithExtension1a has ext1, but never marshals it.
61 if err := SetExtension(messageWithExtension1a, pb.E_Ext_More, ext1); err != nil {
62 panic("SetExtension on 1a failed: " + err.Error())
63 }
64
65 // messageWithExtension1b is the unmarshaled form of messageWithExtension1a.
66 if err := SetExtension(messageWithExtension1b, pb.E_Ext_More, ext1); err != nil {
67 panic("SetExtension on 1b failed: " + err.Error())
68 }
69 buf, err := Marshal(messageWithExtension1b)
70 if err != nil {
71 panic("Marshal of 1b failed: " + err.Error())
72 }
73 messageWithExtension1b.Reset()
74 if err := Unmarshal(buf, messageWithExtension1b); err != nil {
75 panic("Unmarshal of 1b failed: " + err.Error())
76 }
77
78 // messageWithExtension2 has ext2.
79 if err := SetExtension(messageWithExtension2, pb.E_Ext_More, ext2); err != nil {
80 panic("SetExtension on 2 failed: " + err.Error())
81 }
82
83 if err := SetExtension(messageWithInt32Extension1, pb.E_Ext_Number, Int32(23)); err != nil {
84 panic("SetExtension on Int32-1 failed: " + err.Error())
85 }
86 if err := SetExtension(messageWithInt32Extension1, pb.E_Ext_Number, Int32(24)); err != nil {
87 panic("SetExtension on Int32-2 failed: " + err.Error())
88 }
89
90 // messageWithExtension3{a,b,c} has unregistered extension.
91 if RegisteredExtensions(messageWithExtension3a)[200] != nil {
92 panic("expect extension 200 unregistered")
93 }
94 bytes := []byte{
95 0xc0, 0x0c, 0x01, // id=200, wiretype=0 (varint), data=1
96 }
97 bytes2 := []byte{
98 0xc0, 0x0c, 0x02, // id=200, wiretype=0 (varint), data=2
99 }
100 SetRawExtension(messageWithExtension3a, 200, bytes)
101 SetRawExtension(messageWithExtension3b, 200, bytes)
102 SetRawExtension(messageWithExtension3c, 200, bytes2)
103}
104
105var EqualTests = []struct {
106 desc string

Callers

nothing calls this directly

Calls 9

StringFunction · 0.85
SetExtensionFunction · 0.85
MarshalFunction · 0.85
Int32Function · 0.85
RegisteredExtensionsFunction · 0.85
SetRawExtensionFunction · 0.85
UnmarshalFunction · 0.70
ResetMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…