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() }
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) }) }) }
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) }) }) }
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) }) }) }
func (s Z_List) ToArray() []Z { return *(*[]Z)(unsafe.Pointer(C.PointerList(s).ToArray())) }
func (s Z_List) Len() int { return C.PointerList(s).Len() }
func (s Routable_List) ToArray() []Routable { return *(*[]Routable)(unsafe.Pointer(C.PointerList(s).ToArray())) }
func (s Routable_List) Len() int { return C.PointerList(s).Len() }
func (s Request_List) At(i int) Request { return Request(C.PointerList(s).At(i).ToStruct()) }
func (s Ranges_List) ToArray() []Ranges { return *(*[]Ranges)(unsafe.Pointer(C.PointerList(s).ToArray())) }
func (s StatisticalRecords_List) At(i int) StatisticalRecords { return StatisticalRecords(C.PointerList(s).At(i).ToStruct()) }
func (s StatisticalRecords_List) Len() int { return C.PointerList(s).Len() }
func (s Records_List) ToArray() []Records { return *(*[]Records)(unsafe.Pointer(C.PointerList(s).ToArray())) }
func (s Records_List) At(i int) Records { return Records(C.PointerList(s).At(i).ToStruct()) }
func (s Records_List) Len() int { return C.PointerList(s).Len() }
func (s Ranges_List) Len() int { return C.PointerList(s).Len() }
func (s Ranges_List) At(i int) Ranges { return Ranges(C.PointerList(s).At(i).ToStruct()) }
func (s StatisticalRecords_List) ToArray() []StatisticalRecords { return *(*[]StatisticalRecords)(unsafe.Pointer(C.PointerList(s).ToArray())) }
func (s Request_List) Len() int { return C.PointerList(s).Len() }
func (s Versions_List) Len() int { return C.PointerList(s).Len() }
func (s Request_List) ToArray() []Request { return *(*[]Request)(unsafe.Pointer(C.PointerList(s).ToArray())) }
func (s Versions_List) At(i int) Versions { return Versions(C.PointerList(s).At(i).ToStruct()) }
func (s Routable_List) At(i int) Routable { return Routable(C.PointerList(s).At(i).ToStruct()) }
func (s Versions_List) ToArray() []Versions { return *(*[]Versions)(unsafe.Pointer(C.PointerList(s).ToArray())) }
func (s Routable_List) Set(i int, item Routable) { C.PointerList(s).Set(i, C.Object(item)) }
func (s ChangedRange_List) Len() int { return C.PointerList(s).Len() }
func (s Z_List) At(i int) Z { return Z(C.PointerList(s).At(i).ToStruct()) }
func (s ChangedRange_List) At(i int) ChangedRange { return ChangedRange(C.PointerList(s).At(i).ToStruct()) }
func (s Z_List) Set(i int, item Z) { C.PointerList(s).Set(i, C.Object(item)) }
func (s ChangedRange_List) ToArray() []ChangedRange { return *(*[]ChangedRange)(unsafe.Pointer(C.PointerList(s).ToArray())) }