Ejemplo n.º 1
0
func zdateFilledSegment(n int, packed bool) (*capn.Segment, []byte) {
	seg := capn.NewBuffer(nil)
	z := air.NewRootZ(seg)
	list := air.NewZdateList(seg, n)
	// hand added a Set() method to messages_test.go, so plist not needed
	plist := capn.PointerList(list)

	for i := 0; i < n; i++ {
		d := air.NewZdate(seg)
		d.SetMonth(12)
		d.SetDay(7)
		d.SetYear(int16(2004 + i))
		plist.Set(i, capn.Object(d))
		//list.Set(i, d)
	}
	z.SetZdatevec(list)

	buf := bytes.Buffer{}
	if packed {
		seg.WriteToPacked(&buf)
	} else {
		seg.WriteTo(&buf)
	}
	return seg, buf.Bytes()
}
Ejemplo n.º 2
0
func TestV0ListofEmptyShouldMatchCapnp(t *testing.T) {

	exp := CapnpEncode("(mylist = [(),()])", "HoldsVerEmptyList")

	cv.Convey("Given an empty struct with 0 data/0 ptr fields", t, func() {
		cv.Convey("then a list of 2 empty structs should match the capnp representation", func() {

			seg := capn.NewBuffer(nil)
			scratch := capn.NewBuffer(nil)
			holder := air.NewRootHoldsVerEmptyList(seg)

			ShowSeg("          after NewRootHoldsVerEmptyList(seg), segment seg is:", seg)

			elist := air.NewVerEmptyList(seg, 2)
			plist := capn.PointerList(elist)

			ShowSeg("          pre NewVerEmpty(scratch), segment seg is:", seg)

			e0 := air.NewVerEmpty(scratch)
			e1 := air.NewVerEmpty(scratch)
			plist.Set(0, capn.Object(e0))
			plist.Set(1, capn.Object(e1))

			ShowSeg("          pre SetMylist, segment seg is:", seg)

			fmt.Printf("Then we do the SetMylist():\n")
			holder.SetMylist(elist)

			// save
			buf := bytes.Buffer{}
			seg.WriteTo(&buf)
			act := buf.Bytes()
			save(act, "my.act.holder.elist")

			// show
			ShowSeg("          actual:\n", seg)

			fmt.Printf("act decoded by capnp: '%s'\n", string(CapnpDecode(act, "HoldsVerEmptyList")))

			fmt.Printf("expected:\n")
			ShowBytes(exp, 10)
			fmt.Printf("exp decoded by capnp: '%s'\n", string(CapnpDecode(exp, "HoldsVerEmptyList")))

			cv.So(act, cv.ShouldResemble, exp)
		})
	})
}
Ejemplo n.º 3
0
func TestZserverWithOneEmptyJob(t *testing.T) {

	exp := CapnpEncode(`(waitingjobs = [()])`, "Zserver")

	cv.Convey("Given an Zserver with one empty job", t, func() {
		cv.Convey("then the go-capnproto serialization should match the capnp c++ serialization", func() {

			seg := capn.NewBuffer(nil)
			scratch := capn.NewBuffer(nil)
			server := air.NewRootZserver(seg)

			joblist := air.NewZjobList(seg, 1)
			plist := capn.PointerList(joblist)

			ShowSeg("          pre NewZjob, segment seg is:", seg)

			zjob := air.NewZjob(scratch)
			plist.Set(0, capn.Object(zjob))

			ShowSeg("          pre SetWaitingjobs, segment seg is:", seg)

			fmt.Printf("Then we do the SetWaitingjobs:\n")
			server.SetWaitingjobs(joblist)

			// save
			buf := bytes.Buffer{}
			seg.WriteTo(&buf)
			act := buf.Bytes()
			save(act, "my.act.zserver")

			// show
			ShowSeg("          actual:\n", seg)

			fmt.Printf("act decoded by capnp: '%s'\n", string(CapnpDecode(act, "Zserver")))

			fmt.Printf("expected:\n")
			ShowBytes(exp, 10)
			fmt.Printf("exp decoded by capnp: '%s'\n", string(CapnpDecode(exp, "Zserver")))

			cv.So(act, cv.ShouldResemble, exp)
		})
	})
}
Ejemplo n.º 4
0
func TestZserverWithOneFullJob(t *testing.T) {

	exp := CapnpEncode(`(waitingjobs = [(cmd = "abc", args = ["xyz"])])`, "Zserver")

	cv.Convey("Given an Zserver with one empty job", t, func() {
		cv.Convey("then the go-capnproto serialization should match the capnp c++ serialization", func() {

			seg := capn.NewBuffer(nil)
			scratch := capn.NewBuffer(nil)

			server := air.NewRootZserver(seg)

			joblist := air.NewZjobList(seg, 1)
			plist := capn.PointerList(joblist)

			zjob := air.NewZjob(scratch)
			zjob.SetCmd("abc")
			tl := scratch.NewTextList(1)
			tl.Set(0, "xyz")
			zjob.SetArgs(tl)

			plist.Set(0, capn.Object(zjob))

			server.SetWaitingjobs(joblist)

			buf := bytes.Buffer{}
			seg.WriteTo(&buf)

			act := buf.Bytes()
			fmt.Printf("          actual:\n")
			ShowBytes(act, 10)
			fmt.Printf("act decoded by capnp: '%s'\n", string(CapnpDecode(act, "Zserver")))
			save(act, "myact")

			fmt.Printf("expected:\n")
			ShowBytes(exp, 10)
			fmt.Printf("exp decoded by capnp: '%s'\n", string(CapnpDecode(exp, "Zserver")))
			save(exp, "myexp")

			cv.So(act, cv.ShouldResemble, exp)
		})
	})
}
Ejemplo n.º 5
0
func RWTestGoToCapn(seg *capn.Segment, src *RWTest) air.RWTestCapn {
	dest := air.AutoNewRWTestCapn(seg)

	// NestMatrix -> Nester1Capn (go slice to capn list)
	if len(src.NestMatrix) > 0 {
		//typedList := air.NewNester1CapnList(seg, len(src.NestMatrix))
		plist := seg.NewPointerList(len(src.NestMatrix))
		i := 0
		for _, ele := range src.NestMatrix {
			//plist.Set(i, capn.Object(Nester1GoToCapn(seg, &ele)))
			r := capn.Object(SliceNester1ToNester1CapnList(seg, ele))
			plist.Set(i, r)
			i++
		}
		//dest.SetNestMatrix(typedList)
		dest.SetNestMatrix(plist)
	}

	return dest
}
Ejemplo n.º 6
0
func (s Z) SetMatch(v Match) { C.Struct(s).Set16(0, 1); C.Struct(s).SetObject(0, C.Object(v)) }
Ejemplo n.º 7
0
func (s Routable_List) Set(i int, item Routable) { C.PointerList(s).Set(i, C.Object(item)) }
Ejemplo n.º 8
0
func (s Request) SetInsertValues(v CmdInsertValues) {
	C.Struct(s).Set16(8, 6)
	C.Struct(s).SetObject(0, C.Object(v))
}
Ejemplo n.º 9
0
func (s Request) SetQueryChangedRanges(v CmdQueryChangedRanges) {
	C.Struct(s).Set16(8, 5)
	C.Struct(s).SetObject(0, C.Object(v))
}
Ejemplo n.º 10
0
func (s Versions) SetUuids(v C.DataList)      { C.Struct(s).SetObject(0, C.Object(v)) }
Ejemplo n.º 11
0
func (s Request) SetQueryNearestValue(v CmdQueryNearestValue) {
	C.Struct(s).Set16(8, 4)
	C.Struct(s).SetObject(0, C.Object(v))
}
Ejemplo n.º 12
0
func (s CmdQueryVersion) SetUuids(v C.DataList) { C.Struct(s).SetObject(0, C.Object(v)) }
Ejemplo n.º 13
0
func (s MigrationElement_List) Set(i int, item MigrationElement) {
	C.PointerList(s).Set(i, C.Object(item))
}
Ejemplo n.º 14
0
func (s MigrationElement) SetVars(v Var_List) { C.Struct(s).SetObject(1, C.Object(v)) }
Ejemplo n.º 15
0
func (s MigrationElement) SetTxn(v Txn)       { C.Struct(s).SetObject(0, C.Object(v)) }
Ejemplo n.º 16
0
func (s Request) SetQueryVersion(v CmdQueryVersion) {
	C.Struct(s).Set16(8, 3)
	C.Struct(s).SetObject(0, C.Object(v))
}
Ejemplo n.º 17
0
func (s Records) SetValues(v Record_List)  { C.Struct(s).SetObject(0, C.Object(v)) }
Ejemplo n.º 18
0
func (s Request) SetQueryStandardValues(v CmdQueryStandardValues) {
	C.Struct(s).Set16(8, 1)
	C.Struct(s).SetObject(0, C.Object(v))
}
Ejemplo n.º 19
0
func (s StatisticalRecords) SetValues(v StatisticalRecord_List) { C.Struct(s).SetObject(0, C.Object(v)) }
Ejemplo n.º 20
0
func (s CmdInsertValues) SetValues(v Record_List) { C.Struct(s).SetObject(1, C.Object(v)) }
Ejemplo n.º 21
0
func (s Versions) SetVersions(v C.UInt64List) { C.Struct(s).SetObject(1, C.Object(v)) }
Ejemplo n.º 22
0
func (s Request) SetQueryStatisticalValues(v CmdQueryStatisticalValues) {
	C.Struct(s).Set16(8, 2)
	C.Struct(s).SetObject(0, C.Object(v))
}
Ejemplo n.º 23
0
func (s Ranges) SetValues(v ChangedRange_List) { C.Struct(s).SetObject(0, C.Object(v)) }
Ejemplo n.º 24
0
func (s Response) SetRecords(v Records) {
	C.Struct(s).Set16(10, 1)
	C.Struct(s).SetObject(0, C.Object(v))
}
Ejemplo n.º 25
0
func (s Request) SetDeleteValues(v CmdDeleteValues) {
	C.Struct(s).Set16(8, 7)
	C.Struct(s).SetObject(0, C.Object(v))
}
Ejemplo n.º 26
0
func (s Response) SetStatisticalRecords(v StatisticalRecords) {
	C.Struct(s).Set16(10, 2)
	C.Struct(s).SetObject(0, C.Object(v))
}
Ejemplo n.º 27
0
func (s Z) SetProgressupdate(v ProgressUpdate) {
	C.Struct(s).Set16(0, 0)
	C.Struct(s).SetObject(0, C.Object(v))
}
Ejemplo n.º 28
0
func (s Response) SetVersionList(v Versions) {
	C.Struct(s).Set16(10, 3)
	C.Struct(s).SetObject(0, C.Object(v))
}
Ejemplo n.º 29
0
func (s Z_List) Set(i int, item Z)         { C.PointerList(s).Set(i, C.Object(item)) }
Ejemplo n.º 30
0
func (s Response) SetChangedRngList(v Ranges) {
	C.Struct(s).Set16(10, 4)
	C.Struct(s).SetObject(0, C.Object(v))
}