当前位置: 首页>>代码示例>>Golang>>正文


Golang binary.ReadVarint函数代码示例

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


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

示例6: rawInt64

// rawInt64 should only be used by low-level decoders
func (p *importer) rawInt64() int64 {
	i, err := binary.ReadVarint(p)
	if err != nil {
		panic(fmt.Sprintf("read error: %v", err))
	}
	return i
}
开发者ID:CyCoreSystems,项目名称:coreos-kubernetes,代码行数:8,代码来源:bimport.go

示例7: Unmarshal

func (t *Accept) Unmarshal(rr io.Reader) error {
	var wire byteReader
	var ok bool
	if wire, ok = rr.(byteReader); !ok {
		wire = bufio.NewReader(rr)
	}
	var b [12]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.Instance = int32((uint32(bs[4]) | (uint32(bs[5]) << 8) | (uint32(bs[6]) << 16) | (uint32(bs[7]) << 24)))
	t.Ballot = 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)
	}
	if _, err := io.ReadAtLeast(wire, bs, 12); err != nil {
		return err
	}
	t.LeaseInstance = int32((uint32(bs[0]) | (uint32(bs[1]) << 8) | (uint32(bs[2]) << 16) | (uint32(bs[3]) << 24)))
	t.OriginReplica = int32((uint32(bs[4]) | (uint32(bs[5]) << 8) | (uint32(bs[6]) << 16) | (uint32(bs[7]) << 24)))
	t.PropId = int32((uint32(bs[8]) | (uint32(bs[9]) << 8) | (uint32(bs[10]) << 16) | (uint32(bs[11]) << 24)))
	return nil
}
开发者ID:pombredanne,项目名称:qlease,代码行数:31,代码来源:paxosprotomarsh.go

示例8: GetValue

func (b *BoltDB) GetValue() int64 {
	var retVal int64
	err := b.db.View(func(tx *bolt.Tx) error {
		b := tx.Bucket(demoBucket)
		if b == nil {
			retVal = -1
			return nil
		}
		v := b.Get(demoKey)
		if v == nil {

			retVal = 0
		} else {
			i, err := binary.ReadVarint(bytes.NewBuffer(v))
			if err != nil {
				return err
			}
			retVal = i
		}
		return nil
	})
	if err != nil {
		log.Fatal(err)
	}
	return retVal
}
开发者ID:TrevorSStone,项目名称:boltmobiledemo,代码行数:26,代码来源:boltmobiledemo.go

示例9: DecodeOld

func DecodeOld(str string) (int64, error) {
	data, err := base64.StdEncoding.DecodeString(str)
	if err != nil {
		return 0, err
	}
	return binary.ReadVarint(bytes.NewReader(data))
}
开发者ID:orian,项目名称:utils,代码行数:7,代码来源:ids.go

示例10: main

// Testing out how to hash some object
func main() {
	fmt.Println("Hello, playground")

	// sha := sha256.New()

	result := sha256.Sum256([]byte("foobar"))
	length := len(result)
	fmt.Printf("%d\n", length)
	fmt.Printf("%x\n", result)

	part0 := result[:16]
	fmt.Printf("%d\n", len(part0))
	fmt.Printf("%x\n", part0)

	// converting byte array to signed int
	buf := bytes.NewBuffer(part0)
	intPart0, _ := binary.ReadVarint(buf)
	// note: probably want unsigned int instead...

	fmt.Printf("%d\n\n\n", intPart0)

	part1 := result[16:]
	fmt.Printf("%d\n", len(part1))
	fmt.Printf("%x\n", part1)

	b := NewBloomFilterStringKeyed(32, 10)

	fmt.Println(b.byteCapacity)
	fmt.Println(b.numHashes)
	fmt.Println(b.bitHashTable)

	b.AddKey("foo")

}
开发者ID:kaschaeffer,项目名称:bloomfilter,代码行数:35,代码来源:bloomfilter.go

示例11: Unmarshal

