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

Function newTestMessage

proto/text_test.go:303–359  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

301func (*textMessage) ProtoMessage() {}
302
303func newTestMessage() *pb2.MyMessage {
304 msg := &pb2.MyMessage{
305 Count: proto.Int32(42),
306 Name: proto.String("Dave"),
307 Quote: proto.String(`"I didn't want to go."`),
308 Pet: []string{"bunny", "kitty", "horsey"},
309 Inner: &pb2.InnerMessage{
310 Host: proto.String("footrest.syd"),
311 Port: proto.Int32(7001),
312 Connected: proto.Bool(true),
313 },
314 Others: []*pb2.OtherMessage{
315 {
316 Key: proto.Int64(0xdeadbeef),
317 Value: []byte{1, 65, 7, 12},
318 },
319 {
320 Weight: proto.Float32(6.022),
321 Inner: &pb2.InnerMessage{
322 Host: proto.String("lesha.mtv"),
323 Port: proto.Int32(8002),
324 },
325 },
326 },
327 Bikeshed: pb2.MyMessage_BLUE.Enum(),
328 Somegroup: &pb2.MyMessage_SomeGroup{
329 GroupField: proto.Int32(8),
330 },
331 // One normally wouldn't do this.
332 // This is an undeclared tag 13, as a varint (wire type 0) with value 4.
333 XXX_unrecognized: []byte{13<<3 | 0, 4},
334 }
335 ext := &pb2.Ext{
336 Data: proto.String("Big gobs for big rats"),
337 }
338 if err := proto.SetExtension(msg, pb2.E_Ext_More, ext); err != nil {
339 panic(err)
340 }
341 greetings := []string{"adg", "easy", "cow"}
342 if err := proto.SetExtension(msg, pb2.E_Greeting, greetings); err != nil {
343 panic(err)
344 }
345
346 // Add an unknown extension. We marshal a pb2.Ext, and fake the ID.
347 b, err := proto.Marshal(&pb2.Ext{Data: proto.String("3G skiing")})
348 if err != nil {
349 panic(err)
350 }
351 b = append(proto.EncodeVarint(201<<3|proto.WireBytes), b...)
352 proto.SetRawExtension(msg, 201, b)
353
354 // Extensions can be plain fields, too, so let's test that.
355 b = append(proto.EncodeVarint(202<<3|proto.WireVarint), 19)
356 proto.SetRawExtension(msg, 202, b)
357
358 return msg
359}
360

Callers 3

TestMarshalTextFunction · 0.85
TestCompactTextFunction · 0.85
TestMarshalTextFailingFunction · 0.85

Calls 10

Int32Function · 0.92
StringFunction · 0.92
BoolFunction · 0.92
Int64Function · 0.92
Float32Function · 0.92
SetExtensionFunction · 0.92
MarshalFunction · 0.92
EncodeVarintFunction · 0.92
SetRawExtensionFunction · 0.92
EnumMethod · 0.45

Tested by

no test coverage detected