Ejemplo n.º 1
0
func SliceStringToTextList(seg *capn.Segment, m []string) capn.TextList {
	lst := seg.NewTextList(len(m))
	for i := range m {
		lst.Set(i, string(m[i]))
	}
	return lst
}
Ejemplo n.º 2
0
func SliceByteToUInt8List(seg *capn.Segment, m []byte) capn.UInt8List {
	lst := seg.NewUInt8List(len(m))
	for i := range m {
		lst.Set(i, uint8(m[i]))
	}
	return lst
}
Ejemplo n.º 3
0
func (t *Topology) AddToSegAutoRoot(seg *capn.Segment) msgs.Topology {
	topology := msgs.AutoNewTopology(seg)
	topology.SetClusterId(t.ClusterId)
	topology.SetVersion(t.Version)
	hosts := seg.NewTextList(len(t.Hosts))
	topology.SetHosts(hosts)
	for idx, host := range t.Hosts {
		hosts.Set(idx, host)
	}
	topology.SetF(t.F)
	topology.SetMaxRMCount(t.MaxRMCount)
	topology.SetAsyncFlush(t.AsyncFlush)
	rms := seg.NewUInt32List(len(t.AllRMs))
	topology.SetRms(rms)
	for idx, rmId := range t.AllRMs {
		rms.Set(idx, uint32(rmId))
	}
	accounts := msgs.NewAccountList(seg, len(t.Accounts))
	topology.SetAccounts(accounts)
	idx := 0
	for un, pw := range t.Accounts {
		account := accounts.At(idx)
		idx++
		account.SetUsername(un)
		account.SetPassword(pw)
	}
	return topology
}
Ejemplo n.º 4
0
// reduce boilerplate, dump this segment to disk.
func SegToFile(seg *capn.Segment, filePath string) {
	file, err := os.Create(filePath)
	if err != nil {
		panic(err)
	}
	seg.WriteTo(file)
	file.Close()
}
Ejemplo n.º 5
0
func ShowSeg(msg string, seg *capn.Segment) []byte {
	pre := bytes.Buffer{}
	seg.WriteTo(&pre)

	fmt.Printf("%s\n", msg)
	by := pre.Bytes()
	ShowBytes(by, 10)
	return by
}
Ejemplo n.º 6
0
func SegToBytes(seg *capn.Segment) []byte {
	if seg == nil {
		log.Fatal("SegToBytes called with nil segment!")
	}
	buf := new(bytes.Buffer)
	if _, err := seg.WriteTo(buf); err != nil {
		log.Fatal("Error when writing segment to bytes:", err)
	}
	return buf.Bytes()
}
Ejemplo n.º 7
0
func Nester1GoToCapn(seg *capn.Segment, src *Nester1) air.Nester1Capn {
	//fmt.Printf("\n\n   Nester1GoToCapn sees seg = '%#v'\n", seg)
	dest := air.AutoNewNester1Capn(seg)

	mylist1 := seg.NewTextList(len(src.Strs))
	for i := range src.Strs {
		mylist1.Set(i, string(src.Strs[i]))
	}
	dest.SetStrs(mylist1)

	//fmt.Printf("after Nester1GoToCapn setting\n")
	return dest
}
Ejemplo n.º 8
0
func (vc *VectorClock) AddToSeg(seg *capn.Segment) msgs.VectorClock {
	if vc == nil {
		vcCap := msgs.NewVectorClock(seg)
		vcCap.SetVarUuids(seg.NewDataList(0))
		vcCap.SetValues(seg.NewUInt64List(0))
		return vcCap

	} else if vc.cap == nil {
		vcCap := msgs.NewVectorClock(seg)
		vc.cap = &vcCap
		vUUIds := seg.NewDataList(len(vc.Clock))
		values := seg.NewUInt64List(len(vc.Clock))
		vcCap.SetVarUuids(vUUIds)
		vcCap.SetValues(values)
		idx := 0
		for vUUId, ver := range vc.Clock {
			vUUIds.Set(idx, vUUId[:])
			values.Set(idx, ver)
			idx++
		}
		return vcCap

	} else {
		return *vc.cap
	}
}
Ejemplo n.º 9
0
func HashTableGoToCapn(seg *capn.Segment, src *HashTable) HashTableCapn {
	dest := AutoNewHashTableCapn(seg)
	dest.SetCellSz(uint64(src.CellSz))
	dest.SetArraySize(uint64(src.ArraySize))
	dest.SetPopulation(uint64(src.Population))

	mylist1 := seg.NewUInt8List(len(src.Offheap))
	for i := range src.Offheap {
		mylist1.Set(i, uint8(src.Offheap[i]))
	}
	dest.SetOffheap(mylist1.ToArray())

	return dest
}
Ejemplo n.º 10
0
func MmapMallocGoToCapn(seg *capn.Segment, src *MmapMalloc) MmapMallocCapn {
	dest := AutoNewMmapMallocCapn(seg)
	dest.SetPath(src.Path)
	dest.SetFd(int64(src.Fd))
	dest.SetFileBytesLen(src.FileBytesLen)
	dest.SetBytesAlloc(src.BytesAlloc)

	mylist1 := seg.NewUInt8List(len(src.Mem))
	for i := range src.Mem {
		mylist1.Set(i, uint8(src.Mem[i]))
	}
	dest.SetMem(mylist1.ToArray())

	return dest
}
Ejemplo n.º 11
0
// notifyContact routes a message to a single contact.
func (r *BroadcastRouter) notifyContact(deliveries chan<- bool, url string,
	segment *capn.Segment, logID string) {

	buf := bytes.Buffer{}
	segment.WriteTo(&buf)
	req, err := http.NewRequest("PUT", url, &buf)
	if err != nil {
		if r.logger.ShouldLog(ERROR) {
			r.logger.Error("router", "Router request failed",
				LogFields{"rid": logID, "error": err.Error()})
		}
		deliveries <- false
		return
	}
	req.Header.Set(HeaderID, logID)
	if r.logger.ShouldLog(DEBUG) {
		r.logger.Debug("router", "Sending request",
			LogFields{"rid": logID, "url": url})
	}
	req.Header.Add("Content-Type", "application/json")
	resp, err := r.rclient.Do(req)
	if err != nil {
		if r.logger.ShouldLog(ERROR) {
			r.logger.Error("router", "Router send failed",
				LogFields{"rid": logID, "error": err.Error()})
		}
		deliveries <- false
		return
	}
	defer resp.Body.Close()
	// Discard the response body. If the body is not fully consumed, the HTTP
	// client will not reuse the underlying TCP connection.
	io.Copy(ioutil.Discard, resp.Body)
	if resp.StatusCode != 200 {
		if r.logger.ShouldLog(DEBUG) {
			r.logger.Debug("router", "Denied",
				LogFields{"rid": logID, "url": url})
		}
		deliveries <- false
		return
	}
	if r.logger.ShouldLog(INFO) {
		r.logger.Info("router", "Server accepted",
			LogFields{"rid": logID, "url": url})
	}
	deliveries <- true
}
Ejemplo n.º 12
0
func (c Conds) AddToSeg(seg *capn.Segment) msgs.ConditionPair_List {
	cap := msgs.NewConditionPairList(seg, len(c))
	idx := 0
	for rmId, condSup := range c {
		condSupCap := msgs.NewConditionPair(seg)
		condSupCap.SetRmId(uint32(rmId))
		condSupCap.SetCondition(condSup.Cond.AddToSeg(seg))
		suppliersCap := seg.NewUInt32List(len(condSup.Suppliers))
		for idx, rmId := range condSup.Suppliers {
			suppliersCap.Set(idx, uint32(rmId))
		}
		condSupCap.SetSuppliers(suppliersCap)
		cap.Set(idx, condSupCap)
		idx++
	}
	return cap
}
Ejemplo n.º 13
0
func (sts *SimpleTxnSubmitter) setAllocations(allocIdx int, rmIdToActionIndices map[common.RMId]*[]int, allocations *msgs.Allocation_List, seg *capn.Segment, active bool, rmIds []common.RMId) {
	for _, rmId := range rmIds {
		actionIndices := *(rmIdToActionIndices[rmId])
		sort.Ints(actionIndices)
		allocation := allocations.At(allocIdx)
		allocation.SetRmId(uint32(rmId))
		actionIndicesCap := seg.NewUInt16List(len(actionIndices))
		allocation.SetActionIndices(actionIndicesCap)
		for k, v := range actionIndices {
			actionIndicesCap.Set(k, uint16(v))
		}
		if active {
			allocation.SetActive(sts.connections[rmId].BootCount())
		} else {
			allocation.SetActive(0)
		}
		allocIdx++
	}
}
Ejemplo n.º 14
0
func RWTestGoToCapn(seg *capn.Segment, src *RWTest) air.RWTestCapn {
	dest := air.AutoNewRWTestCapn(seg)

	// NestMatrix -> Nester1Capn (go slice to capn list)
	if len(src.NestMatrix) > 0 {
		//typedList := air.NewNester1CapnList(seg, len(src.NestMatrix))
		plist := seg.NewPointerList(len(src.NestMatrix))
		i := 0
		for _, ele := range src.NestMatrix {
			//plist.Set(i, capn.Object(Nester1GoToCapn(seg, &ele)))
			r := capn.Object(SliceNester1ToNester1CapnList(seg, ele))
			plist.Set(i, r)
			i++
		}
		//dest.SetNestMatrix(typedList)
		dest.SetNestMatrix(plist)
	}

	return dest
}
Ejemplo n.º 15
0
// shell out to display capnp bytes as human-readable text. Data flow:
//    in-memory capn segment -> stdin to capnp decode -> stdout human-readble string form
func CapnpDecodeSegment(seg *capn.Segment, capnpExePath string, capnpSchemaFilePath string, typeName string) string {

	// set defaults
	if capnpExePath == "" {
		capnpExePath = CheckAndGetCapnpPath()
	}

	if capnpSchemaFilePath == "" {
		capnpSchemaFilePath = "aircraftlib/aircraft.capnp"
	}

	if typeName == "" {
		typeName = "Z"
	}

	cs := []string{"decode", "--short", capnpSchemaFilePath, typeName}
	cmd := exec.Command(capnpExePath, cs...)
	cmdline := capnpExePath + " " + strings.Join(cs, " ")

	buf := new(bytes.Buffer)
	seg.WriteTo(buf)

	cmd.Stdin = buf

	var errout bytes.Buffer
	cmd.Stderr = &errout

	bs, err := cmd.Output()
	if err != nil {
		if err.Error() == "exit status 1" {
			cwd, _ := os.Getwd()
			fmt.Fprintf(os.Stderr, "\nCall to capnp in CapnpDecodeSegment(): '%s' in dir '%s' failed with status 1\n", cmdline, cwd)
			fmt.Printf("stderr: '%s'\n", string(errout.Bytes()))
			fmt.Printf("stdout: '%s'\n", string(bs))
		}
		panic(err)
	}
	return strings.TrimSpace(string(bs))
}
Ejemplo n.º 16
0
func (cts *ClientTxnSubmitter) translateUpdates(seg *capn.Segment, updates map[*msgs.Update][]*msgs.Action) cmsgs.ClientUpdate_List {
	clientUpdates := cmsgs.NewClientUpdateList(seg, len(updates))
	idx := 0
	for update, actions := range updates {
		clientUpdate := clientUpdates.At(idx)
		idx++
		clientUpdate.SetVersion(update.TxnId())
		clientActions := cmsgs.NewClientActionList(seg, len(actions))
		clientUpdate.SetActions(clientActions)

		for idy, action := range actions {
			clientAction := clientActions.At(idy)
			clientAction.SetVarId(action.VarId())
			switch action.Which() {
			case msgs.ACTION_MISSING:
				clientAction.SetDelete()
			case msgs.ACTION_WRITE:
				clientAction.SetWrite()
				write := action.Write()
				clientWrite := clientAction.Write()
				clientWrite.SetValue(write.Value())
				references := write.References()
				clientReferences := seg.NewDataList(references.Len())
				clientWrite.SetReferences(clientReferences)
				for idz, n := 0, references.Len(); idz < n; idz++ {
					ref := references.At(idz)
					clientReferences.Set(idz, ref.Id())
					positions := common.Positions(ref.Positions())
					cts.hashCache.AddPosition(common.MakeVarUUId(ref.Id()), &positions)
				}
			default:
				panic(fmt.Sprintf("Unexpected action type: %v", action.Which()))
			}
		}
	}
	return clientUpdates
}
Ejemplo n.º 17
0
func AutoNewZ(s *C.Segment) Z              { return Z(s.NewStructAR(8, 1)) }
Ejemplo n.º 18
0
func NewRootZ(s *C.Segment) Z              { return Z(s.NewRootStruct(8, 1)) }
Ejemplo n.º 19
0
func NewZ(s *C.Segment) Z                  { return Z(s.NewStruct(8, 1)) }
Ejemplo n.º 20
0
func NewRoutableList(s *C.Segment, sz int) Routable_List {
	return Routable_List(s.NewCompositeList(16, 2, sz))
}
Ejemplo n.º 21
0
func ReadRootRoutable(s *C.Segment) Routable { return Routable(s.Root(0).ToStruct()) }
Ejemplo n.º 22
0
func AutoNewRoutable(s *C.Segment) Routable  { return Routable(s.NewStructAR(16, 2)) }
Ejemplo n.º 23
0
func NewRootRoutable(s *C.Segment) Routable  { return Routable(s.NewRootStruct(16, 2)) }
Ejemplo n.º 24
0
func NewRootRecord(s *C.Segment) Record  { return Record(s.NewRootStruct(16, 0)) }
Ejemplo n.º 25
0
func NewRequestList(s *C.Segment, sz int) Request_List {
	return Request_List(s.NewCompositeList(16, 1, sz))
}
Ejemplo n.º 26
0
func NewRangesList(s *C.Segment, sz int) Ranges_List { return Ranges_List(s.NewCompositeList(8, 1, sz)) }
Ejemplo n.º 27
0
func ReadRootRanges(s *C.Segment) Ranges       { return Ranges(s.Root(0).ToStruct()) }
Ejemplo n.º 28
0
func ReadRootZ(s *C.Segment) Z             { return Z(s.Root(0).ToStruct()) }
Ejemplo n.º 29
0
func NewZList(s *C.Segment, sz int) Z_List { return Z_List(s.NewCompositeList(8, 1, sz)) }
Ejemplo n.º 30
0
func NewRootRanges(s *C.Segment) Ranges        { return Ranges(s.NewRootStruct(8, 1)) }