当前位置: 首页>>代码示例>>Golang>>正文


Golang Segment.NewDataList方法代码示例

本文整理汇总了Golang中github.com/glycerine/go-capnproto.Segment.NewDataList方法的典型用法代码示例。如果您正苦于以下问题:Golang Segment.NewDataList方法的具体用法?Golang Segment.NewDataList怎么用?Golang Segment.NewDataList使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/glycerine/go-capnproto.Segment的用法示例。


在下文中一共展示了Segment.NewDataList方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: AddToSeg

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
	}
}
开发者ID:,项目名称:,代码行数:26,代码来源:

示例2: translateUpdates

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
}
开发者ID:,项目名称:,代码行数:37,代码来源:

示例3: AddToSegAutoRoot

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
}
开发者ID:,项目名称:,代码行数:88,代码来源:


注:本文中的github.com/glycerine/go-capnproto.Segment.NewDataList方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。