本文整理汇总了Golang中github.com/pingcap/tidb/util/codec.DecodeInt函数的典型用法代码示例。如果您正苦于以下问题:Golang DecodeInt函数的具体用法?Golang DecodeInt怎么用?Golang DecodeInt使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了DecodeInt函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: DecodeRecordKey
// DecodeRecordKey decodes the key and gets the tableID, handle and columnID.
func DecodeRecordKey(key kv.Key) (tableID int64, handle int64, columnID int64, err error) {
k := key
if !key.HasPrefix(TablePrefix) {
return 0, 0, 0, errors.Errorf("invalid record key - %q", k)
}
key = key[len(TablePrefix):]
key, tableID, err = codec.DecodeInt(key)
if err != nil {
return 0, 0, 0, errors.Trace(err)
}
if !key.HasPrefix(recordPrefixSep) {
return 0, 0, 0, errors.Errorf("invalid record key - %q", k)
}
key = key[len(recordPrefixSep):]
key, handle, err = codec.DecodeInt(key)
if err != nil {
return 0, 0, 0, errors.Trace(err)
}
if len(key) == 0 {
return
}
key, columnID, err = codec.DecodeInt(key)
if err != nil {
return 0, 0, 0, errors.Trace(err)
}
return
}
示例2: DecodeRowKey
// DecodeRowKey decodes the key and gets the handle.
func DecodeRowKey(key kv.Key) (handle int64, err error) {
k := key
if !key.HasPrefix(tablePrefix) {
return 0, errInvalidRecordKey.Gen("invalid record key - %q", k)
}
key = key[len(tablePrefix):]
// Table ID is not needed.
key, _, err = codec.DecodeInt(key)
if err != nil {
return 0, errors.Trace(err)
}
if !key.HasPrefix(recordPrefixSep) {
return 0, errInvalidRecordKey.Gen("invalid record key - %q", k)
}
key = key[len(recordPrefixSep):]
key, handle, err = codec.DecodeInt(key)
if err != nil {
return 0, errors.Trace(err)
}
return
}
示例3: collectColumnsInExpr
func collectColumnsInExpr(expr *tipb.Expr, ctx *selectContext, collector map[int64]*tipb.ColumnInfo) error {
if expr == nil {
return nil
}
if expr.GetTp() == tipb.ExprType_ColumnRef {
_, i, err := codec.DecodeInt(expr.Val)
if err != nil {
return errors.Trace(err)
}
var columns []*tipb.ColumnInfo
if ctx.sel.TableInfo != nil {
columns = ctx.sel.TableInfo.Columns
} else {
columns = ctx.sel.IndexInfo.Columns
}
for _, c := range columns {
if c.GetColumnId() == i {
collector[i] = c
return nil
}
}
return xeval.ErrInvalid.Gen("column %d not found", i)
}
for _, child := range expr.Children {
err := collectColumnsInExpr(child, ctx, collector)
if err != nil {
return errors.Trace(err)
}
}
return nil
}
示例4: Next
// Next returns the next row of the sub result.
// If no more row to return, data would be nil.
func (r *SubResult) Next() (handle int64, data []types.Datum, err error) {
if r.resp == nil {
r.resp = new(tipb.SelectResponse)
var b []byte
b, err = ioutil.ReadAll(r.reader)
r.reader.Close()
if err != nil {
return 0, nil, errors.Trace(err)
}
err = proto.Unmarshal(b, r.resp)
if err != nil {
return 0, nil, errors.Trace(err)
}
}
if r.cursor >= len(r.resp.Rows) {
return 0, nil, nil
}
row := r.resp.Rows[r.cursor]
data, err = tablecodec.DecodeValues(row.Data, r.fields)
if err != nil {
return 0, nil, errors.Trace(err)
}
handleBytes := row.GetHandle()
_, handle, err = codec.DecodeInt(handleBytes)
if err != nil {
return 0, nil, errors.Trace(err)
}
r.cursor++
return
}
示例5: evalDuration
func (e *Evaluator) evalDuration(val []byte) (types.Datum, error) {
var d types.Datum
_, i, err := codec.DecodeInt(val)
if err != nil {
return d, ErrInvalid.Gen("invalid duration %d", i)
}
d.SetMysqlDuration(mysql.Duration{Duration: time.Duration(i), Fsp: mysql.MaxFsp})
return d, nil
}
示例6: evalInt
func (e *Evaluator) evalInt(val []byte) (types.Datum, error) {
var d types.Datum
_, i, err := codec.DecodeInt(val)
if err != nil {
return d, ErrInvalid.Gen("invalid int % x", val)
}
d.SetInt64(i)
return d, nil
}
示例7: evalColumnRef
func (e *Evaluator) evalColumnRef(val []byte) (types.Datum, error) {
var d types.Datum
_, i, err := codec.DecodeInt(val)
if err != nil {
return d, errors.Trace(err)
}
d, ok := e.Row[i]
if !ok {
return d, ErrInvalid.Gen("column % x not found", val)
}
return d, nil
}