Ejemplo n.º 1
0
func (f *Field) Dump(alloc arena.ArenaAllocator) []byte {
	if f.Data != nil {
		return []byte(f.Data)
	}

	l := len(f.Schema) + len(f.Table) + len(f.OrgTable) + len(f.Name) + len(f.OrgName) + len(f.DefaultValue) + 48

	data := alloc.AllocBytes(l)

	data = append(data, defCache...)

	data = append(data, PutLengthEncodedString(f.Schema, alloc)...)

	data = append(data, PutLengthEncodedString(f.Table, alloc)...)
	data = append(data, PutLengthEncodedString(f.OrgTable, alloc)...)

	data = append(data, PutLengthEncodedString(f.Name, alloc)...)
	data = append(data, PutLengthEncodedString(f.OrgName, alloc)...)

	data = append(data, 0x0c)

	data = append(data, Uint16ToBytes(f.Charset)...)
	data = append(data, Uint32ToBytes(f.ColumnLength)...)
	data = append(data, f.Type)
	data = append(data, Uint16ToBytes(f.Flag)...)
	data = append(data, f.Decimal)
	data = append(data, 0, 0)

	if f.DefaultValue != nil {
		data = append(data, Uint64ToBytes(f.DefaultValueLength)...)
		data = append(data, f.DefaultValue...)
	}

	return data
}
Ejemplo n.º 2
0
func NewTrackedBuffer(nodeFormatter func(buf *TrackedBuffer, node SQLNode), alloc arena.ArenaAllocator) *TrackedBuffer {
	buf := &TrackedBuffer{
		Buffer:        bytes.NewBuffer(alloc.AllocBytes(256)),
		bindLocations: make([]bindLocation, 0, 4),
		nodeFormatter: nodeFormatter,
	}
	return buf
}
Ejemplo n.º 3
0
func PutLengthEncodedString(b []byte, alloc arena.ArenaAllocator) []byte {
	data := alloc.AllocBytes(len(b) + 9)
	data = append(data, PutLengthEncodedInt(uint64(len(b)))...)
	data = append(data, b...)
	return data
}