• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang go-capnproto.Segment类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: SliceStringToTextList

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


示例2: SliceByteToUInt8List

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


示例3: AddToSegAutoRoot

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
}
开发者ID:chang290,项目名称:server,代码行数:28,代码来源:topology.go


示例4: SegToFile

// 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()
}
开发者ID:hodduc,项目名称:go-capnproto,代码行数:9,代码来源:util_test.go


示例5: ShowSeg

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
}
开发者ID:hodduc,项目名称:go-capnproto,代码行数:9,代码来源:struct_test.go


示例6: SegToBytes

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()
}
开发者ID:chang290,项目名称:server,代码行数:10,代码来源:utils.go


示例7: Nester1GoToCapn

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
}
开发者ID:hodduc,项目名称:go-capnproto,代码行数:13,代码来源:nested_test.go


示例8: 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,代码来源:


示例9: HashTableGoToCapn

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
}
开发者ID:robmurtha,项目名称:offheap,代码行数:14,代码来源:translateCapn.go


示例10: MmapMallocGoToCapn

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
}
开发者ID:robmurtha,项目名称:offheap,代码行数:15,代码来源:translateCapn.go


示例11: notifyContact

// 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
}
开发者ID:jrconlin,项目名称:pushgo,代码行数:48,代码来源:router_broadcast.go


示例12: setAllocations

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


示例13: RWTestGoToCapn

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
}
开发者ID:hodduc,项目名称:go-capnproto,代码行数:20,代码来源:nested_test.go


示例14: CapnpDecodeSegment

// 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))
}
开发者ID:hodduc,项目名称:go-capnproto,代码行数:41,代码来源:util_test.go


示例15: 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,代码来源:


示例16: AutoNewZ

func AutoNewZ(s *C.Segment) Z              { return Z(s.NewStructAR(8, 1)) }
开发者ID:jamessan,项目名称:dcs,代码行数:1,代码来源:sourcebackend.capnp.go


示例17: NewRootZ

func NewRootZ(s *C.Segment) Z              { return Z(s.NewRootStruct(8, 1)) }
开发者ID:jamessan,项目名称:dcs,代码行数:1,代码来源:sourcebackend.capnp.go


示例18: NewZ

func NewZ(s *C.Segment) Z                  { return Z(s.NewStruct(8, 1)) }
开发者ID:jamessan,项目名称:dcs,代码行数:1,代码来源:sourcebackend.capnp.go


示例19: NewRoutableList

func NewRoutableList(s *C.Segment, sz int) Routable_List {
	return Routable_List(s.NewCompositeList(16, 2, sz))
}
开发者ID:jrconlin,项目名称:pushgo,代码行数:3,代码来源:routable.capnp.go


示例20: ReadRootRoutable

func ReadRootRoutable(s *C.Segment) Routable { return Routable(s.Root(0).ToStruct()) }
开发者ID:jrconlin,项目名称:pushgo,代码行数:1,代码来源:routable.capnp.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang convey.Convey函数代码示例发布时间:2022-05-23
下一篇:
Golang go-capnproto.Struct函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap