本文整理匯總了Golang中github.com/dropbox/goprotoc/proto.Unmarshal函數的典型用法代碼示例。如果您正苦於以下問題:Golang Unmarshal函數的具體用法?Golang Unmarshal怎麽用?Golang Unmarshal使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Unmarshal函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestAMarshalTo
func TestAMarshalTo(t *testing.T) {
popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
p := NewPopulatedA(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 := &A{}
if err := github_com_dropbox_goprotoc_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)
}
}
示例2: ReadMsg
func (this *fullReader) ReadMsg(msg proto.Message) error {
length, err := this.r.Read(this.buf)
if err != nil {
return err
}
return proto.Unmarshal(this.buf[:length], msg)
}
示例3: TestOldNewOldNew
func TestOldNewOldNew(t *testing.T) {
popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
older := NewPopulatedOldA(popr, true)
data1, err := dropbox_gogoprotobuf_proto.Marshal(older)
if err != nil {
panic(err)
}
newer := &A{}
if err := dropbox_gogoprotobuf_proto.Unmarshal(data1, newer); err != nil {
panic(err)
}
data2, err := dropbox_gogoprotobuf_proto.Marshal(newer)
if err != nil {
panic(err)
}
bluer := &OldA{}
if err := dropbox_gogoprotobuf_proto.Unmarshal(data2, bluer); err != nil {
panic(err)
}
if err := older.VerboseEqual(bluer); err != nil {
t.Fatalf("%#v !VerboseProto %#v, since %v", older, bluer, err)
}
data3, err := dropbox_gogoprotobuf_proto.Marshal(bluer)
if err != nil {
panic(err)
}
purple := &A{}
if err := dropbox_gogoprotobuf_proto.Unmarshal(data3, purple); err != nil {
panic(err)
}
data4, err := dropbox_gogoprotobuf_proto.Marshal(purple)
if err != nil {
panic(err)
}
magenta := &OldA{}
if err := dropbox_gogoprotobuf_proto.Unmarshal(data4, magenta); err != nil {
panic(err)
}
if err := older.VerboseEqual(magenta); err != nil {
t.Fatalf("%#v !VerboseProto %#v, since %v", older, magenta, err)
}
}
示例4: TestNewOld
func TestNewOld(t *testing.T) {
popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
newer := NewPopulatedA(popr, true)
data1, err := dropbox_gogoprotobuf_proto.Marshal(newer)
if err != nil {
panic(err)
}
older := &OldA{}
if err := dropbox_gogoprotobuf_proto.Unmarshal(data1, older); err != nil {
panic(err)
}
data2, err := dropbox_gogoprotobuf_proto.Marshal(older)
if err != nil {
panic(err)
}
bluer := &A{}
if err := dropbox_gogoprotobuf_proto.Unmarshal(data2, bluer); err != nil {
panic(err)
}
if err := newer.VerboseEqual(bluer); err != nil {
t.Fatalf("%#v !VerboseProto %#v, since %v", newer, bluer, err)
}
}
示例5: TestGroups2_GVerboseEqual
func TestGroups2_GVerboseEqual(t *testing5.T) {
popr := math_rand5.New(math_rand5.NewSource(time5.Now().UnixNano()))
p := NewPopulatedGroups2_G(popr, false)
data, err := dropbox_gogoprotobuf_proto2.Marshal(p)
if err != nil {
panic(err)
}
msg := &Groups2_G{}
if err := dropbox_gogoprotobuf_proto2.Unmarshal(data, msg); err != nil {
panic(err)
}
if err := p.VerboseEqual(msg); err != nil {
t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err)
}
}
示例6: TestEVerboseEqual
func TestEVerboseEqual(t *testing4.T) {
popr := math_rand4.New(math_rand4.NewSource(time4.Now().UnixNano()))
p := NewPopulatedE(popr, false)
data, err := github_com_dropbox_goprotoc_proto1.Marshal(p)
if err != nil {
panic(err)
}
msg := &E{}
if err := github_com_dropbox_goprotoc_proto1.Unmarshal(data, msg); err != nil {
panic(err)
}
if err := p.VerboseEqual(msg); err != nil {
t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err)
}
}
示例7: TestOldWithGroup_Group2VerboseEqual
func TestOldWithGroup_Group2VerboseEqual(t *testing6.T) {
popr := math_rand6.New(math_rand6.NewSource(time6.Now().UnixNano()))
p := NewPopulatedOldWithGroup_Group2(popr, false)
data, err := dropbox_gogoprotobuf_proto3.Marshal(p)
if err != nil {
panic(err)
}
msg := &OldWithGroup_Group2{}
if err := dropbox_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)
}
}
示例8: TestNinRepEnumVerboseEqual
func TestNinRepEnumVerboseEqual(t *testing3.T) {
popr := math_rand3.New(math_rand3.NewSource(time3.Now().UnixNano()))
p := NewPopulatedNinRepEnum(popr, false)
data, err := dropbox_gogoprotobuf_proto2.Marshal(p)
if err != nil {
panic(err)
}
msg := &NinRepEnum{}
if err := dropbox_gogoprotobuf_proto2.Unmarshal(data, msg); err != nil {
panic(err)
}
if err := p.VerboseEqual(msg); err != nil {
t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err)
}
}
示例9: ReadMsg
func (this *uint32Reader) ReadMsg(msg proto.Message) error {
if _, err := io.ReadFull(this.r, this.lenBuf); err != nil {
return err
}
length32 := this.byteOrder.Uint32(this.lenBuf)
length := int(length32)
if length < 0 || length > this.maxSize {
return io.ErrShortBuffer
}
if length >= len(this.buf) {
this.buf = make([]byte, length)
}
_, err := io.ReadFull(this.r, this.buf[:length])
if err != nil {
return err
}
return proto.Unmarshal(this.buf[:length], msg)
}
示例10: TestFooProto
func TestFooProto(t *testing.T) {
popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
p := NewPopulatedFoo(popr, false)
data, err := dropbox_gogoprotobuf_proto.Marshal(p)
if err != nil {
panic(err)
}
msg := &Foo{}
if err := dropbox_gogoprotobuf_proto.Unmarshal(data, msg); err != nil {
panic(err)
}
for i := range data {
data[i] = byte(popr.Intn(256))
}
if !p.Equal(msg) {
t.Fatalf("%#v !Proto %#v", msg, p)
}
}
示例11: TestUnsafeIssue21
func TestUnsafeIssue21(t *testing.T) {
popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
msg1 := NewPopulatedNinRepNativeUnsafe(popr, true)
data1, err := proto.Marshal(msg1)
if err != nil {
panic(err)
}
packedmsg := &NinRepPackedNativeUnsafe{}
err = proto.Unmarshal(data1, packedmsg)
if err != nil {
panic(err)
}
if len(packedmsg.XXX_unrecognized) != 0 {
t.Fatalf("packed msg unmarshaled unrecognized fields, even though there aren't any")
}
if err := VerboseEqualUnsafe(msg1, packedmsg); err != nil {
t.Fatalf("%v", err)
}
}
示例12: BenchmarkEProtoUnmarshal
func BenchmarkEProtoUnmarshal(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 := github_com_dropbox_goprotoc_proto.Marshal(NewPopulatedE(popr, false))
if err != nil {
panic(err)
}
datas[i] = data
}
msg := &E{}
b.ResetTimer()
for i := 0; i < b.N; i++ {
total += len(datas[i%10000])
if err := github_com_dropbox_goprotoc_proto.Unmarshal(datas[i%10000], msg); err != nil {
panic(err)
}
}
b.SetBytes(int64(total / b.N))
}
示例13: TestOldWithGroup_Group2Proto
func TestOldWithGroup_Group2Proto(t *testing.T) {
popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
p := NewPopulatedOldWithGroup_Group2(popr, false)
data, err := dropbox_gogoprotobuf_proto.Marshal(p)
if err != nil {
panic(err)
}
msg := &OldWithGroup_Group2{}
if err := dropbox_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)
}
}
示例14: parseFile
func parseFile(filename string, includeSourceInfo bool, includeImports bool, paths ...string) (*descriptor.FileDescriptorSet, error) {
args := []string{"--proto_path=" + strings.Join(paths, ":")}
if includeSourceInfo {
args = append(args, "--include_source_info")
}
if includeImports {
args = append(args, "--include_imports")
}
args = append(args, "--descriptor_set_out=/dev/stdout")
args = append(args, filename)
cmd := exec.Command("protoc", args...)
data, err := cmd.CombinedOutput()
if err != nil {
return nil, &errCmd{data, err}
}
fileDesc := &descriptor.FileDescriptorSet{}
if err := proto.Unmarshal(data, fileDesc); err != nil {
return nil, err
}
return fileDesc, nil
}
示例15: ReadMsg
func (this *varintReader) ReadMsg(msg proto.Message) error {
firstLen, err := this.r.Read(this.lenBuf)
if err != nil {
return err
}
length64, lenLen := binary.Uvarint(this.lenBuf)
if lenLen <= 0 {
if lenLen == 0 {
return errSmallBuffer
}
return errLargeValue
}
msgLen := int(length64)
if len(this.buf) < msgLen {
this.buf = make([]byte, msgLen)
}
prefixN := copy(this.buf, this.lenBuf[lenLen:firstLen])
if _, err := io.ReadFull(this.r, this.buf[prefixN:msgLen]); err != nil {
return err
}
return proto.Unmarshal(this.buf[:msgLen], msg)
}