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

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

示例1: readVarint

func (bin *mBinaryProto) readVarint(reader io.Reader) (int64, error) {
    if br, ok := reader.(io.ByteReader); ok {
        return binary.ReadVarint(br)
    }
    br := newByteReader(reader, bin.readBuffer)
    return binary.ReadVarint(br)
}

开发者ID:msglib,项目名称:msglib-go,代码行数:7,代码来源:msglib.go

示例2: SaveRow

//  0. embedded video
//  1. picture
//  2. pictures
//  3. title
//  4. tags
//  5. categories
//  6. pornstars
//  7. duration in seconds
//  8. views
//  9. upvotes
//  10. downvotes
func SaveRow(row []byte) {
    var video Video

    // Split the columns
    b := bytes.Split(row, []byte(`|`))

    video.SourceName = "pornhub"
    video.Username = "Pornhub"
    // video.EmbedCode = EscapeStrings(string(b[0]))
    video.EmbedCode = EscapeString(string(b[0]))
    video.Picture = string(b[1])
    video.Pictures = string(b[2])
    video.Title = string(b[3])
    video.Description = "Watch " + string(b[3])
    video.Tags = string(b[4])
    video.Categories = string(b[5])
    video.Pornstars = string(b[6])
    video.Duration, _ = binary.ReadVarint(bytes.NewBuffer(b[7]))
    video.ViewsCount, _ = binary.ReadVarint(bytes.NewBuffer(b[8]))
    video.Upvotes, _ = binary.ReadVarint(bytes.NewBuffer(b[9]))
    video.Downvotes, _ = binary.ReadVarint(bytes.NewBuffer(b[10]))
    video.CreatedAt = time.Now()
    video.UpdatedAt = time.Now()

    insertVideo(video)
}

开发者ID:shavit,项目名称:Kese-Dollz,代码行数:37,代码来源:load_videos_line_by_line.go

示例3: UnmarshalBinary

// UnmarshalBinary implements encoding.BinaryUnmarshaler.
func (tr *TimeRange) UnmarshalBinary(buf []byte) error {
    r := bytes.NewReader(buf)
    first, err := binary.ReadVarint(r)
    if err != nil {
        return err
    }
    last, err := binary.ReadVarint(r)
    if err != nil {
        return err
    }
    tr.First = clientmodel.Timestamp(first)
    tr.Last = clientmodel.Timestamp(last)
    return nil
}

开发者ID:gitlabuser,项目名称:prometheus,代码行数:15,代码来源:codable.go

示例4: UnmarshalDeltaNodes

func UnmarshalDeltaNodes(buf []byte, nodes []element.Node) ([]element.Node, error) {
    r := bytes.NewBuffer(buf)
    length, err := binary.ReadVarint(r)
    if err != nil {
        return nil, err
    }

    if int64(cap(nodes)) < length {
        nodes = make([]element.Node, length)
    } else {
        nodes = nodes[:length]
    }

    lastId := int64(0)
    for i := 0; int64(i) < length; i++ {
        id, err := binary.ReadVarint(r)
        if err != nil {
            return nil, err
        }
        id = lastId + id
        nodes[i].Id = id
        lastId = id
    }

    lastLong := int64(0)
    for i := 0; int64(i) < length; i++ {
        long, err := binary.ReadVarint(r)
        if err != nil {
            return nil, err
        }
        long = lastLong + long
        nodes[i].Long = IntToCoord(uint32(long))
        lastLong = long
    }

    lastLat := int64(0)
    for i := 0; int64(i) < length; i++ {
        lat, err := binary.ReadVarint(r)
        if err != nil {
            return nil, err
        }
        lat = lastLat + lat
        nodes[i].Lat = IntToCoord(uint32(lat))
        lastLat = lat
    }

    return nodes, nil
}

开发者ID:renderless,项目名称:imposm3,代码行数:48,代码来源:deltacoords.go

示例5: Unmarshal

func (t *Commit) Unmarshal(rr io.Reader) error {
    var wire byteReader
    var ok bool
    if wire, ok = rr.(byteReader); !ok {
        wire = bufio.NewReader(rr)
    }
    var b [24]byte
    var bs []byte
    bs = b[:12]
    if _, err := io.ReadAtLeast(wire, bs, 12); err != nil {
        return err
    }
    t.LeaderId = int32((uint32(bs[0]) | (uint32(bs[1]) << 8) | (uint32(bs[2]) << 16) | (uint32(bs[3]) << 24)))
    t.Replica = int32((uint32(bs[4]) | (uint32(bs[5]) << 8) | (uint32(bs[6]) << 16) | (uint32(bs[7]) << 24)))
    t.Instance = int32((uint32(bs[8]) | (uint32(bs[9]) << 8) | (uint32(bs[10]) << 16) | (uint32(bs[11]) << 24)))
    alen1, err := binary.ReadVarint(wire)
    if err != nil {
        return err
    }
    t.Command = make([]state.Command, alen1)
    for i := int64(0); i < alen1; i++ {
        t.Command[i].Unmarshal(wire)
    }
    bs = b[:24]
    if _, err := io.ReadAtLeast(wire, bs, 24); err != nil {
        return err
    }
    t.Seq = int32((uint32(bs[0]) | (uint32(bs[1]) << 8) | (uint32(bs[2]) << 16) | (uint32(bs[3]) << 24)))
    t.Deps[0] = int32((uint32(bs[4]) | (uint32(bs[5]) << 8) | (uint32(bs[6]) << 16) | (uint32(bs[7]) << 24)))
    t.Deps[1] = int32((uint32(bs[8]) | (uint32(bs[9]) << 8) | (uint32(bs[10]) << 16) | (uint32(bs[11]) << 24)))
    t.Deps[2] = int32((uint32(bs[12]) | (uint32(bs[13]) << 8) | (uint32(bs[14]) << 16) | (uint32(bs[15]) << 24)))
    t.Deps[3] = int32((uint32(bs[16]) | (uint32(bs[17]) << 8) | (uint32(bs[18]) << 16) | (uint32(bs[19]) << 24)))
    t.Deps[4] = int32((uint32(bs[20]) | (uint32(bs[21]) << 8) | (uint32(bs[22]) << 16) | (uint32(bs[23]) << 24)))
    return nil
}

开发者ID:WIZARD-CXY,项目名称:golang-devops-stuff,代码行数:35,代码来源:epaxosprotomarsh.go

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