func (t *PrepareReply) Unmarshal(rr io.Reader) error {
	var wire byteReader
	var ok bool
	if wire, ok = rr.(byteReader); !ok {
		wire = bufio.NewReader(rr)
	}
	var b [10]byte
	var bs []byte
	bs = b[:9]
	if _, err := io.ReadAtLeast(wire, bs, 9); err != nil {
		return err
	}
	t.Balnum = int32((uint32(bs[0]) | (uint32(bs[1]) << 8) | (uint32(bs[2]) << 16) | (uint32(bs[3]) << 24)))
	t.OK = uint8(bs[4])
	t.Ballot = int32((uint32(bs[5]) | (uint32(bs[6]) << 8) | (uint32(bs[7]) << 16) | (uint32(bs[8]) << 24)))
	alen1, err := binary.ReadVarint(wire)
	if err != nil {
		return err
	}
	t.Cstruct = make([]int32, alen1)
	for i := int64(0); i < alen1; i++ {
		bs = b[:4]
		if _, err := io.ReadAtLeast(wire, bs, 4); err != nil {
			return err
		}
		t.Cstruct[i] = int32((uint32(bs[0]) | (uint32(bs[1]) << 8) | (uint32(bs[2]) << 16) | (uint32(bs[3]) << 24)))
	}
	return nil
}
开发者ID:WIZARD-CXY,项目名称:golang-devops-stuff,代码行数:29,代码来源:gpaxosprotomarsh.go

示例12: Read

//The go routine here, keep waiting messages from connected client Blocking.
func (client *Client) Read(mp *MessagePasser) {
	for {
		//line, err := client.reader.ReadBytes('\xfe')
		length, err := binary.ReadVarint(client.reader)

		if err != nil {
			client.rethrowError(mp)
			mp.RemoveMapping(client.IP)
			mp.RemoveMapping(client.name)
			return
		}
		buffer := make([]byte, length)
		client.reader.Read(buffer)

		msg := new(Message)
		msg.Deserialize(buffer)

		err = msg.Deserialize(buffer)
		if err != nil {
			fmt.Println("err is " + err.Error())
		}
		client.addToClients(msg, mp.connections.clients)
		mp.Incoming <- msg // Since there is only one socket, directly put all the received
		// msgs into the global receiving channel (message queue)
	}
}
开发者ID:wcyz666,项目名称:DS_TeamProject,代码行数:27,代码来源:MessagePasser.go

示例13: Decode

func (bed BinaryVarintEncoderDecoder) Decode(r io.Reader, n *big.Float) error {
	var isInteger int8
	var f float64
	var exponent int32
	n.SetUint64(0)

	if err := binary.Read(r, binary.BigEndian, &isInteger); err != nil {
		return err
	}

	if isInteger <= 0 {
		var x int64
		var err error
		if x, err = binary.ReadVarint(miniByteReader{r}); err != nil {
			return err
		}
		n.SetInt64(x)
		n.SetPrec(ENCODER_DECODER_PREC)
		return nil
	} else {
		if err := binary.Read(r, binary.BigEndian, &f); err != nil {
			return err
		}
		if err := binary.Read(r, binary.BigEndian, &exponent); err != nil {
			return err
		}
		bed.tmp.SetFloat64(f)
		bed.tmp.SetPrec(ENCODER_DECODER_PREC)
		n.SetMantExp(bed.tmp, int(exponent))
		return nil
	}
}
开发者ID:Richardphp,项目名称:noms,代码行数:32,代码来源:binary-varint-encoder.go

示例14: init

func init() {
	// seed math.random from crypto.random
	seedBytes, _ := makeRandom(8)
	seedBuf := bytes.NewBuffer(seedBytes)
	n64, _ := binary.ReadVarint(seedBuf)
	mrand.Seed(n64)
}
开发者ID:rsrsps,项目名称:redoctober,代码行数:7,代码来源:passvault.go

示例15: rawInt64

// rawInt64 should only be used by low-level decoders.
func (p *importer) rawInt64() int64 {
	i, err := binary.ReadVarint(p)
	if err != nil {
		formatErrorf("read error: %v", err)
	}
	return i
}
开发者ID:kuangchanglang,项目名称:go,代码行数:8,代码来源:bimport.go


注:本文中的encoding/binary.ReadVarint函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。