本文整理汇总了Golang中encoding/binary.ReadUvarint函数的典型用法代码### 示例。如果您正苦于以下问题:Golang ReadUvarint函数的具体用法?Golang ReadUvarint怎么用?Golang ReadUvarint使用的例子?那么恭喜您, 这里精选的函数代码### 示例或许可以为您提供帮助。
在下文中一共展示了ReadUvarint函数的20个代码### 示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码### 示例。
示例1: ParseKey
func (sr *StoredRow) ParseKey(key []byte) error {
buf := bytes.NewBuffer(key)
_, err := buf.ReadByte() // type
if err != nil {
return err
}
sr.docID, err = buf.ReadBytes(ByteSeparator)
if len(sr.docID) < 2 { // 1 for min doc id length, 1 for separator
err = fmt.Errorf("invalid doc length 0")
return err
}
sr.docID = sr.docID[:len(sr.docID)-1] // trim off separator byte
sr.docNum, err = binary.ReadUvarint(buf)
if err != nil {
return err
}
err = binary.Read(buf, binary.LittleEndian, &sr.field)
if err != nil {
return err
}
sr.arrayPositions = make([]uint64, 0)
nextArrayPos, err := binary.ReadUvarint(buf)
for err == nil {
sr.arrayPositions = append(sr.arrayPositions, nextArrayPos)
nextArrayPos, err = binary.ReadUvarint(buf)
}
return nil
}
开发者ID:mitra-varuna,项目名称:bleve,代码行数:34,代码来源:stored.go
示例2: NewStoredRowK
func NewStoredRowK(key []byte) (*StoredRow, error) {
rv := StoredRow{}
buf := bytes.NewBuffer(key)
_, err := buf.ReadByte() // type
if err != nil {
return nil, err
}
rv.doc, err = buf.ReadBytes(ByteSeparator)
if len(rv.doc) < 2 { // 1 for min doc id length, 1 for separator
err = fmt.Errorf("invalid doc length 0")
return nil, err
}
rv.doc = rv.doc[:len(rv.doc)-1] // trim off separator byte
err = binary.Read(buf, binary.LittleEndian, &rv.field)
if err != nil {
return nil, err
}
rv.arrayPositions = make([]uint64, 0)
nextArrayPos, err := binary.ReadUvarint(buf)
for err == nil {
rv.arrayPositions = append(rv.arrayPositions, nextArrayPos)
nextArrayPos, err = binary.ReadUvarint(buf)
}
return &rv, nil
}
开发者ID:vseledkin,项目名称:bleve,代码行数:30,代码来源:row.go
示例3: recv
func (p *Player) recv() {
for {
length, err := ReadVarint(p.conn)
if err != nil {
p.Game.RemovePlayer(p.Name)
fmt.Println("Player disconnected")
return
}
buf := make([]byte, length)
io.ReadFull(p.conn, buf)
r := bytes.NewReader(buf)
binary.ReadUvarint(r)
id, _ := binary.ReadUvarint(r)
switch id {
case 0x01:
message := ReadString(r)
if strings.HasPrefix(message, "/") {
// Commands
} else {
WriteChatMessage(p.Game, fmt.Sprintf("<%s> %s", p.Name, message))
fmt.Printf("<%s> %s\n", p.Name, message)
}
}
}
}
开发者ID:cengizIO,项目名称:GoCraft,代码行数:30,代码来源:player.go
示例4: readEntry
func readEntry(reader *dirIndexReader, offset uint64) (*indexEntry, error) {
seekErr := seekIndex(reader, offset)
if seekErr != nil {
return nil, seekErr
}
n, err := binary.ReadUvarint(reader.indexReader)
if err != nil {
return nil, err
}
entries := []indexEntryElement{}
for i := uint64(0); i < n; i++ {
docId, derr := binary.ReadUvarint(reader.indexReader)
if derr != nil {
return nil, derr
}
var freq float64
ferr := binary.Read(reader.indexReader, binary.LittleEndian, &freq)
if ferr != nil {
return nil, ferr
}
entries = append(entries, indexEntryElement{docId, freq})
}
tail, terr := binary.ReadUvarint(reader.indexReader)
if terr != nil {
return nil, terr
}
return &indexEntry{entries, tail}, nil
}
开发者ID:vspy,项目名称:gosearch,代码行数:32,代码来源:search.go
示例5: UnserializeSimpleTask
// Format of a simple task:
// 2 bytes : magic number
// 8 bytes : id length : l
// 8 bytes : data length : n
// 32 bytes : target
// 32 bytes : action
// l bytes : id
// n bytes : data
func UnserializeSimpleTask(data []byte) *SimpleTask {
// Magic number 01
if data[0] != 0 || data[1] != 1 {
return nil
}
// ID Length
idLength, err := binary.ReadUvarint(bytes.NewBuffer(data[2:10]))
if err != nil {
return nil
}
// Data Length
length, err := binary.ReadUvarint(bytes.NewBuffer(data[10:18]))
if err != nil {
return nil
}
// Target
target := string(data[18:50])
// Action
action := string(data[50:82])
// ID
readId := string(data[82 : 82+idLength])
// Data
readData := data[82+idLength : 82+idLength+length]
return NewSimpleTask(readId, target, action, readData)
}
开发者ID:remeh,项目名称:gost,代码行数:41,代码来源:task.go
最后编辑: kuteng 文档更新时间: 2021-08-23 19:14 作者:kuteng