// WriteVarInt64 writes u to w.
4232
func WriteVarInt64(w io.Writer, i int64) error {
	var b []byte
	_, err := w.Write(appendSleb128(b, i))
	return err
}
132384
func EncodeUvarint(out io.Writer, n int) error {
	var buf [16]byte
	var err error
	i := 0
	if (n & 0xffffff80) != 0 {
		buf[i] = byte((n | 0x80) & 0xff)
		i++
		n >>= 7
		if (n & 0xffffff80) != 0 {
			buf[i] = byte((n | 0x80) & 0xff)
			i++
			n >>= 7
			if (n & 0xffffff80) != 0 {
				buf[i] = byte((n | 0x80) & 0xff)
				i++
				n >>= 7
				if (n & 0xffffff80) != 0 {
					buf[i] = byte((n | 0x80) & 0xff)
					i++
					n >>= 7
				}
			}
		}
	}
	buf[i] = byte(n)
	_, err = out.Write(buf[:i+1])
	return err
}
1225136
func (b *Buffer) Write64(v uint64) {
	order.PutUint64(b.append(8), v)
}
874341
func EncodeUvarint(b []byte, v uint64) []byte {
	var data [binary.MaxVarintLen64]byte
	n := binary.PutUvarint(data[:], v)
	return append(b, data[:n]...)
}
223045
func (f *FlagSet) Int64Var(p *int64, name string, value int64, usage string) {
	f.Var(newInt64Value(value, p), name, usage)
}
1068277
func EncodeVarint(x uint32) []byte {
	if x>>7 == 0 {
		return []byte{
			byte(x),
		}
	}

	if x>>14 == 0 {
		return []byte{
			byte(0x80 | x>>7),
			byte(127 & x),
		}
	}

	if x>>21 == 0 {
		return []byte{
			byte(0x80 | x>>14),
			byte(0x80 | x>>7),
			byte(127 & x),
		}
	}

	return []byte{
		byte(0x80 | x>>21),
		byte(0x80 | x>>14),
		byte(0x80 | x>>7),
		byte(127 & x),
	}
}
1314594
func (p *Buffer) EncodeVarint(x uint64) error {
	for x >= 1<<7 {
		p.buf = append(p.buf, uint8(x&0x7f|0x80))
		x >>= 7
	}
	p.buf = append(p.buf, uint8(x))
	return nil
}
1326682
func VarintSize(x int64) int {
	ux := uint64(x) << 1
	if x < 0 {
		ux = ^ux
	}
	return UvarintSize(ux)
}
38771
func ReadVarInt64(r io.Reader) (int64, error) {
	var result int64
	var shift uint64
	size := uint64(32)
	buf := make([]byte, 1)
	for {
		if _, err := r.Read(buf); err != nil {
			return 0, err
		}
		v := int64(buf[0])
		result |= (v & 0x7F) << shift
		shift += 7
		if v&0x80 == 0 {
			if (shift < size) && (v&0x40 != 0) {
				result |= (^0 << shift)
			}
			return result, nil
		}
	}
}
368487
func (stream *Stream) WriteInt32(nval int32) {
	var val uint32
	if nval < 0 {
		val = uint32(-nval)
		stream.buf = append(stream.buf, '-')
	} else {
		val = uint32(nval)
	}
	stream.WriteUint32(val)
}
533563
func ToInt64(v interface{}) int64 {
	if str, ok := v.(string); ok {
		return strToInt64(str)
	}

	val := reflect.Indirect(reflect.ValueOf(v))
	switch val.Kind() {
	case reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Int:
		return val.Int()
	case reflect.Uint8, reflect.Uint16, reflect.Uint32:
		return int64(val.Uint())
	case reflect.Uint, reflect.Uint64:
		tv := val.Uint()
		// this can overflow and give -1, but IMO this is better than
		// returning maxint64
		return int64(tv)
	case reflect.Float32, reflect.Float64:
		return int64(val.Float())
	case reflect.Bool:
		if val.Bool() {
			return 1
		}
		return 0
	default:
		return 0
	}
}
477448
func (w *ByteWriter) MustWriteInt64(val int64, offset int) int {
	return w.MustWriteVal(val, offset)
}
770174
func (p *TCompactProtocol) WriteI16(value int16) error {
	_, err := p.writeVarint32(p.int32ToZigzag(int32(value)))
	return NewTProtocolException(err)
}
463423
func (b *ByteBuf) WriteUInt64(v uint64) (n int, err error) {
	b.Expansion(8)
	Uint64ToBytesTo(v, b.buf[b.writerIndex:b.writerIndex+8])
	b.writerIndex += 8
	return 8, nil
}
427213
func WriteInteger(n int64, buf *goetty.ByteBuf) {
	buf.WriteByte(':')
	buf.Write(goetty.FormatInt64ToBytes(n))
	buf.Write(Delims)
}
706341
func (ed *eventData) writeInt64(value int64) {
	binary.Write(&ed.buffer, binary.LittleEndian, value)
}
1106706
func writeInt(w enhancedWriter, i int64) (int, error) {
	bp := numBufPool.Get().(*[]byte)
	*bp = strconv.AppendInt((*bp)[:0], i, 10)
	written, err := w.Write(*bp)
	numBufPool.Put(bp)
	return written, err
}