func TestPBLinkMarshalTo(t *testing.T) { popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) p := NewPopulatedPBLink(popr, false) size := p.Size() data := make([]byte, size) for i := range data { data[i] = byte(popr.Intn(256)) } _, err := p.MarshalTo(data) if err != nil { panic(err) } msg := &PBLink{} if err := code_google_com_p_gogoprotobuf_proto.Unmarshal(data, msg); err != nil { panic(err) } for i := range data { data[i] = byte(popr.Intn(256)) } if err := p.VerboseEqual(msg); err != nil { t.Fatalf("%#v !VerboseProto %#v, since %v", msg, p, err) } if !p.Equal(msg) { t.Fatalf("%#v !Proto %#v", msg, p) } }
func TestPBNodeVerboseEqual(t *testing6.T) { popr := math_rand6.New(math_rand6.NewSource(time6.Now().UnixNano())) p := NewPopulatedPBNode(popr, false) data, err := code_google_com_p_gogoprotobuf_proto3.Marshal(p) if err != nil { panic(err) } msg := &PBNode{} if err := code_google_com_p_gogoprotobuf_proto3.Unmarshal(data, msg); err != nil { panic(err) } if err := p.VerboseEqual(msg); err != nil { t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err) } }
func BenchmarkPBNodeProtoUnmarshal(b *testing.B) { popr := math_rand.New(math_rand.NewSource(616)) total := 0 datas := make([][]byte, 10000) for i := 0; i < 10000; i++ { data, err := code_google_com_p_gogoprotobuf_proto.Marshal(NewPopulatedPBNode(popr, false)) if err != nil { panic(err) } datas[i] = data } msg := &PBNode{} b.ResetTimer() for i := 0; i < b.N; i++ { total += len(datas[i%10000]) if err := code_google_com_p_gogoprotobuf_proto.Unmarshal(datas[i%10000], msg); err != nil { panic(err) } } b.SetBytes(int64(total / b.N)) }