github.com/insionng/yougam@v0.0.0-20170714101924-2bc18d833463/libraries/pingcap/tidb/server/column.go (about)

     1  // Copyright 2015 PingCAP, Inc.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // See the License for the specific language governing permissions and
    12  // limitations under the License.
    13  
    14  package server
    15  
    16  import (
    17  	"github.com/insionng/yougam/libraries/pingcap/tidb/util/arena"
    18  )
    19  
    20  // ColumnInfo contains information of a column
    21  type ColumnInfo struct {
    22  	Schema             string
    23  	Table              string
    24  	OrgTable           string
    25  	Name               string
    26  	OrgName            string
    27  	ColumnLength       uint32
    28  	Charset            uint16
    29  	Flag               uint16
    30  	Decimal            uint8
    31  	Type               uint8
    32  	DefaultValueLength uint64
    33  	DefaultValue       []byte
    34  }
    35  
    36  // Dump dumps ColumnInfo to bytes.
    37  func (column *ColumnInfo) Dump(alloc arena.Allocator) []byte {
    38  	l := len(column.Schema) + len(column.Table) + len(column.OrgTable) + len(column.Name) + len(column.OrgName) + len(column.DefaultValue) + 48
    39  
    40  	data := make([]byte, 0, l)
    41  
    42  	data = append(data, dumpLengthEncodedString([]byte("def"), alloc)...)
    43  
    44  	data = append(data, dumpLengthEncodedString([]byte(column.Schema), alloc)...)
    45  
    46  	data = append(data, dumpLengthEncodedString([]byte(column.Table), alloc)...)
    47  	data = append(data, dumpLengthEncodedString([]byte(column.OrgTable), alloc)...)
    48  
    49  	data = append(data, dumpLengthEncodedString([]byte(column.Name), alloc)...)
    50  	data = append(data, dumpLengthEncodedString([]byte(column.OrgName), alloc)...)
    51  
    52  	data = append(data, 0x0c)
    53  
    54  	data = append(data, dumpUint16(column.Charset)...)
    55  	data = append(data, dumpUint32(column.ColumnLength)...)
    56  	data = append(data, column.Type)
    57  	data = append(data, dumpUint16(column.Flag)...)
    58  	data = append(data, column.Decimal)
    59  	data = append(data, 0, 0)
    60  
    61  	if column.DefaultValue != nil {
    62  		data = append(data, dumpUint64(uint64(len(column.DefaultValue)))...)
    63  		data = append(data, []byte(column.DefaultValue)...)
    64  	}
    65  
    66  	return data
    67  }