func JobToCapnp(j *Job) (bytes.Buffer, *capn.Segment) { seg := capn.NewBuffer(nil) z := schema.NewRootZ(seg) zjob := JobToCapnpSegment(j, seg) z.SetJob(zjob) buf := bytes.Buffer{} seg.WriteTo(&buf) return buf, seg }
func (js *JobServ) ServerToCapnp() (bytes.Buffer, *capn.Segment) { seg := capn.NewBuffer(nil) z := schema.NewRootZ(seg) zjs := schema.NewZgoqserver(seg) z.SetGoqserver(zjs) // nextjobid zjs.SetNextjobid(js.NextJobId) var i int var j *Job // runq if len(js.RunQ) > 0 { //fmt.Printf("len of Runq: %d, %#v\n", len(js.RunQ), js.RunQ) runq := schema.NewZjobList(seg, len(js.RunQ)) plistRunq := capn.PointerList(runq) i = 0 for _, j = range js.RunQ { zjob := JobToCapnpSegment(j, seg) plistRunq.Set(i, capn.Object(zjob)) i++ } zjs.SetRunq(runq) } // waitingjobs if len(js.WaitingJobs) > 0 { //fmt.Printf("len of WaitingJobs: %d, %#v\n", len(js.WaitingJobs), js.WaitingJobs) waitingjobs := schema.NewZjobList(seg, len(js.WaitingJobs)) plistWaitingjobs := capn.PointerList(waitingjobs) i = 0 for _, j = range js.WaitingJobs { zjob := JobToCapnpSegment(j, seg) plistWaitingjobs.Set(i, capn.Object(zjob)) i++ } zjs.SetWaitingjobs(waitingjobs) } // counters zjs.SetFinishedjobscount(js.FinishedJobsCount) zjs.SetBadsgtcount(js.BadSgtCount) zjs.SetCancelledjobcount(js.CancelledJobCount) zjs.SetBadnoncecount(js.BadNonceCount) // FinishedRing -> finishedjobs if len(js.FinishedRing) > 0 { finishedjobs := schema.NewZjobList(seg, len(js.FinishedRing)) plistFinishedjobs := capn.PointerList(finishedjobs) i = 0 for _, j = range js.FinishedRing { zjob := JobToCapnpSegment(j, seg) plistFinishedjobs.Set(i, capn.Object(zjob)) i++ } zjs.SetFinishedjobs(finishedjobs) } buf := bytes.Buffer{} seg.WriteTo(&buf) return buf, seg }