github.com/insionng/yougam@v0.0.0-20170714101924-2bc18d833463/libraries/pingcap/tidb/structure/structure.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 structure
    15  
    16  import (
    17  	"github.com/insionng/yougam/libraries/pingcap/tidb/kv"
    18  	"github.com/insionng/yougam/libraries/pingcap/tidb/terror"
    19  )
    20  
    21  // structure error codes.
    22  const (
    23  	codeInvalidHashKeyFlag   terror.ErrCode = 1
    24  	codeInvalidHashKeyPrefix                = 2
    25  	codeInvalidListIndex                    = 3
    26  	codeInvalidListMetaData                 = 4
    27  )
    28  
    29  var (
    30  	errInvalidHashKeyFlag   = terror.ClassStructure.New(codeInvalidHashKeyFlag, "invalid encoded hash key flag")
    31  	errInvalidHashKeyPrefix = terror.ClassStructure.New(codeInvalidHashKeyPrefix, "invalid encoded hash key prefix")
    32  	errInvalidListIndex     = terror.ClassStructure.New(codeInvalidListMetaData, "invalid list index")
    33  	errInvalidListMetaData  = terror.ClassStructure.New(codeInvalidListMetaData, "invalid list meta data")
    34  )
    35  
    36  // NewStructure creates a TxStructure in transaction txn and with key prefix.
    37  func NewStructure(txn kv.Transaction, prefix []byte) *TxStructure {
    38  	return &TxStructure{
    39  		txn:    txn,
    40  		prefix: prefix,
    41  	}
    42  }
    43  
    44  // TxStructure supports some simple data structures like string, hash, list, etc... and
    45  // you can use these in a transaction.
    46  type TxStructure struct {
    47  	txn    kv.Transaction
    48  	prefix []byte
    49  }