Пример #1
0
func ExampleReadFromStream() {
	s := capn.NewBuffer(nil)
	d := air.NewRootZdate(s)
	d.SetYear(2004)
	d.SetMonth(12)
	d.SetDay(7)
	buf := bytes.Buffer{}
	s.WriteTo(&buf)

	fmt.Println(hex.EncodeToString(buf.Bytes()))

	// Read
	s, err := capn.ReadFromStream(&buf, nil)
	if err != nil {
		fmt.Printf("read error %v\n", err)
		return
	}
	d = air.ReadRootZdate(s)
	fmt.Printf("year %d, month %d, day %d\n", d.Year(), d.Month(), d.Day())
}
Пример #2
0
// actually return n segments back-to-back.
// WriteTo will automatically add the stream header word with message length.
//
func zdateReaderNBackToBack(n int, packed bool) *bytes.Reader {

	buf := bytes.Buffer{}

	for i := 0; i < n; i++ {
		seg := capn.NewBuffer(nil)
		d := air.NewRootZdate(seg)
		d.SetMonth(12)
		d.SetDay(7)
		d.SetYear(int16(2004 + i))

		if packed {
			seg.WriteToPacked(&buf)
		} else {
			seg.WriteTo(&buf)
		}
	}

	return bytes.NewReader(buf.Bytes())
}