func (b *Reader) CompactString() string {
	l := int(b.Uvarint()) - 1
	return string(b.Span(l))
}
CompactString returns a Kafka compact string from the reader.
package kbin
import (
	"encoding/binary"
	"errors"
	"math"
	"math/bits"
)
var ErrNotEnoughData = errors.New("response did not contain enough data to be valid")
func AppendBool(dst []byte, v bool) []byte {
	if v {
		return append(dst, 1)
	}
	return append(dst, 0)
}
func AppendInt8(dst []byte, i int8) []byte {
	return append(dst, byte(i))
}
func AppendInt16(dst []byte, i int16) []byte {
	return AppendUint16(dst, uint16(i))
}
func AppendUint16(dst []byte, u uint16) []byte {
	return append(dst, byte(u>>8), byte(u))
}
func AppendInt32(dst []byte, i int32) []byte {
	return AppendUint32(dst, uint32(i))
}
func AppendInt64(dst []byte, i int64) []byte {
	return appendUint64(dst, uint64(i))
}
func AppendFloat64(dst []byte, f float64) []byte {
	return appendUint64(dst, math.Float64bits(f))
}
func AppendUuid(dst []byte, uuid [16]byte) []byte {
	return append(dst, uuid[:]...)
}
func appendUint64(dst []byte, u uint64) []byte {
	return append(dst, byte(u>>56), byte(u>>48), byte(u>>40), byte(u>>32),
		byte(u>>24), byte(u>>16), byte(u>>8), byte(u))
}
func AppendUint32(dst []byte, u uint32) []byte {
	return append(dst, byte(u>>24), byte(u>>16), byte(u>>8), byte(u))
}
const uvarintLens = "\x01\x01\x01\x01\x01\x01\x01\x01\x02\x02\x02\x02\x02\x02\x02\x03\x03\x03\x03\x03\x03\x03\x04\x04\x04\x04\x04\x04\x04\x05\x05\x05\x05\x05\x05\x05\x06\x06\x06\x06\x06\x06\x06\x07\x07\x07\x07\x07\x07\x07\x08\x08\x08\x08\x08\x08\x08\x09\x09\x09\x09\x09\x09\x09\x10\x10\x10\x10\x10\x10\x10\x11\x11\x11\x11\x11\x11\x11\x12\x12\x12\x12\x12\x12\x12\x13\x13\x13\x13\x13\x13\x13\x14\x14\x14\x14\x14\x14\x14\x15\x15\x15\x15\x15\x15\x15\x16\x16\x16\x16\x16\x16\x16\x17\x17\x17\x17\x17\x17\x17\x18\x18\x18\x18\x18\x18\x18\x19\x19\x19\x19\x19\x19\x19\x20\x20\x20\x20\x20\x20\x20\x21\x21\x21\x21\x21\x21\x21\x22\x22\x22\x22\x22\x22\x22\x23\x23\x23\x23\x23\x23\x23\x24\x24\x24\x24\x24\x24\x24\x25\x25\x25\x25\x25\x25\x25\x26\x26\x26\x26\x26\x26\x26\x27\x27\x27\x27\x27\x27\x27\x28\x28\x28\x28\x28\x28\x28\x29\x29\x29\x29\x29\x29\x29\x30\x30\x30\x30\x30\x30\x30\x31\x31\x31\x31\x31\x31\x31\x32\x32\x32\x32\x32\x32\x32\x33\x33\x33\x33\x33\x33\x33\x34\x34\x34\x34\x34\x34\x34\x35\x35\x35\x35\x35\x35\x35\x36\x36\x36\x36\x36\x36\x36\x37\x37\x37"
func VarintLen(i int32) int {
	u := uint32(i)<<1 ^ uint32(i>>31)
	return UvarintLen(u)
}
func UvarintLen(u uint32) int {
	return int(uvarintLens[byte(bits.Len32(u))])
}
func Varint(in []byte) (int32, int) {
	x, n := Uvarint(in)
	return int32((x >> 1) ^ -(x & 1)), n
}
func Uvarint(in []byte) (uint32, int) {
	var x uint32
	var overflow int
	if len(in) < 1 {
		goto fail
	}
	x = uint32(in[0] & 0x7f)
	if in[0]&0x80 == 0 {
		return x, 1
	} else if len(in) < 2 {
		goto fail
	}
	x |= uint32(in[1]&0x7f) << 7
	if in[1]&0x80 == 0 {
		return x, 2
	} else if len(in) < 3 {
		goto fail
	}
	x |= uint32(in[2]&0x7f) << 14
	if in[2]&0x80 == 0 {
		return x, 3
	} else if len(in) < 4 {
		goto fail
	}
	x |= uint32(in[3]&0x7f) << 21
	if in[3]&0x80 == 0 {
		return x, 4
	} else if len(in) < 5 {
		goto fail
	}
	x |= uint32(in[4]&0x7f) << 28
	if in[4] <= 0x0f {
		return x, 5
	}
	overflow = -5
fail:
	return 0, overflow
}
func AppendVarint(dst []byte, i int32) []byte {
	return AppendUvarint(dst, uint32(i)<<1^uint32(i>>31))
}
func AppendUvarint(dst []byte, u uint32) []byte {
	switch UvarintLen(u) {
	case 5:
		return append(dst,
			byte(u&0x7f|0x80),
			byte((u>>7)&0x7f|0x80),
			byte((u>>14)&0x7f|0x80),
			byte((u>>21)&0x7f|0x80),
			byte(u>>28))
	case 4:
		return append(dst,
			byte(u&0x7f|0x80),
			byte((u>>7)&0x7f|0x80),
			byte((u>>14)&0x7f|0x80),
			byte(u>>21))
	case 3:
		return append(dst,
			byte(u&0x7f|0x80),
			byte((u>>7)&0x7f|0x80),
			byte(u>>14))
	case 2:
		return append(dst,
			byte(u&0x7f|0x80),
			byte(u>>7))
	case 1:
		return append(dst, byte(u))
	}
	return dst
}
func AppendString(dst []byte, s string) []byte {
	dst = AppendInt16(dst, int16(len(s)))
	return append(dst, s...)
}
func AppendCompactString(dst []byte, s string) []byte {
	dst = AppendUvarint(dst, 1+uint32(len(s)))
	return append(dst, s...)
}
func AppendNullableString(dst []byte, s *string) []byte {
	if s == nil {
		return AppendInt16(dst, -1)
	}
	return AppendString(dst, *s)
}
func AppendCompactNullableString(dst []byte, s *string) []byte {
	if s == nil {
		return AppendUvarint(dst, 0)
	}
	return AppendCompactString(dst, *s)
}
func AppendBytes(dst, b []byte) []byte {
	dst = AppendInt32(dst, int32(len(b)))
	return append(dst, b...)
}
func AppendCompactBytes(dst, b []byte) []byte {
	dst = AppendUvarint(dst, 1+uint32(len(b)))
	return append(dst, b...)
}
func AppendNullableBytes(dst []byte, b []byte) []byte {
	if b == nil {
		return AppendInt32(dst, -1)
	}
	return AppendBytes(dst, b)
}
func AppendCompactNullableBytes(dst []byte, b []byte) []byte {
	if b == nil {
		return AppendUvarint(dst, 0)
	}
	return AppendCompactBytes(dst, b)
}
func AppendVarintString(dst []byte, s string) []byte {
	dst = AppendVarint(dst, int32(len(s)))
	return append(dst, s...)
}
func AppendVarintBytes(dst []byte, b []byte) []byte {
	if b == nil {
		return AppendVarint(dst, -1)
	}
	dst = AppendVarint(dst, int32(len(b)))
	return append(dst, b...)
}
func AppendArrayLen(dst []byte, l int) []byte {
	return AppendInt32(dst, int32(l))
}
func AppendCompactArrayLen(dst []byte, l int) []byte {
	return AppendUvarint(dst, 1+uint32(l))
}
func AppendNullableArrayLen(dst []byte, l int, isNil bool) []byte {
	if isNil {
		return AppendInt32(dst, -1)
	}
	return AppendInt32(dst, int32(l))
}
func AppendCompactNullableArrayLen(dst []byte, l int, isNil bool) []byte {
	if isNil {
		return AppendUvarint(dst, 0)
	}
	return AppendUvarint(dst, 1+uint32(l))
}
type Reader struct {
	Src []byte
	bad bool
}
func (b *Reader) Bool() bool {
	if len(b.Src) < 1 {
		b.bad = true
		b.Src = nil
		return false
	}
	t := b.Src[0] != 0  
	b.Src = b.Src[1:]
	return t
}
func (b *Reader) Int8() int8 {
	if len(b.Src) < 1 {
		b.bad = true
		b.Src = nil
		return 0
	}
	r := b.Src[0]
	b.Src = b.Src[1:]
	return int8(r)
}
func (b *Reader) Int16() int16 {
	if len(b.Src) < 2 {
		b.bad = true
		b.Src = nil
		return 0
	}
	r := int16(binary.BigEndian.Uint16(b.Src))
	b.Src = b.Src[2:]
	return r
}
func (b *Reader) Uint16() uint16 {
	if len(b.Src) < 2 {
		b.bad = true
		b.Src = nil
		return 0
	}
	r := binary.BigEndian.Uint16(b.Src)
	b.Src = b.Src[2:]
	return r
}
func (b *Reader) Int32() int32 {
	if len(b.Src) < 4 {
		b.bad = true
		b.Src = nil
		return 0
	}
	r := int32(binary.BigEndian.Uint32(b.Src))
	b.Src = b.Src[4:]
	return r
}
func (b *Reader) Int64() int64 {
	return int64(b.readUint64())
}
func (b *Reader) Uuid() [16]byte {
	var r [16]byte
	copy(r[:], b.Span(16))
	return r
}
func (b *Reader) Float64() float64 {
	return math.Float64frombits(b.readUint64())
}
func (b *Reader) readUint64() uint64 {
	if len(b.Src) < 8 {
		b.bad = true
		b.Src = nil
		return 0
	}
	r := binary.BigEndian.Uint64(b.Src)
	b.Src = b.Src[8:]
	return r
}
func (b *Reader) Uint32() uint32 {
	if len(b.Src) < 4 {
		b.bad = true
		b.Src = nil
		return 0
	}
	r := binary.BigEndian.Uint32(b.Src)
	b.Src = b.Src[4:]
	return r
}
func (b *Reader) Varint() int32 {
	val, n := Varint(b.Src)
	if n <= 0 {
		b.bad = true
		b.Src = nil
		return 0
	}
	b.Src = b.Src[n:]
	return int32(val)
}
func (b *Reader) Uvarint() uint32 {
	val, n := Uvarint(b.Src)
	if n <= 0 {
		b.bad = true
		b.Src = nil
		return 0
	}
	b.Src = b.Src[n:]
	return val
}
func (b *Reader) Span(l int) []byte {
	if len(b.Src) < l || l < 0 {
		b.bad = true
		b.Src = nil
		return nil
	}
	r := b.Src[:l:l]
	b.Src = b.Src[l:]
	return r
}
func (b *Reader) String() string {
	l := b.Int16()
	return string(b.Span(int(l)))
}