コード例 #1
0
ファイル: topology.go プロジェクト: chang290/server
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
}
コード例 #2
0
ファイル: nested_test.go プロジェクト: hodduc/go-capnproto
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
}
コード例 #3
0
ファイル: nested_test.go プロジェクト: hodduc/go-capnproto
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
}
コード例 #4
0
func (config *Configuration) AddToSegAutoRoot(seg *capn.Segment) msgs.Configuration {
	cap := msgs.AutoNewConfiguration(seg)
	cap.SetClusterId(config.ClusterId)
	cap.SetVersion(config.Version)

	hosts := seg.NewTextList(len(config.Hosts))
	cap.SetHosts(hosts)
	for idx, host := range config.Hosts {
		hosts.Set(idx, host)
	}

	cap.SetF(config.F)
	cap.SetMaxRMCount(config.MaxRMCount)
	cap.SetNoSync(config.NoSync)

	rms := seg.NewUInt32List(len(config.rms))
	cap.SetRms(rms)
	for idx, rmId := range config.rms {
		rms.Set(idx, uint32(rmId))
	}

	rmsRemoved := seg.NewUInt32List(len(config.rmsRemoved))
	cap.SetRmsRemoved(rmsRemoved)
	idx := 0
	for rmId := range config.rmsRemoved {
		rmsRemoved.Set(idx, uint32(rmId))
		idx++
	}

	fingerprintsMap := config.fingerprints
	fingerprints := seg.NewDataList(len(fingerprintsMap))
	cap.SetFingerprints(fingerprints)
	idx = 0
	for fingerprint := range fingerprintsMap {
		fingerprints.Set(idx, fingerprint[:])
		idx++
	}

	if config.nextConfiguration == nil {
		cap.SetStable()
	} else {
		nextConfig := config.nextConfiguration
		cap.SetTransitioningTo()
		next := cap.TransitioningTo()
		next.SetConfiguration(nextConfig.Configuration.AddToSegAutoRoot(seg))

		allHostsCap := seg.NewTextList(len(nextConfig.AllHosts))
		for idx, host := range nextConfig.AllHosts {
			allHostsCap.Set(idx, host)
		}
		next.SetAllHosts(allHostsCap)

		newRMIdsCap := seg.NewUInt32List(len(nextConfig.NewRMIds))
		for idx, rmId := range nextConfig.NewRMIds {
			newRMIdsCap.Set(idx, uint32(rmId))
		}
		next.SetNewRMIds(newRMIdsCap)

		survivingRMIdsCap := seg.NewUInt32List(len(nextConfig.SurvivingRMIds))
		for idx, rmId := range nextConfig.SurvivingRMIds {
			survivingRMIdsCap.Set(idx, uint32(rmId))
		}
		next.SetSurvivingRMIds(survivingRMIdsCap)

		lostRMIdsCap := seg.NewUInt32List(len(nextConfig.LostRMIds))
		for idx, rmId := range nextConfig.LostRMIds {
			lostRMIdsCap.Set(idx, uint32(rmId))
		}
		next.SetLostRMIds(lostRMIdsCap)

		barrierReached1Cap := seg.NewUInt32List(len(nextConfig.BarrierReached1))
		for idx, rmId := range nextConfig.BarrierReached1 {
			barrierReached1Cap.Set(idx, uint32(rmId))
		}
		next.SetBarrierReached1(barrierReached1Cap)

		barrierReached2Cap := seg.NewUInt32List(len(nextConfig.BarrierReached2))
		for idx, rmId := range nextConfig.BarrierReached2 {
			barrierReached2Cap.Set(idx, uint32(rmId))
		}
		next.SetBarrierReached2(barrierReached2Cap)

		next.SetInstalledOnNew(nextConfig.InstalledOnNew)

		next.SetPending(nextConfig.Pending.AddToSeg(seg))
	}
	return cap
}