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

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

示例1: TestNoMergeExtensionMerge

func TestNoMergeExtensionMerge(t *testing.T) {
    bigm := prototests.AContainer
    m := &prototests.Small{SmallField: proto.Int64(1)}
    data, err := proto.Marshal(bigm)
    if err != nil {
        panic(err)
    }
    mdata, err := proto.Marshal(m)
    if err != nil {
        panic(err)
    }
    key := uint32(101)<<3 | uint32(2)
    datakey := make([]byte, 10)
    n := binary.PutUvarint(datakey, uint64(key))
    datakey = datakey[:n]
    datalen := make([]byte, 10)
    n = binary.PutUvarint(datalen, uint64(len(mdata)))
    datalen = datalen[:n]
    data = append(data, append(datakey, append(datalen, mdata...)...)...)
    err = noMerge(data, bigm.Description(), "prototests", "Container")
    if err == nil || !strings.Contains(err.Error(), "FieldB requires merging") {
        t.Fatalf("FieldB should require merging, but error is %v", err)
    }
    t.Log(err)
}

开发者ID:katydid,项目名称:katydid,代码行数:25,代码来源:nomerge_test.go

示例2: appendRec

func (b *Batch) appendRec(kt kType, key, value []byte) {
    n := 1 + binary.MaxVarintLen32 + len(key)
    if kt == ktVal {
        n += binary.MaxVarintLen32 + len(value)
    }
    b.grow(n)
    off := len(b.data)
    data := b.data[:off+n]
    data[off] = byte(kt)
    off += 1
    off += binary.PutUvarint(data[off:], uint64(len(key)))
    copy(data[off:], key)
    off += len(key)
    if kt == ktVal {
        off += binary.PutUvarint(data[off:], uint64(len(value)))
        copy(data[off:], value)
        off += len(value)
    }
    b.data = data[:off]
=======
    off := len(b.buf)
    if off == 0 {
        // include headers
        off = kBatchHdrLen
        n += off
    }
    if cap(b.buf)-off >= n {
        return
    }
    buf := make([]byte, 2*cap(b.buf)+n)
    copy(buf, b.buf)
    b.buf = buf[:off]
}

开发者ID:json007,项目名称:goleveldb,代码行数:33,代码来源:batch.go

示例3: writeMetaData

func writeMetaData(outPath string) {
    outFile, err := os.Create(outPath)
    defer outFile.Close()
    if err != nil {
        panic(err)
    }
    var buf []byte = make([]byte, 4)
    var posBuf []byte = make([]byte, 8)
    binary.PutUvarint(buf, uint64(uniqueTerms))
    outFile.Write(buf)
    buf = []byte{0, 0, 0, 0}
    binary.PutUvarint(buf, uint64(docId))
    outFile.Write(buf)
    buf = []byte{0, 0, 0, 0}

    var docIdInt int = int(docId)
    for i := 0; i < docIdInt; i++ {
        binary.PutUvarint(buf, uint64(iDocInfos[i].length))
        outFile.Write(buf)
        buf = []byte{0, 0, 0, 0}
        binary.PutUvarint(posBuf, uint64(iDocInfos[i].pos))
        outFile.Write(posBuf)
        posBuf = []byte{0, 0, 0, 0, 0, 0, 0, 0}
    }
}

开发者ID:s1na,项目名称:fetch,代码行数:25,代码来源:index.go

示例4: writeIndex

func writeIndex(outPath string) {
    outFile, err := os.Create(outPath)
    defer outFile.Close()
    if err != nil {
        panic(err)
    }
    writer := bufio.NewWriterSize(io.Writer(outFile), writerBufSize)

    var v *list.List
    dBuf := make([]byte, 4)
    tfBuf := make([]byte, 4)
    pBuf := make([]byte, 4)
    for _, k := range dictionary.keys {
        v = dictionary.m[k]
        writer.WriteString(k + ",")
        var posting *Posting
        for el := v.Front(); el != nil; el = el.Next() {
            posting = el.Value.(*Posting)
            binary.PutUvarint(dBuf, uint64(posting.doc))
            writer.Write(dBuf)
            dBuf = []byte{0, 0, 0, 0}
            binary.PutUvarint(tfBuf, uint64(posting.tf))
            writer.Write(tfBuf)
            tfBuf = []byte{0, 0, 0, 0}
            for posEl := posting.pos.Front(); posEl != nil; posEl = posEl.Next() {
                pos := posEl.Value.(uint32)
                binary.PutUvarint(pBuf, uint64(pos))
                writer.Write(pBuf)
                pBuf = []byte{0, 0, 0, 0}
            }
        }
        writer.Write([]byte{0, 0, 0, 0})
    }
    writer.Flush()
}

开发者ID:s1na,项目名称:fetch,代码行数:35,代码来源:index.go

示例5: appendRec

func (b *Batch) appendRec(kt keyType, key, value []byte) {
    n := 1 + binary.MaxVarintLen32 + len(key)
    if kt == keyTypeVal {
        n += binary.MaxVarintLen32 + len(value)
    }
    b.grow(n)
    index := batchIndex{keyType: kt}
    o := len(b.data)
    data := b.data[:o+n]
    data[o] = byte(kt)
    o++
    o += binary.PutUvarint(data[o:], uint64(len(key)))
    index.keyPos = o
    index.keyLen = len(key)
    o += copy(data[o:], key)
    if kt == keyTypeVal {
        o += binary.PutUvarint(data[o:], uint64(len(value)))
        index.valuePos = o
        index.valueLen = len(value)
        o += copy(data[o:], value)
    }
    b.data = data[:o]
    b.index = append(b.index, index)
    b.internalLen += index.keyLen + index.valueLen + 8
}

开发者ID:lessos,项目名称:lessdb,代码行数:25,代码来源:batch.go

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