當前位置: 首頁>>代碼示例>>Golang>>正文


Golang aircraftlib.NewRootZ函數代碼示例

本文整理匯總了Golang中zombiezen/com/go/capnproto2/internal/aircraftlib.NewRootZ函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewRootZ函數的具體用法?Golang NewRootZ怎麽用?Golang NewRootZ使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了NewRootZ函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: TestInsert_StructListNoPtr

func TestInsert_StructListNoPtr(t *testing.T) {
	_, seg, err := capnp.NewMessage(capnp.SingleSegment(nil))
	if err != nil {
		t.Fatalf("NewMessage: %v", err)
	}
	z, err := air.NewRootZ(seg)
	if err != nil {
		t.Fatalf("NewRootZ: %v", err)
	}
	bz := &StructZ{Which: air.Z_Which_zvec, Zvec: []Z{
		{Which: air.Z_Which_i64, I64: 123},
	}}
	err = Insert(air.Z_TypeID, z.Struct, bz)
	if err != nil {
		t.Errorf("Insert(%s) error: %v", zpretty.Sprint(bz), err)
	}
	want := &Z{Which: air.Z_Which_zvec, Zvec: []*Z{
		{Which: air.Z_Which_i64, I64: 123},
	}}
	if equal, err := zequal(want, z); err != nil {
		t.Errorf("Insert(%s) compare err: %v", zpretty.Sprint(bz), err)
	} else if !equal {
		t.Errorf("Insert(%s) produced %v", zpretty.Sprint(bz), z)
	}
}
開發者ID:zombiezen,項目名稱:go-capnproto2,代碼行數:25,代碼來源:pogs_test.go

示例2: TestExtract

func TestExtract(t *testing.T) {
	for _, test := range goodTests {
		_, seg, err := capnp.NewMessage(capnp.SingleSegment(nil))
		if err != nil {
			t.Errorf("NewMessage for %s: %v", zpretty.Sprint(test), err)
			continue
		}
		z, err := air.NewRootZ(seg)
		if err != nil {
			t.Errorf("NewRootZ for %s: %v", zpretty.Sprint(test), err)
			continue
		}
		if err := zfill(z, &test); err != nil {
			t.Errorf("zfill for %s: %v", zpretty.Sprint(test), err)
			continue
		}
		out := new(Z)
		if err := Extract(out, air.Z_TypeID, z.Struct); err != nil {
			t.Errorf("Extract(%v) error: %v", z, err)
		}
		if !reflect.DeepEqual(out, &test) {
			t.Errorf("Extract(%v) produced %s; want %s", z, zpretty.Sprint(out), zpretty.Sprint(test))
		}
	}
}
開發者ID:zombiezen,項目名稱:go-capnproto2,代碼行數:25,代碼來源:pogs_test.go

示例3: TestExtract_StructListNoPtr

func TestExtract_StructListNoPtr(t *testing.T) {
	_, seg, err := capnp.NewMessage(capnp.SingleSegment(nil))
	if err != nil {
		t.Fatalf("NewMessage: %v", err)
	}
	z, err := air.NewRootZ(seg)
	if err != nil {
		t.Fatalf("NewRootZ: %v", err)
	}
	err = zfill(z, &Z{Which: air.Z_Which_zvec, Zvec: []*Z{
		{Which: air.Z_Which_i64, I64: 123},
	}})
	if err != nil {
		t.Fatalf("zfill: %v", err)
	}
	out := new(StructZ)
	if err := Extract(out, air.Z_TypeID, z.Struct); err != nil {
		t.Errorf("Extract(%v) error: %v", z, err)
	}
	want := &StructZ{Which: air.Z_Which_zvec, Zvec: []Z{
		{Which: air.Z_Which_i64, I64: 123},
	}}
	if !reflect.DeepEqual(out, want) {
		t.Errorf("Extract(%v) produced %s; want %s", z, zpretty.Sprint(out), zpretty.Sprint(want))
	}
}
開發者ID:zombiezen,項目名稱:go-capnproto2,代碼行數:26,代碼來源:pogs_test.go

示例4: zdateFilledMessage

