// decodeIndices takes a ThreatEntrySet for removals returned by the server and
// returns a list of indices that the client should remove from its database.
344535
func decodeIndices(input *pb.ThreatEntrySet) ([]int32, error) {
	switch input.CompressionType {
	case pb.CompressionType_RAW:
		raw := input.GetRawIndices()
		if raw == nil {
			return nil, errors.New("safebrowsing: invalid raw indices")
		}
		return raw.Indices, nil
	case pb.CompressionType_RICE:
		values, err := decodeRiceIntegers(input.GetRiceIndices())
		if err != nil {
			return nil, err
		}
		indices := make([]int32, 0, len(values))
		for _, v := range values {
			indices = append(indices, int32(v))
		}
		return indices, nil
	default:
		return nil, errors.New("safebrowsing: invalid compression type")
	}
}
367912
func DecodeKeys(a ...string) ([]*Key, error) {
	if len(a) == 0 {
		return nil, errNoKeys
	}
	var err error
	ks := make([]*Key, len(a))
	for i, s := range a {
		ks[i], err = DecodeKey(s)
		if err != nil {
			return nil, err
		}
	}
	return ks, nil
}
184763
func decodeHashes(input *pb.ThreatEntrySet) ([]hashPrefix, error) {
	switch input.CompressionType {
	case pb.CompressionType_RAW:
		raw := input.GetRawHashes()
		if raw == nil {
			return nil, errors.New("safebrowsing: nil raw hashes")
		}
		if raw.PrefixSize < minHashPrefixLength || raw.PrefixSize > maxHashPrefixLength {
			return nil, errors.New("safebrowsing: invalid hash prefix length")
		}
		if len(raw.RawHashes)%int(raw.PrefixSize) != 0 {
			return nil, errors.New("safebrowsing: invalid raw hashes")
		}
		hashes := make([]hashPrefix, len(raw.RawHashes)/int(raw.PrefixSize))
		for i := range hashes {
			hashes[i] = hashPrefix(raw.RawHashes[:raw.PrefixSize])
			raw.RawHashes = raw.RawHashes[raw.PrefixSize:]
		}
		return hashes, nil
	case pb.CompressionType_RICE:
		values, err := decodeRiceIntegers(input.GetRiceHashes())
		if err != nil {
			return nil, err
		}
		hashes := make([]hashPrefix, 0, len(values))
		var buf [4]byte
		for _, h := range values {
			binary.LittleEndian.PutUint32(buf[:], h)
			hashes = append(hashes, hashPrefix(buf[:]))
		}
		return hashes, nil
	default:
		return nil, errors.New("safebrowsing: invalid compression type")
	}
}
1041636
func (sf *ScalarFunction) ResolveIndices(schema *Schema) (Expression, error) {
	newSf := sf.Clone()
	err := newSf.resolveIndices(schema)
	return newSf, err
}
1063793
func (d *Context) HexDecode(index int) {
	C.duk_hex_decode(d.duk_context, C.duk_idx_t(index))
}
1328564
func (t *tableCommon) removeRowIndices(ctx sessionctx.Context, h int64, rec []types.Datum) error {
	txn, err := ctx.Txn(true)
	if err != nil {
		return err
	}
	for _, v := range t.DeletableIndices() {
		vals, err := v.FetchValues(rec, nil)
		if err != nil {
			logutil.Logger(context.Background()).Info("remove row index failed", zap.Any("index", v.Meta()), zap.Uint64("txnStartTS", txn.StartTS()), zap.Int64("handle", h), zap.Any("record", rec), zap.Error(err))
			return err
		}
		if err = v.Delete(ctx.GetSessionVars().StmtCtx, txn, vals, h, txn); err != nil {
			if v.Meta().State != model.StatePublic && kv.ErrNotExist.Equal(err) {
				// If the index is not in public state, we may have not created the index,
				// or already deleted the index, so skip ErrNotExist error.
				logutil.Logger(context.Background()).Debug("row index not exists", zap.Any("index", v.Meta()), zap.Uint64("txnStartTS", txn.StartTS()), zap.Int64("handle", h))
				continue
			}
			return err
		}
	}
	return nil
}
633344
func decodeItem(data []byte, i int) (
	result interface{}, index int, err error) {

	var decodeFunc = []func([]byte, int) (interface{}, int, error){
		DecodeString, DecodeInt, DecodeList, DecodeDict,
	}

	for _, f := range decodeFunc {
		result, index, err = f(data, i)
		if err == nil {
			return
		}
	}

	err = errors.New("invalid bencode when decode item")
	return
}
638574
func decodeFindOptions(ctx context.Context, r *http.Request) (*platform.FindOptions, error) {
	opts := &platform.FindOptions{}
	qp := r.URL.Query()

	if offset := qp.Get("offset"); offset != "" {
		o, err := strconv.Atoi(offset)
		if err != nil {
			return nil, err
		}

		opts.Offset = o
	}

	if limit := qp.Get("limit"); limit != "" {
		l, err := strconv.Atoi(limit)
		if err != nil {
			return nil, err
		}

		if l < 1 || l > platform.MaxPageSize {
			return nil, errors.InvalidDataf("limit must be between 1 and %d", platform.MaxPageSize)
		}

		opts.Limit = l
	} else {
		opts.Limit = platform.DefaultPageSize
	}

	if sortBy := qp.Get("sortBy"); sortBy != "" {
		opts.SortBy = sortBy
	}

	if descending := qp.Get("descending"); descending != "" {
		desc, err := strconv.ParseBool(descending)
		if err != nil {
			return nil, err
		}

		opts.Descending = desc
	}

	return opts, nil
}
638169
func (p *Pointer) DecodedTokens() []string {
	result := make([]string, 0, len(p.referenceTokens))
	for _, t := range p.referenceTokens {
		result = append(result, Unescape(t))
	}
	return result
}
978962
func DecodeAttrs(v []byte) (map[string]interface{}, error) {
	var pb internal.AttrMap
	if err := proto.Unmarshal(v, &pb); err != nil {
		return nil, err
	}
	return decodeAttrs(pb.GetAttrs()), nil
}
988559
func (s *CountService) Indices(indices ...string) *CountService {
	if s.index == nil {
		s.index = make([]string, 0)
	}
	s.index = append(s.index, indices...)
	return s
}
355118
func (xr *Reader) decodeIndexes(backSize int64) error {
	pos, err := xr.rd.Seek(0, io.SeekCurrent)
	if err != nil {
		return err
	}

	// Read all indexes.
	var compSize int64
	xr.idxs = xr.idxs[:0]
	for {
		// Seek backwards past index and compressed blocks.
		newPos := pos - (backSize + compSize)
		if newPos < 0 || newPos > pos {
			return errCorrupted // Integer overflow for new seek position
		}
		if pos, err = xr.rd.Seek(newPos, io.SeekStart); err != nil {
			return err
		}
		if backSize == 0 {
			break
		}

		// Read the index.
		if cap(xr.idxs) > len(xr.idxs) {
			xr.idxs = xr.idxs[:len(xr.idxs)+1]
		} else {
			xr.idxs = append(xr.idxs, index{})
		}
		idx := &xr.idxs[len(xr.idxs)-1]
		idx.Reset()
		idx.IndexSize = backSize
		if err = xr.decodeIndex(idx); err != nil {
			return err
		}
		backSize, compSize = idx.BackSize, idx.LastRecord().CompOffset
	}
	if pos != 0 {
		return errCorrupted
	}

	// Compact all indexes into one.
	for i := len(xr.idxs) - 1; i >= 0; i-- {
		idx := xr.idxs[i]
		if !xr.idx.AppendIndex(&idx) {
			return errCorrupted
		}
		if !xr.idx.AppendRecord(idx.IndexSize, 0, indexType) {
			return errCorrupted
		}
	}
	return nil
}
757953
func DecodeList(data []byte, start int) (
	result interface{}, index int, err error) {

	if start >= len(data) || data[start] != 'l' {
		err = errors.New("invalid list bencode")
		return
	}

	var item interface{}
	r := make([]interface{}, 0, 8)

	index = start + 1
	for index < len(data) {
		char, _ := utf8.DecodeRune(data[index:])
		if char == 'e' {
			break
		}

		item, index, err = decodeItem(data, index)
		if err != nil {
			return
		}
		r = append(r, item)
	}

	if index == len(data) {
		err = errors.New("'e' not found when decode list")
		return
	}
	index++

	result = r
	return
}
1263585
func (p *PhysicalMergeJoin) ResolveIndices() (err error) {
	err = p.physicalSchemaProducer.ResolveIndices()
	if err != nil {
		return err
	}
	lSchema := p.children[0].Schema()
	rSchema := p.children[1].Schema()
	for i, col := range p.LeftKeys {
		newKey, err := col.ResolveIndices(lSchema)
		if err != nil {
			return err
		}
		p.LeftKeys[i] = newKey.(*expression.Column)
	}
	for i, col := range p.RightKeys {
		newKey, err := col.ResolveIndices(rSchema)
		if err != nil {
			return err
		}
		p.RightKeys[i] = newKey.(*expression.Column)
	}
	for i, expr := range p.LeftConditions {
		p.LeftConditions[i], err = expr.ResolveIndices(lSchema)
		if err != nil {
			return err
		}
	}
	for i, expr := range p.RightConditions {
		p.RightConditions[i], err = expr.ResolveIndices(rSchema)
		if err != nil {
			return err
		}
	}
	for i, expr := range p.OtherConditions {
		p.OtherConditions[i], err = expr.ResolveIndices(expression.MergeSchema(lSchema, rSchema))
		if err != nil {
			return err
		}
	}
	return
}
896486
func DecodeUints(s string) ([]uint, error) {
	xs := make([]uint, 0)
	var x, shift uint
	for i, c := range []byte(s) {
		switch {
		case 63 <= c && c < 95:
			xs = append(xs, x+(uint(c)-63)<<shift)
			x = 0
			shift = 0
		case 95 <= c && c < 127:
			x += (uint(c) - 95) << shift
			shift += 5
		default:
			return nil, &InvalidCharacterError{i, c}
		}
	}
	if shift != 0 {
		return nil, &UnterminatedError{}
	}
	return xs, nil
}
38509
func (dec *Decoder) DecodeInterface(i *interface{}) error {
	if dec.isPooled == 1 {
		panic(InvalidUsagePooledDecoderError("Invalid usage of pooled decoder"))
	}
	err := dec.decodeInterface(i)
	return err
}
1035091
func (t *tableCommon) addIndices(ctx sessionctx.Context, recordID int64, r []types.Datum, rm kv.RetrieverMutator,
	opt *table.CreateIdxOpt) (int64, error) {
	txn, err := ctx.Txn(true)
	if err != nil {
		return 0, err
	}
	// Clean up lazy check error environment
	defer txn.DelOption(kv.PresumeKeyNotExistsError)
	skipCheck := ctx.GetSessionVars().LightningMode || ctx.GetSessionVars().StmtCtx.BatchCheck
	if t.meta.PKIsHandle && !skipCheck && !opt.SkipHandleCheck {
		if err := CheckHandleExists(ctx, t, recordID, nil); err != nil {
			return recordID, err
		}
	}

	writeBufs := ctx.GetSessionVars().GetWriteStmtBufs()
	indexVals := writeBufs.IndexValsBuf
	for _, v := range t.WritableIndices() {
		var err2 error
		indexVals, err2 = v.FetchValues(r, indexVals)
		if err2 != nil {
			return 0, err2
		}
		var dupKeyErr error
		if !skipCheck && v.Meta().Unique {
			entryKey, err1 := t.genIndexKeyStr(indexVals)
			if err1 != nil {
				return 0, err1
			}
			dupKeyErr = kv.ErrKeyExists.FastGen("Duplicate entry '%s' for key '%s'", entryKey, v.Meta().Name)
			txn.SetOption(kv.PresumeKeyNotExistsError, dupKeyErr)
		}
		if dupHandle, err := v.Create(ctx, rm, indexVals, recordID, opt); err != nil {
			if kv.ErrKeyExists.Equal(err) {
				return dupHandle, dupKeyErr
			}
			return 0, err
		}
		txn.DelOption(kv.PresumeKeyNotExistsError)
	}
	// save the buffer, multi rows insert can use it.
	writeBufs.IndexValsBuf = indexVals
	return 0, nil
}