Ejemplo n.º 1
0
func ReadVarString(r io.Reader) (string, int, error) {

	totalRead := 0

	length, i, err := varint.ReadVarInt(r)
	totalRead += i
	if err != nil {
		return "", totalRead, err
	}

	bytes := make([]byte, length)
	i, err = io.ReadFull(r, bytes)
	totalRead += i
	if err != nil {
		return err.Error(), totalRead, err
	}

	value := string(bytes)

	return value, totalRead, nil

}
Ejemplo n.º 2
0
func (this *DataReader) ReadVarInt() (uint64, error) {

	value, i, err := varint.ReadVarInt(this.r)
	this.count += int64(i)
	return value, err
}