本文整理汇总了Golang中encoding/binary.PutVarint函数的典型用法代码### 示例。如果您正苦于以下问题:Golang PutVarint函数的具体用法?Golang PutVarint怎么用?Golang PutVarint使用的例子?那么恭喜您, 这里精选的函数代码### 示例或许可以为您提供帮助。

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

示例1: Marshal

func (t *LeaseMetadata) Marshal(wire io.Writer) {
    var b [10]byte
    var bs []byte
    bs = b[:]
    alen1 := int64(len(t.Quorum))
    if wlen := binary.PutVarint(bs, alen1); wlen >= 0 {
        wire.Write(b[0:wlen])
    }
    for i := int64(0); i < alen1; i++ {
        bs = b[:4]
        tmp32 := t.Quorum[i]
        bs[0] = byte(tmp32)
        bs[1] = byte(tmp32 >> 8)
        bs[2] = byte(tmp32 >> 16)
        bs[3] = byte(tmp32 >> 24)
        wire.Write(bs)
    }
    bs = b[:]
    alen2 := int64(len(t.ObjectKeys))
    if wlen := binary.PutVarint(bs, alen2); wlen >= 0 {
        wire.Write(b[0:wlen])
    }
    for i := int64(0); i < alen2; i++ {
        t.ObjectKeys[i].Marshal(wire)
    }
    bs = b[:2]
    bs[0] = byte(t.IgnoreReplicas)
    bs[1] = byte(t.ReinstateReplicas)
    wire.Write(bs)
}

开发者ID:pombredanne,项目名称:qlease,代码行数:30,代码来源:qlprotomarsh.go

示例2: Increment

func (b *BoltDB) Increment() int64 {
    buf := make([]byte, 8)
    var retVal int64
    err := b.db.Update(func(tx *bolt.Tx) error {
        b, err := tx.CreateBucketIfNotExists(demoBucket)
        if err != nil {
            log.Fatal(err)
        }
        v := b.Get(demoKey)
        if v == nil {
            binary.PutVarint(buf, 0)
            retVal = 0
        } else {
            i, err := binary.ReadVarint(bytes.NewBuffer(v))
            if err != nil {
                log.Fatal(err)
            }
            i++
            retVal = i
            binary.PutVarint(buf, i)
        }
        err = b.Put(demoKey, buf)
        return err
    })
    if err != nil {
        log.Fatal(err)
    }

    return retVal
}

开发者ID:TrevorSStone,项目名称:boltmobiledemo,代码行数:30,代码来源:boltmobiledemo.go

示例3: writeNumber

func (b *binaryNomsWriter) writeNumber(v Number) {
    b.ensureCapacity(binary.MaxVarintLen64 * 2)
    i, exp := float64ToIntExp(float64(v))
    count := binary.PutVarint(b.buff[b.offset:], i)
    b.offset += uint32(count)
    count = binary.PutVarint(b.buff[b.offset:], int64(exp))
    b.offset += uint32(count)
}

开发者ID:Richardphp,项目名称:noms,代码行数:8,代码来源:codec.go

示例4: zoneFilename

func zoneFilename(x, y int64, z int8) string {
    var buf [binary.MaxVarintLen64*2 + 1]byte
    i := binary.PutVarint(buf[:], x)
    i += binary.PutVarint(buf[i:], y)
    buf[i] = uint8(z)
    i++
    encoded := base32.StdEncoding.EncodeToString(buf[:i])
    return filepath.Join("rnoadm-AA", "zone"+encoded+".gz")
}

开发者ID:BenLubar,项目名称:Rnoadm,代码行数:9,代码来源:storage.go

示例5: putFunc

func putFunc(cmd *cobra.Command, args []string) {
    if keySpaceSize <= 0 {
        fmt.Fprintf(os.Stderr, "expected positive --key-space-size, got (%v)", keySpaceSize)
        os.Exit(1)
    }

    requests := make(chan v3.Op, totalClients)
    clients := mustCreateClients(totalClients, totalConns)
    k, v := make([]byte, keySize), string(mustRandBytes(valSize))

    bar = pb.New(putTotal)
    bar.Format("Bom !")
    bar.Start()

    r := newReport()
    for i := range clients {
        wg.Add(1)
        go func(c *v3.Client) {
            defer wg.Done()
            for op := range requests {
                st := time.Now()
                _, err := c.Do(context.Background(), op)
                r.Results() <- report.Result{Err: err, Start: st, End: time.Now()}
                bar.Increment()
            }
        }(clients[i])
    }

    go func() {
        for i := 0; i < putTotal; i++ {
            if seqKeys {
                binary.PutVarint(k, int64(i%keySpaceSize))
            } else {
                binary.PutVarint(k, int64(rand.Intn(keySpaceSize)))
            }
            requests <- v3.OpPut(string(k), v)
        }
        close(requests)
    }()

    if compactInterval > 0 {
        go func() {
            for {
                time.Sleep(compactInterval)
                compactKV(clients)
            }
        }()
    }

    rc := r.Run()
    wg.Wait()
    close(r.Results())
    bar.Finish()
    fmt.Println(<-rc)
}

开发者ID:pulcy,项目名称:vault-monkey,代码行数:55,代码来源:put.go

最后编辑: kuteng  文档更新时间: 2021-08-23 19:14   作者:kuteng