func zdateFilledMessage(t testing.TB, n int32) *capnp.Message {
	msg, seg, err := capnp.NewMessage(capnp.SingleSegment(nil))
	if err != nil {
		t.Fatal(err)
	}
	z, err := air.NewRootZ(seg)
	if err != nil {
		t.Fatal(err)
	}
	list, err := air.NewZdate_List(seg, n)
	if err != nil {
		t.Fatal(err)
	}

	for i := 0; i < int(n); i++ {
		d, err := air.NewZdate(seg)
		if err != nil {
			t.Fatal(err)
		}
		d.SetMonth(12)
		d.SetDay(7)
		d.SetYear(int16(2004 + i))
		list.Set(i, d)
	}
	z.SetZdatevec(list)

	return msg
}
開發者ID:startupit69,項目名稱:go-capnproto2,代碼行數:28,代碼來源:integrationutil_test.go

示例5: zdataFilledSegment

func zdataFilledSegment(n int) (*capnp.Segment, []byte) {
	msg, seg, err := capnp.NewMessage(capnp.SingleSegment(nil))
	if err != nil {
		panic(err)
	}
	z, err := air.NewRootZ(seg)
	if err != nil {
		panic(err)
	}
	d, err := air.NewZdata(seg)
	if err != nil {
		panic(err)
	}

	b := make([]byte, n)
	for i := 0; i < len(b); i++ {
		b[i] = byte(i)
	}
	d.SetData(b)
	z.SetZdata(d)

	buf, err := msg.Marshal()
	if err != nil {
		panic(err)
	}
	return seg, buf
}
開發者ID:hodduc,項目名稱:go-capnproto2,代碼行數:27,代碼來源:integrationutil_test.go

示例6: TestExtract_Tags

func TestExtract_Tags(t *testing.T) {
	tests := []struct {
		name string
		z    Z
		tagz TagZ
	}{
		{
			name: "renamed field",
			z:    Z{Which: air.Z_Which_f64, F64: 3.5},
			tagz: TagZ{Which: air.Z_Which_f64, Float64: 3.5},
		},
		{
			name: "omitted field",
			z:    Z{Which: air.Z_Which_i64, I64: 42},
			tagz: TagZ{Which: air.Z_Which_i64},
		},
		{
			name: "field with overlapping name",
			z:    Z{Which: air.Z_Which_bool, Bool: true},
			tagz: TagZ{Which: air.Z_Which_bool, U8: true},
		},
	}
	for _, test := range tests {
		_, seg, err := capnp.NewMessage(capnp.SingleSegment(nil))
		if err != nil {
			t.Errorf("%s: NewMessage: %v", test.name, err)
			continue
		}
		z, err := air.NewRootZ(seg)
		if err != nil {
			t.Errorf("%s: NewRootZ: %v", test.name, err)
			continue
		}
		if err := zfill(z, &test.z); err != nil {
			t.Errorf("%s: zfill: %v", test.name, err)
			continue
		}
		out := new(TagZ)
		if err := Extract(out, air.Z_TypeID, z.Struct); err != nil {
			t.Errorf("%s: Extract error: %v", test.name, err)
		}
		if !reflect.DeepEqual(out, &test.tagz) {
			t.Errorf("%s: Extract produced %s; want %s", test.name, zpretty.Sprint(out), zpretty.Sprint(test.tagz))
		}
	}
}
開發者ID:zombiezen,項目名稱:go-capnproto2,代碼行數:46,代碼來源:pogs_test.go

示例7: TestExtract_WhichTagMismatch

func TestExtract_WhichTagMismatch(t *testing.T) {
	_, seg, err := capnp.NewMessage(capnp.SingleSegment(nil))
	if err != nil {
		t.Fatalf("NewMessage: %v", err)
	}
	z, err := air.NewRootZ(seg)
	if err != nil {
		t.Fatalf("NewRootZ: %v", err)
	}
	if err := zfill(z, &Z{Which: air.Z_Which_i64, I64: 42}); err != nil {
		t.Fatalf("zfill: %v", err)
	}
	out := new(ZBool)
	if err := Extract(out, air.Z_TypeID, z.Struct); err == nil {
		t.Error("Extract did not return an error")
	}
}
開發者ID:zombiezen,項目名稱:go-capnproto2,代碼行數:17,代碼來源:pogs_test.go

示例8: TestInsert_Tags

