Beispiel #1
0
func zfill(c air.Z, g *Z) error {
	switch g.Which {
	case air.Z_Which_f64:
		c.SetF64(g.F64)
	case air.Z_Which_f32:
		c.SetF32(g.F32)
	case air.Z_Which_i64:
		c.SetI64(g.I64)
	case air.Z_Which_i32:
		c.SetI32(g.I32)
	case air.Z_Which_i16:
		c.SetI16(g.I16)
	case air.Z_Which_i8:
		c.SetI8(g.I8)
	case air.Z_Which_u64:
		c.SetU64(g.U64)
	case air.Z_Which_u32:
		c.SetU32(g.U32)
	case air.Z_Which_u16:
		c.SetU16(g.U16)
	case air.Z_Which_u8:
		c.SetU8(g.U8)
	case air.Z_Which_bool:
		c.SetBool(g.Bool)
	case air.Z_Which_text:
		return c.SetText(g.Text)
	case air.Z_Which_blob:
		return c.SetBlob(g.Blob)
	case air.Z_Which_f64vec:
		if g.F64vec == nil {
			return c.SetF64vec(capnp.Float64List{})
		}
		fv, err := c.NewF64vec(int32(len(g.F64vec)))
		if err != nil {
			return err
		}
		for i, f := range g.F64vec {
			fv.Set(i, f)
		}
	case air.Z_Which_f32vec:
		if g.F32vec == nil {
			return c.SetF32vec(capnp.Float32List{})
		}
		fv, err := c.NewF32vec(int32(len(g.F32vec)))
		if err != nil {
			return err
		}
		for i, f := range g.F32vec {
			fv.Set(i, f)
		}
	case air.Z_Which_i64vec:
		if g.I64vec == nil {
			return c.SetI64vec(capnp.Int64List{})
		}
		iv, err := c.NewI64vec(int32(len(g.I64vec)))
		if err != nil {
			return err
		}
		for i, n := range g.I64vec {
			iv.Set(i, n)
		}
	case air.Z_Which_i8vec:
		if g.I8vec == nil {
			return c.SetI8vec(capnp.Int8List{})
		}
		iv, err := c.NewI8vec(int32(len(g.I8vec)))
		if err != nil {
			return err
		}
		for i, n := range g.I8vec {
			iv.Set(i, n)
		}
	case air.Z_Which_u64vec:
		if g.U64vec == nil {
			return c.SetU64vec(capnp.UInt64List{})
		}
		uv, err := c.NewU64vec(int32(len(g.U64vec)))
		if err != nil {
			return err
		}
		for i, n := range g.U64vec {
			uv.Set(i, n)
		}
	case air.Z_Which_u8vec:
		if g.U8vec == nil {
			return c.SetU8vec(capnp.UInt8List{})
		}
		uv, err := c.NewU8vec(int32(len(g.U8vec)))
		if err != nil {
			return err
		}
		for i, n := range g.U8vec {
			uv.Set(i, n)
		}
	case air.Z_Which_boolvec:
		if g.Boolvec == nil {
			return c.SetBoolvec(capnp.BitList{})
		}
		vec, err := c.NewBoolvec(int32(len(g.Boolvec)))
		if err != nil {
			return err
		}
		for i, v := range g.Boolvec {
			vec.Set(i, v)
		}
	case air.Z_Which_datavec:
		if g.Datavec == nil {
			return c.SetDatavec(capnp.DataList{})
		}
		vec, err := c.NewDatavec(int32(len(g.Datavec)))
		if err != nil {
			return err
		}
		for i, v := range g.Datavec {
			if err := vec.Set(i, v); err != nil {
				return err
			}
		}
	case air.Z_Which_textvec:
		if g.Textvec == nil {
			return c.SetTextvec(capnp.TextList{})
		}
		vec, err := c.NewTextvec(int32(len(g.Textvec)))
		if err != nil {
			return err
		}
		for i, v := range g.Textvec {
			if err := vec.Set(i, v); err != nil {
				return err
			}
		}
	case air.Z_Which_zvec:
		if g.Zvec == nil {
			return c.SetZvec(air.Z_List{})
		}
		vec, err := c.NewZvec(int32(len(g.Zvec)))
		if err != nil {
			return err
		}
		for i, z := range g.Zvec {
			if err := zfill(vec.At(i), z); err != nil {
				return err
			}
		}
	case air.Z_Which_zvecvec:
		if g.Zvecvec == nil {
			return c.SetZvecvec(capnp.PointerList{})
		}
		vv, err := c.NewZvecvec(int32(len(g.Zvecvec)))
		if err != nil {
			return err
		}
		for i, zz := range g.Zvecvec {
			v, err := air.NewZ_List(vv.Segment(), int32(len(zz)))
			if err != nil {
				return err
			}
			if err := vv.SetPtr(i, v.ToPtr()); err != nil {
				return err
			}
			for j, z := range zz {
				if err := zfill(v.At(j), z); err != nil {
					return err
				}
			}
		}
	case air.Z_Which_planebase:
		if g.Planebase == nil {
			return c.SetPlanebase(air.PlaneBase{})
		}
		pb, err := c.NewPlanebase()
		if err != nil {
			return err
		}
		if err := pb.SetName(g.Planebase.Name); err != nil {
			return err
		}
		if g.Planebase.Homes != nil {
			homes, err := pb.NewHomes(int32(len(g.Planebase.Homes)))
			if err != nil {
				return err
			}
			for i := range g.Planebase.Homes {
				homes.Set(i, g.Planebase.Homes[i])
			}
		}
		pb.SetRating(g.Planebase.Rating)
		pb.SetCanFly(g.Planebase.CanFly)
		pb.SetCapacity(g.Planebase.Capacity)
		pb.SetMaxSpeed(g.Planebase.MaxSpeed)
	case air.Z_Which_airport:
		c.SetAirport(g.Airport)
	case air.Z_Which_grp:
		c.SetGrp()
		if g.Grp != nil {
			c.Grp().SetFirst(g.Grp.First)
			c.Grp().SetSecond(g.Grp.Second)
		}
	default:
		return fmt.Errorf("zfill: unknown type: %v", g.Which)
	}
	return nil
}