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

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

示例1: GetPartition

// Return all entries in the chosen part.
func (ht *HashTable) GetPartition(partNum, partSize int) (keys, vals []int) {
    rangeStart, rangeEnd := GetPartitionRange(partNum, partSize)
    prealloc := (rangeEnd - rangeStart) * PER_BUCKET
    keys = make([]int, 0, prealloc)
    vals = make([]int, 0, prealloc)
    for head := rangeStart; head < rangeEnd; head++ {
        var entry, bucket int = 0, head
        for {
            entryAddr := bucket*BUCKET_SIZE + BUCKET_HEADER + entry*ENTRY_SIZE
            entryKey, _ := binary.Varint(ht.Buf[entryAddr+1 : entryAddr+11])
            entryVal, _ := binary.Varint(ht.Buf[entryAddr+11 : entryAddr+21])
            if ht.Buf[entryAddr] == 1 {
                keys = append(keys, int(entryKey))
                vals = append(vals, int(entryVal))
            } else if entryKey == 0 && entryVal == 0 {
                break
            }
            if entry++; entry == PER_BUCKET {
                entry = 0
                if bucket = ht.nextBucket(bucket); bucket == 0 {
                    return
                }
            }
        }
    }
    return
}

开发者ID:huanshi,项目名称:tiedot,代码行数:28,代码来源:hashtable.go

示例2: ParseMessage

func ParseMessage(b []byte) (m Message, err error) {
    err = nil
    i, _ := binary.Varint(b[:1])
    m.majorVer = int8(i) // version-number              2 bytes     - required
    i, _ = binary.Varint(b[1:2])
    m.minorVer = int8(i)
    //log.Println(m)

    //panic(1)

    ii, _ := binary.Uvarint(b[3:4])
    m.operationIdStatusCode = uint16(ii) // operation-id (request)      2 bytes     - required
    m.IsResponse = typeCheck(uint16(ii)) // or status-code (response)

    iii, _ := binary.Varint(b[4:8]) //  request-id                  4 bytes     - required
    m.requestId = int32(iii)
    //et := bytes.IndexByte(b[8:], TAG_END)
    //log.Println("message:", m)
    ags := splitAValues(b[8:]) //et+9]) //  attribute-group             n bytes     - 0 or more

    m.attributeGroups = ags

    // m.endAttributeTag = b[et] // end-of-attributes-tag       1 byte      - required

    //m.Data = b[et+8:] //  data q bytes    - optional
    //log.Println("Data: ", m.Data)

    return
}

开发者ID:hilerchyn,项目名称:goIPP,代码行数:29,代码来源:unMarshall.go

示例3: Get

// Look up values by key.
func (ht *HashTable) Get(key, limit int) (vals []int) {
    if limit == 0 {
        vals = make([]int, 0, 10)
    } else {
        vals = make([]int, 0, limit)
    }
    for count, entry, bucket := 0, 0, HashKey(key); ; {
        entryAddr := bucket*BUCKET_SIZE + BUCKET_HEADER + entry*ENTRY_SIZE
        entryKey, _ := binary.Varint(ht.Buf[entryAddr+1 : entryAddr+11])
        entryVal, _ := binary.Varint(ht.Buf[entryAddr+11 : entryAddr+21])
        if ht.Buf[entryAddr] == 1 {
            if int(entryKey) == key {
                vals = append(vals, int(entryVal))
                if count++; count == limit {
                    return
                }
            }
        } else if entryKey == 0 && entryVal == 0 {
            return
        }
        if entry++; entry == PER_BUCKET {
            entry = 0
            if bucket = ht.nextBucket(bucket); bucket == 0 {
                return
            }
        }
    }
}

开发者ID:Lanzafame,项目名称:tiedot,代码行数:29,代码来源:hashtable.go

示例4: Int64

//  Int64 decodes a int64 from buffer
func (d *Dec) Int64() int64 {
    if d.err != nil {
        return 0
    }
    if d.i >= len(d.decbuf) || d.i < 0 /*overflow*/ {
        d.err = errNoDecData
        return 0
    }
    d.lng = int(d.decbuf[d.i])
    // if d.lng <= 0 {
    //  d.err = errDecode
    //  return 0
    // }
    d.i++
    d.lst = d.i + d.lng
    if d.lst > len(d.decbuf) {
        d.err = errDecodeNotEnoughtData
        return 0
    }
    var x int64
    if d.lst == len(d.decbuf) {
        x, d.i = binary.Varint(d.decbuf[d.i:])
    } else {
        x, d.i = binary.Varint(d.decbuf[d.i:d.lst])
    }
    if d.i <= 0 {
        d.err = errDecode
        return 0
    }
    d.i = d.lst
    return x
}

开发者ID:mrkovec,项目名称:encdec,代码行数:33,代码来源:encdec.go

示例5: readNumber

func (b *binaryNomsReader) readNumber() Number {
    // b.assertCanRead(binary.MaxVarintLen64 * 2)
    i, count := binary.Varint(b.buff[b.offset:])
    b.offset += uint32(count)
    exp, count2 := binary.Varint(b.buff[b.offset:])
    b.offset += uint32(count2)
    return Number(intExpToFloat64(i, int(exp)))
}

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

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