func TestInsert_Tags(t *testing.T) {
	tests := []struct {
		name string
		tagz TagZ
		z    Z
	}{
		{
			name: "renamed field",
			tagz: TagZ{Which: air.Z_Which_f64, Float64: 3.5},
			z:    Z{Which: air.Z_Which_f64, F64: 3.5},
		},
		{
			name: "omitted field",
			tagz: TagZ{Which: air.Z_Which_i64, I64: 42},
			z:    Z{Which: air.Z_Which_i64, I64: 0},
		},
		{
			name: "field with overlapping name",
			tagz: TagZ{Which: air.Z_Which_bool, U8: true},
			z:    Z{Which: air.Z_Which_bool, Bool: true},
		},
	}
	for _, test := range tests {
		_, seg, err := capnp.NewMessage(capnp.SingleSegment(nil))
		if err != nil {
			t.Errorf("%s: NewMessage: %v", test.name, err)
			continue
		}
		z, err := air.NewRootZ(seg)
		if err != nil {
			t.Errorf("%s: NewRootZ: %v", test.name, err)
			continue
		}
		err = Insert(air.Z_TypeID, z.Struct, &test.tagz)
		if err != nil {
			t.Errorf("%s: Insert(%s) error: %v", test.name, zpretty.Sprint(test.tagz), err)
		}
		if equal, err := zequal(&test.z, z); err != nil {
			t.Errorf("%s: Insert(%s) compare err: %v", test.name, zpretty.Sprint(test.tagz), err)
		} else if !equal {
			t.Errorf("%s: Insert(%s) produced %v", test.name, zpretty.Sprint(test.tagz), z)
		}
	}
}
開發者ID:zombiezen,項目名稱:go-capnproto2,代碼行數:44,代碼來源:pogs_test.go

示例9: TestExtract_WhichTag

func TestExtract_WhichTag(t *testing.T) {
	_, seg, err := capnp.NewMessage(capnp.SingleSegment(nil))
	if err != nil {
		t.Fatalf("NewMessage: %v", err)
	}
	z, err := air.NewRootZ(seg)
	if err != nil {
		t.Fatalf("NewRootZ: %v", err)
	}
	if err := zfill(z, &Z{Which: air.Z_Which_bool, Bool: true}); err != nil {
		t.Fatalf("zfill: %v", err)
	}
	out := new(ZBool)
	if err := Extract(out, air.Z_TypeID, z.Struct); err != nil {
		t.Errorf("Extract error: %v", err)
	}
	if !out.Bool {
		t.Errorf("Extract produced %s; want %s", zpretty.Sprint(out), zpretty.Sprint(&ZBool{Bool: true}))
	}
}
開發者ID:zombiezen,項目名稱:go-capnproto2,代碼行數:20,代碼來源:pogs_test.go

示例10: TestInsert_StructNoPtr

func TestInsert_StructNoPtr(t *testing.T) {
	_, seg, err := capnp.NewMessage(capnp.SingleSegment(nil))
	if err != nil {
		t.Fatalf("NewMessage: %v", err)
	}
	z, err := air.NewRootZ(seg)
	if err != nil {
		t.Fatalf("NewRootZ: %v", err)
	}
	bz := &StructZ{Which: air.Z_Which_planebase, Planebase: PlaneBase{Name: "foo"}}
	err = Insert(air.Z_TypeID, z.Struct, bz)
	if err != nil {
		t.Errorf("Insert(%s) error: %v", zpretty.Sprint(bz), err)
	}
	want := &Z{Which: air.Z_Which_planebase, Planebase: &PlaneBase{Name: "foo"}}
	if equal, err := zequal(want, z); err != nil {
		t.Errorf("Insert(%s) compare err: %v", zpretty.Sprint(bz), err)
	} else if !equal {
		t.Errorf("Insert(%s) produced %v", zpretty.Sprint(bz), z)
	}
}
開發者ID:zombiezen,項目名稱:go-capnproto2,代碼行數:21,代碼來源:pogs_test.go

示例11: TestInsert_StringListBytes

func TestInsert_StringListBytes(t *testing.T) {
	_, seg, err := capnp.NewMessage(capnp.SingleSegment(nil))
	if err != nil {
		t.Fatalf("NewMessage: %v", err)
	}
	z, err := air.NewRootZ(seg)
	if err != nil {
		t.Fatalf("NewRootZ: %v", err)
	}
	bz := &BytesZ{Which: air.Z_Which_textvec, Textvec: [][]byte{[]byte("Holmes"), []byte("Watson")}}
	err = Insert(air.Z_TypeID, z.Struct, bz)
	if err != nil {
		t.Errorf("Insert(%s) error: %v", zpretty.Sprint(bz), err)
	}
	want := &Z{Which: air.Z_Which_textvec, Textvec: []string{"Holmes", "Watson"}}
	if equal, err := zequal(want, z); err != nil {
		t.Errorf("Insert(%s) compare err: %v", zpretty.Sprint(bz), err)
	} else if !equal {
		t.Errorf("Insert(%s) produced %v", zpretty.Sprint(bz), z)
	}
}
開發者ID:zombiezen,項目名稱:go-capnproto2,代碼行數:21,代碼來源:pogs_test.go

