本文整理汇总了Golang中github.com/glycerine/go-capnproto.Segment类的典型用法代码示例。如果您正苦于以下问题:Golang Segment类的具体用法?Golang Segment怎么用?Golang Segment使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Segment类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
}
示例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
}
示例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
}
示例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()
}
示例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
}
示例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()
}
示例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
}
示例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
}
}
示例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
}
示例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
}
示例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
}
示例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++
}
}
示例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
}
示例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))
}
示例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
}