func (b *Buffer) PutUint(op OpType, idx uint32, value uint) {
	b.PutUint64(op, idx, uint64(value))
}
PutUint appends a uint64 value.
package commit
import (
	"fmt"
	"math"
	"reflect"
	"unsafe"
)
const (
	chunkShift = 14      
	size0      = 0       
	size2      = 1 << 4  
	size4      = 2 << 4  
	size8      = 3 << 4  
	isNext     = 1 << 7  
	isString   = 1 << 6  
)
type OpType uint8
const (
	Delete   OpType = 0  
	Insert   OpType = 1  
	PutFalse OpType = 0  
	PutTrue  OpType = 2  
	Put      OpType = 2  
	Add      OpType = 3  
)
type Buffer struct {
	last   int32     
	chunk  uint32    
	buffer []byte    
	chunks []header  
	_      [8]byte   
	Column string    
}
type header struct {
	Chunk uint32  
	Start uint32  
	Value uint32  
}
func NewBuffer(capacity int) *Buffer {
	return &Buffer{
		chunk:  math.MaxUint32,
		buffer: make([]byte, 0, capacity),
	}
}
func (b *Buffer) Clone() *Buffer {
	buffer := make([]byte, len(b.buffer))
	copy(buffer, b.buffer)
	chunks := make([]header, 0, len(b.chunks))
	chunks = append(chunks, b.chunks...)
	return &Buffer{
		Column: b.Column,
		buffer: buffer,
		chunks: chunks,
		last:   b.last,
		chunk:  b.chunk,
	}
}
func (b *Buffer) Reset(column string) {
	b.last = 0
	b.chunk = math.MaxUint32
	b.buffer = b.buffer[:0]
	b.chunks = b.chunks[:0]
	b.Column = column
}
func (b *Buffer) IsEmpty() bool {
	return len(b.buffer) == 0
}
func (b *Buffer) RangeChunks(fn func(chunk uint32)) {
	for _, c := range b.chunks {
		fn(c.Chunk)
	}
}
func (b *Buffer) PutAny(op OpType, idx uint32, value interface{}) {
	switch v := value.(type) {
	case uint64:
		b.PutUint64(op, idx, v)
	case uint32:
		b.PutUint32(op, idx, v)
	case uint16:
		b.PutUint16(op, idx, v)
	case uint8:
		b.PutUint16(op, idx, uint16(v))
	case int64:
		b.PutInt64(op, idx, v)
	case int32:
		b.PutInt32(op, idx, v)
	case int16:
		b.PutInt16(op, idx, v)
	case int8:
		b.PutInt16(op, idx, int16(v))
	case string:
		b.PutString(op, idx, v)
	case []byte:
		b.PutBytes(op, idx, v)
	case float32:
		b.PutFloat32(op, idx, v)
	case float64:
		b.PutFloat64(op, idx, v)
	case int:
		b.PutInt64(op, idx, int64(v))
	case uint:
		b.PutUint64(op, idx, uint64(v))
	case bool:
		b.PutBool(idx, v)
	case nil:
		b.PutOperation(op, idx)
	default:
		panic(fmt.Errorf("column: unsupported type (%T)", value))
	}
}
func (b *Buffer) PutUint64(op OpType, idx uint32, value uint64) {
	delta := b.writeChunk(idx)
	switch delta {
	case 1:
		b.buffer = append(b.buffer,
			byte(op)|size8|isNext,
			byte(value>>56), byte(value>>48), byte(value>>40), byte(value>>32),
			byte(value>>24), byte(value>>16), byte(value>>8), byte(value),
		)
	default:
		b.buffer = append(b.buffer,
			byte(op)|size8,
			byte(value>>56), byte(value>>48), byte(value>>40), byte(value>>32),
			byte(value>>24), byte(value>>16), byte(value>>8), byte(value),
		)
		b.writeOffset(uint32(delta))
	}
}
func (b *Buffer) PutUint32(op OpType, idx uint32, value uint32) {
	delta := b.writeChunk(idx)
	switch delta {
	case 1:
		b.buffer = append(b.buffer,
			byte(op)|size4|isNext,
			byte(value>>24), byte(value>>16), byte(value>>8), byte(value),
		)
	default:
		b.buffer = append(b.buffer,
			byte(op)|size4,
			byte(value>>24), byte(value>>16), byte(value>>8), byte(value),
		)
		b.writeOffset(uint32(delta))
	}
}
func (b *Buffer) PutUint16(op OpType, idx uint32, value uint16) {
	delta := b.writeChunk(idx)
	switch delta {
	case 1:
		b.buffer = append(b.buffer, byte(op)|size2|isNext, byte(value>>8), byte(value))
	default:
		b.buffer = append(b.buffer, byte(op)|size2, byte(value>>8), byte(value))
		b.writeOffset(uint32(delta))
	}
}
func (b *Buffer) PutOperation(op OpType, idx uint32) {
	delta := b.writeChunk(idx)
	switch delta {
	case 1:
		b.buffer = append(b.buffer, byte(op)|size0|isNext)
	default:
		b.buffer = append(b.buffer, byte(op)|size0)
		b.writeOffset(uint32(delta))
	}
}
func (b *Buffer) PutBool(idx uint32, value bool) {
	op := PutFalse
	if value {
		op = PutTrue
	}
	b.PutOperation(op, idx)
}
func (b *Buffer) PutInt64(op OpType, idx uint32, value int64) {
	b.PutUint64(op, idx, uint64(value))
}
func (b *Buffer) PutInt32(op OpType, idx uint32, value int32) {
	b.PutUint32(op, idx, uint32(value))
}
func (b *Buffer) PutInt16(op OpType, idx uint32, value int16) {
	b.PutUint16(op, idx, uint16(value))
}
func (b *Buffer) PutFloat64(op OpType, idx uint32, value float64) {
	b.PutUint64(op, idx, math.Float64bits(value))
}
func (b *Buffer) PutFloat32(op OpType, idx uint32, value float32) {
	b.PutUint32(op, idx, math.Float32bits(value))
}
func (b *Buffer) PutNumber(op OpType, idx uint32, value float64) {
	b.PutUint64(op, idx, math.Float64bits(value))
}
func (b *Buffer) PutInt(op OpType, idx uint32, value int) {
	b.PutUint64(op, idx, uint64(value))
}