示例12: TestInsert_StringBytes

func TestInsert_StringBytes(t *testing.T) {
	_, seg, err := capnp.NewMessage(capnp.SingleSegment(nil))
	if err != nil {
		t.Fatalf("NewMessage: %v", err)
	}
	z, err := air.NewRootZ(seg)
	if err != nil {
		t.Fatalf("NewRootZ: %v", err)
	}
	bz := &BytesZ{Which: air.Z_Which_text, Text: []byte("Hello, World!")}
	err = Insert(air.Z_TypeID, z.Struct, bz)
	if err != nil {
		t.Errorf("Insert(%s) error: %v", zpretty.Sprint(bz), err)
	}
	want := &Z{Which: air.Z_Which_text, Text: "Hello, World!"}
	if equal, err := zequal(want, z); err != nil {
		t.Errorf("Insert(%s) compare err: %v", zpretty.Sprint(bz), err)
	} else if !equal {
		t.Errorf("Insert(%s) produced %v", zpretty.Sprint(bz), z)
	}
}
開發者ID:zombiezen,項目名稱:go-capnproto2,代碼行數:21,代碼來源:pogs_test.go

示例13: zdataFilledMessage

func zdataFilledMessage(t testing.TB, n int) *capnp.Message {
	msg, seg, err := capnp.NewMessage(capnp.SingleSegment(nil))
	if err != nil {
		t.Fatal(err)
	}
	z, err := air.NewRootZ(seg)
	if err != nil {
		t.Fatal(err)
	}
	d, err := air.NewZdata(seg)
	if err != nil {
		t.Fatal(err)
	}
	b := make([]byte, n)
	for i := 0; i < len(b); i++ {
		b[i] = byte(i)
	}
	d.SetData(b)
	z.SetZdata(d)
	return msg
}
開發者ID:startupit69,項目名稱:go-capnproto2,代碼行數:21,代碼來源:integrationutil_test.go

示例14: TestInsert_GroupNoPtr

func TestInsert_GroupNoPtr(t *testing.T) {
	_, seg, err := capnp.NewMessage(capnp.SingleSegment(nil))
	if err != nil {
		t.Fatalf("NewMessage: %v", err)
	}
	z, err := air.NewRootZ(seg)
	if err != nil {
		t.Fatalf("NewRootZ: %v", err)
	}
	bz := &StructZ{Which: air.Z_Which_grp, Grp: ZGroup{First: 123, Second: 456}}
	err = Insert(air.Z_TypeID, z.Struct, bz)
	if err != nil {
		t.Errorf("Insert(%s) error: %v", zpretty.Sprint(bz), err)
	}
	want := &Z{Which: air.Z_Which_grp, Grp: &ZGroup{First: 123, Second: 456}}
	if equal, err := zequal(want, z); err != nil {
		t.Errorf("Insert(%s) compare err: %v", zpretty.Sprint(bz), err)
	} else if !equal {
		t.Errorf("Insert(%s) produced %v", zpretty.Sprint(bz), z)
	}
}
開發者ID:zombiezen,項目名稱:go-capnproto2,代碼行數:21,代碼來源:pogs_test.go

示例15: makeMessage

func (blt bitListTest) makeMessage() (*capnp.Message, error) {
	msg, seg, err := capnp.NewMessage(capnp.SingleSegment(nil))
	if err != nil {
		return nil, err
	}
	z, err := air.NewRootZ(seg)
	if err != nil {
		return nil, err
	}
	list, err := capnp.NewBitList(seg, int32(len(blt.list)))
	if err != nil {
		return nil, err
	}
	for i := range blt.list {
		list.Set(i, blt.list[i])
	}
	if err := z.SetBoolvec(list); err != nil {
		return nil, err
	}
	return msg, nil
}
開發者ID:soargon,項目名稱:go-capnproto2,代碼行數:21,代碼來源:integration_test.go


注:本文中的zombiezen/com/go/capnproto2/internal/aircraftlib.NewRootZ函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。