Example #1
16
func (s StatusCode_List) ToArray() []StatusCode {
	return *(*[]StatusCode)(unsafe.Pointer(C.UInt16List(s).ToEnumArray()))
}
Example #2
1
func (s ElementSize_List) Len() int             { return C.UInt16List(s).Len() }
Example #3
1
func (s StatusCode_List) At(i int) StatusCode { return StatusCode(C.UInt16List(s).At(i)) }
Example #4
0
func (s ElementSize_List) At(i int) ElementSize { return ElementSize(C.UInt16List(s).At(i)) }
Example #5
0
func (s JobMsg_List) At(i int) JobMsg                { return JobMsg(C.UInt16List(s).At(i)) }
Example #6
0
func (s JobMsg_List) ToArray() []JobMsg {
	return *(*[]JobMsg)(unsafe.Pointer(C.UInt16List(s).ToEnumArray()))
}
Example #7
0
func (s VoteEnum_List) Set(i int, item VoteEnum) { C.UInt16List(s).Set(i, uint16(item)) }
Example #8
0
func (s JobMsg_List) Len() int                       { return C.UInt16List(s).Len() }
Example #9
0
func (s VoteEnum_List) At(i int) VoteEnum                { return VoteEnum(C.UInt16List(s).At(i)) }
Example #10
0
func (s VoteEnum_List) Len() int                         { return C.UInt16List(s).Len() }
Example #11
0
func (s Allocation) ActionIndices() C.UInt16List     { return C.UInt16List(C.Struct(s).GetObject(0)) }
Example #12
0
func (s Z) U16vec() C.UInt16List      { return C.UInt16List(C.Struct(s).GetObject(0)) }
Example #13
0
func ExampleAirplaneWrite() string {

	fname := "out.write_test.airplane.cpz"

	// make a brand new, empty segment (message)
	seg := capn.NewBuffer(nil)

	// If you want runtime-type identification, this is easily obtained. Just
	// wrap everything in a struct that contains a single anoymous union (e.g. struct Z).
	// Then always set a Z as the root object in you message/first segment.
	// The cost of the extra word of storage is usually worth it, as
	// then human readable output is easily obtained via a shell command such as
	//
	// $ cat binary.cpz | capnp decode aircraft.capnp Z
	//
	// If you need to conserve space, and know your content in advance, it
	// isn't necessary to use an anonymous union. Just supply the type name
	// in place of 'Z' in the decode command above.

	z := air.NewRootZ(seg) // root should be allocated first.
	// There must be only one root.

	// then non-root objects:
	aircraft := air.NewAircraft(seg)
	b737 := air.NewB737(seg)
	planebase := air.NewPlaneBase(seg)

	// how to create a list. Requires a cast at the moment.
	homes := air.NewAirportList(seg, 2)
	uint16list := capn.UInt16List(homes) // cast to the underlying type
	uint16list.Set(0, uint16(air.AIRPORT_JFK))
	uint16list.Set(1, uint16(air.AIRPORT_LAX))

	// set the primitive fields
	planebase.SetCanFly(true)
	planebase.SetName("Henrietta")
	planebase.SetRating(100)
	planebase.SetMaxSpeed(876) // km/hr
	// if we don't set capacity, it will get the default value, in this case 0.
	//planebase.SetCapacity(26020) // Liters fuel

	// set a list field
	planebase.SetHomes(homes)

	// wire up the pointers between objects
	b737.SetBase(planebase)
	aircraft.SetB737(b737)
	z.SetAircraft(aircraft)

	// ready to write

	// example of writing to memory
	buf := bytes.Buffer{}
	seg.WriteTo(&buf)

	// example of writing to file. Just use WriteTo().
	// We could have used SegToFile(seg, fname) from
	// util_test.go intead, but this makes it clear how easy it is.
	file, err := os.Create(fname)
	defer file.Close()
	if err != nil {
		panic(err)
	}
	seg.WriteTo(file)

	// readback and view that file in human readable format. Defined in util_test.go
	text, err := CapnFileToText(fname, "aircraftlib/aircraft.capnp", "")
	if err != nil {
		panic(err)
	}
	fmt.Printf("here is our aircraft:\n")
	fmt.Printf("%s\n", text)

	return text
}
Example #14
-1
func (s StatusCode_List) Len() int            { return C.UInt16List(s).Len() }