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

Function init

proto/proto_equal_test.go:30–77  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

28var messageWithInt32Extension2 = &pb2.MyMessage{Count: proto.Int32(8)}
29
30func init() {
31 ext1 := &pb2.Ext{Data: proto.String("Kirk")}
32 ext2 := &pb2.Ext{Data: proto.String("Picard")}
33
34 // messageWithExtension1a has ext1, but never marshals it.
35 if err := proto.SetExtension(messageWithExtension1a, pb2.E_Ext_More, ext1); err != nil {
36 panic("proto.SetExtension on 1a failed: " + err.Error())
37 }
38
39 // messageWithExtension1b is the unmarshaled form of messageWithExtension1a.
40 if err := proto.SetExtension(messageWithExtension1b, pb2.E_Ext_More, ext1); err != nil {
41 panic("proto.SetExtension on 1b failed: " + err.Error())
42 }
43 buf, err := proto.Marshal(messageWithExtension1b)
44 if err != nil {
45 panic("proto.Marshal of 1b failed: " + err.Error())
46 }
47 messageWithExtension1b.Reset()
48 if err := proto.Unmarshal(buf, messageWithExtension1b); err != nil {
49 panic("proto.Unmarshal of 1b failed: " + err.Error())
50 }
51
52 // messageWithExtension2 has ext2.
53 if err := proto.SetExtension(messageWithExtension2, pb2.E_Ext_More, ext2); err != nil {
54 panic("proto.SetExtension on 2 failed: " + err.Error())
55 }
56
57 if err := proto.SetExtension(messageWithInt32Extension1, pb2.E_Ext_Number, proto.Int32(23)); err != nil {
58 panic("proto.SetExtension on Int32-1 failed: " + err.Error())
59 }
60 if err := proto.SetExtension(messageWithInt32Extension1, pb2.E_Ext_Number, proto.Int32(24)); err != nil {
61 panic("proto.SetExtension on Int32-2 failed: " + err.Error())
62 }
63
64 // messageWithExtension3{a,b,c} has unregistered extension.
65 if proto.RegisteredExtensions(messageWithExtension3a)[200] != nil {
66 panic("expect extension 200 unregistered")
67 }
68 bytes := []byte{
69 0xc0, 0x0c, 0x01, // id=200, wiretype=0 (varint), data=1
70 }
71 bytes2 := []byte{
72 0xc0, 0x0c, 0x02, // id=200, wiretype=0 (varint), data=2
73 }
74 proto.SetRawExtension(messageWithExtension3a, 200, bytes)
75 proto.SetRawExtension(messageWithExtension3b, 200, bytes)
76 proto.SetRawExtension(messageWithExtension3c, 200, bytes2)
77}
78
79var EqualTests = []struct {
80 desc string

Callers

nothing calls this directly

Calls 9

StringFunction · 0.92
SetExtensionFunction · 0.92
MarshalFunction · 0.92
UnmarshalFunction · 0.92
Int32Function · 0.92
RegisteredExtensionsFunction · 0.92
SetRawExtensionFunction · 0.92
ErrorMethod · 0.45
ResetMethod · 0.45

Tested by

no test coverage detected