当前位置: 首页>>代码示例>>Golang>>正文


Golang encoding.EncodeBytes函数代码示例

本文整理汇总了Golang中github.com/cockroachdb/cockroach/util/encoding.EncodeBytes函数的典型用法代码示例。如果您正苦于以下问题:Golang EncodeBytes函数的具体用法?Golang EncodeBytes怎么用?Golang EncodeBytes使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了EncodeBytes函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: newRangeDataIterator

func newRangeDataIterator(d *proto.RangeDescriptor, e engine.Engine) *rangeDataIterator {
	// The first range in the keyspace starts at KeyMin, which includes the node-local
	// space. We need the original StartKey to find the range metadata, but the
	// actual data starts at LocalMax.
	dataStartKey := d.StartKey
	if d.StartKey.Equal(proto.KeyMin) {
		dataStartKey = keys.LocalMax
	}
	ri := &rangeDataIterator{
		ranges: []keyRange{
			{
				start: engine.MVCCEncodeKey(keys.MakeKey(keys.LocalRangeIDPrefix, encoding.EncodeUvarint(nil, uint64(d.RangeID)))),
				end:   engine.MVCCEncodeKey(keys.MakeKey(keys.LocalRangeIDPrefix, encoding.EncodeUvarint(nil, uint64(d.RangeID+1)))),
			},
			{
				start: engine.MVCCEncodeKey(keys.MakeKey(keys.LocalRangePrefix, encoding.EncodeBytes(nil, d.StartKey))),
				end:   engine.MVCCEncodeKey(keys.MakeKey(keys.LocalRangePrefix, encoding.EncodeBytes(nil, d.EndKey))),
			},
			{
				start: engine.MVCCEncodeKey(dataStartKey),
				end:   engine.MVCCEncodeKey(d.EndKey),
			},
		},
		iter: e.NewIterator(),
	}
	ri.iter.Seek(ri.ranges[ri.curIndex].start)
	ri.advance()
	return ri
}
开发者ID:ErikGrimes,项目名称:cockroach,代码行数:29,代码来源:range_data_iter.go

示例2: encodeTableKey

// encodeTableKey encodes a single element of a table key, appending the
// encoded value to b.
func encodeTableKey(b []byte, v reflect.Value) ([]byte, error) {
	switch t := v.Interface().(type) {
	case []byte:
		return roachencoding.EncodeBytes(b, t), nil
	case string:
		return roachencoding.EncodeBytes(b, []byte(t)), nil
	}

	switch v.Kind() {
	case reflect.Bool:
		if v.Bool() {
			return roachencoding.EncodeVarint(b, 1), nil
		}
		return roachencoding.EncodeVarint(b, 0), nil

	case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
		return roachencoding.EncodeVarint(b, v.Int()), nil

	case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
		return roachencoding.EncodeUvarint(b, v.Uint()), nil

	case reflect.Float32, reflect.Float64:
		return roachencoding.EncodeNumericFloat(b, v.Float()), nil

	case reflect.String:
		return roachencoding.EncodeBytes(b, []byte(v.String())), nil
	}

	return nil, fmt.Errorf("unable to encode key: %s", v)
}
开发者ID:Hellblazer,项目名称:cockroach,代码行数:32,代码来源:table.go

示例3: newRangeDataIterator

func newRangeDataIterator(r *Range, e engine.Engine) *rangeDataIterator {
	r.RLock()
	startKey := r.Desc().StartKey
	if startKey.Equal(engine.KeyMin) {
		startKey = engine.KeyLocalMax
	}
	endKey := r.Desc().EndKey
	r.RUnlock()
	ri := &rangeDataIterator{
		ranges: []keyRange{
			{
				start: engine.MVCCEncodeKey(engine.MakeKey(engine.KeyLocalRangeIDPrefix, encoding.EncodeUvarint(nil, uint64(r.Desc().RaftID)))),
				end:   engine.MVCCEncodeKey(engine.MakeKey(engine.KeyLocalRangeIDPrefix, encoding.EncodeUvarint(nil, uint64(r.Desc().RaftID+1)))),
			},
			{
				start: engine.MVCCEncodeKey(engine.MakeKey(engine.KeyLocalRangeKeyPrefix, encoding.EncodeBytes(nil, startKey))),
				end:   engine.MVCCEncodeKey(engine.MakeKey(engine.KeyLocalRangeKeyPrefix, encoding.EncodeBytes(nil, endKey))),
			},
			{
				start: engine.MVCCEncodeKey(startKey),
				end:   engine.MVCCEncodeKey(endKey),
			},
		},
		iter: e.NewIterator(),
	}
	ri.iter.Seek(ri.ranges[ri.curIndex].start)
	ri.advance()
	return ri
}
开发者ID:josephwinston,项目名称:cockroach,代码行数:29,代码来源:range_data_iter.go

示例4: MakeRangeKey

// MakeRangeKey creates a range-local key based on the range
// start key, metadata key suffix, and optional detail (e.g. the
// transaction ID for a txn record, etc.).
func MakeRangeKey(key, suffix, detail roachpb.Key) roachpb.Key {
	if len(suffix) != LocalSuffixLength {
		panic(fmt.Sprintf("suffix len(%q) != %d", suffix, LocalSuffixLength))
	}
	return MakeKey(LocalRangePrefix,
		encoding.EncodeBytes(nil, key), suffix, detail)
}
开发者ID:rohanahata,项目名称:cockroach,代码行数:10,代码来源:keys.go

示例5: encodeTableKey

func encodeTableKey(b []byte, v sqlwire.Datum) ([]byte, error) {
	if v.BoolVal != nil {
		if *v.BoolVal {
			return encoding.EncodeVarint(b, 1), nil
		}
		return encoding.EncodeVarint(b, 0), nil
	} else if v.IntVal != nil {
		return encoding.EncodeVarint(b, *v.IntVal), nil
	} else if v.FloatVal != nil {
		return encoding.EncodeNumericFloat(b, *v.FloatVal), nil
	} else if v.BytesVal != nil {
		return encoding.EncodeBytes(b, v.BytesVal), nil
	} else if v.StringVal != nil {
		return encoding.EncodeBytes(b, []byte(*v.StringVal)), nil
	}
	return nil, fmt.Errorf("unable to encode table key: %T", v)
}
开发者ID:zmoon111,项目名称:cockroach,代码行数:17,代码来源:server.go

示例6: populateTableIndexKey

// populateTableIndexKey populates the key passed in with the
// order encoded values forming the index key.
func populateTableIndexKey(key []byte, tableID, indexID uint32, columnValues ...[]byte) []byte {
	key = append(key, TableDataPrefix...)
	key = encoding.EncodeUvarint(key, uint64(tableID))
	key = encoding.EncodeUvarint(key, uint64(indexID))
	for _, value := range columnValues {
		key = encoding.EncodeBytes(key, value)
	}
	return key
}
开发者ID:routhcr,项目名称:cockroach,代码行数:11,代码来源:keys.go

示例7: encodeTableKey

func encodeTableKey(b []byte, v parser.Datum) ([]byte, error) {
	switch t := v.(type) {
	case parser.DBool:
		if t {
			return encoding.EncodeVarint(b, 1), nil
		}
		return encoding.EncodeVarint(b, 0), nil
	case parser.DInt:
		return encoding.EncodeVarint(b, int64(t)), nil
	case parser.DFloat:
		return encoding.EncodeNumericFloat(b, float64(t)), nil
	case parser.DString:
		return encoding.EncodeBytes(b, []byte(t)), nil
	case parser.DNull:
		// TODO(tamird,pmattis): This is a hack; we should have proper nil encoding.
		return encoding.EncodeBytes(b, nil), nil
	}
	return nil, fmt.Errorf("unable to encode table key: %T", v)
}
开发者ID:arypurnomoz,项目名称:cockroach,代码行数:19,代码来源:table.go

示例8: MakeDataKey

// MakeDataKey creates a time series data key for the given series name, source,
// Resolution and timestamp. The timestamp is expressed in nanoseconds since the
// epoch; it will be truncated to an exact multiple of the supplied
// Resolution's KeyDuration.
func MakeDataKey(name string, source string, r Resolution, timestamp int64) roachpb.Key {
	// Normalize timestamp into a timeslot before recording.
	timeslot := timestamp / r.KeyDuration()

	k := append(roachpb.Key(nil), keyDataPrefix...)
	k = encoding.EncodeBytes(k, []byte(name))
	k = encoding.EncodeVarint(k, int64(r))
	k = encoding.EncodeVarint(k, timeslot)
	k = append(k, source...)
	return k
}
开发者ID:rohanahata,项目名称:cockroach,代码行数:15,代码来源:keys.go

示例9: MakeNameMetadataKey

// MakeNameMetadataKey returns the key for the name. Pass name == "" in order
// to generate the prefix key to use to scan over all of the names for the
// specified parentID.
func MakeNameMetadataKey(parentID ID, name string) roachpb.Key {
	name = normalizeName(name)
	k := keys.MakeTablePrefix(uint32(NamespaceTable.ID))
	k = encoding.EncodeUvarint(k, uint64(NamespaceTable.PrimaryIndex.ID))
	k = encoding.EncodeUvarint(k, uint64(parentID))
	if name != "" {
		k = encoding.EncodeBytes(k, []byte(name))
		k = keys.MakeColumnKey(k, uint32(NamespaceTable.Columns[2].ID))
	}
	return k
}
开发者ID:kaustubhkurve,项目名称:cockroach,代码行数:14,代码来源:keys.go

示例10: encodeTableKey

func encodeTableKey(b []byte, v driver.Value) ([]byte, error) {
	switch t := v.(type) {
	case int64:
		return encoding.EncodeVarint(b, t), nil
	case float64:
		return encoding.EncodeNumericFloat(b, t), nil
	case bool:
		if t {
			return encoding.EncodeVarint(b, 1), nil
		}
		return encoding.EncodeVarint(b, 0), nil
	case []byte:
		return encoding.EncodeBytes(b, t), nil
	case string:
		return encoding.EncodeBytes(b, []byte(t)), nil
	case time.Time:
		return nil, fmt.Errorf("TODO(pmattis): encode index key: time.Time")
	}
	return nil, fmt.Errorf("unable to encode table key: %T", v)
}
开发者ID:Jaekyun,项目名称:cockroach,代码行数:20,代码来源:conn.go

示例11: encodeTableKey

func encodeTableKey(b []byte, v parser.Datum) ([]byte, error) {
	switch t := v.(type) {
	case parser.DBool:
		if t {
			return encoding.EncodeVarint(b, 1), nil
		}
		return encoding.EncodeVarint(b, 0), nil
	case parser.DInt:
		return encoding.EncodeVarint(b, int64(t)), nil
	case parser.DFloat:
		return encoding.EncodeNumericFloat(b, float64(t)), nil
	case parser.DString:
		return encoding.EncodeBytes(b, []byte(t)), nil
	}
	return nil, fmt.Errorf("unable to encode table key: %T", v)
}
开发者ID:yuweiln,项目名称:cockroach,代码行数:16,代码来源:table.go

示例12: MakeRangeKeyPrefix

// MakeRangeKeyPrefix creates a key prefix under which all range-local keys
// can be found.
func MakeRangeKeyPrefix(key roachpb.RKey) roachpb.Key {
	return MakeKey(LocalRangePrefix, encoding.EncodeBytes(nil, key))
}
开发者ID:xujun10110,项目名称:cockroach,代码行数:5,代码来源:keys.go

示例13: ResponseCacheKey

// ResponseCacheKey returns a range-local key by Range ID for a
// response cache entry, with detail specified by encoding the
// supplied client command ID.
func ResponseCacheKey(rangeID roachpb.RangeID, family []byte) roachpb.Key {
	return MakeRangeIDKey(rangeID, LocalResponseCacheSuffix, encoding.EncodeBytes(nil, family))
}
开发者ID:xujun10110,项目名称:cockroach,代码行数:6,代码来源:keys.go

示例14: SequenceCacheKey

// SequenceCacheKey returns a range-local key by Range ID for a
// sequence cache entry, with detail specified by encoding the
// supplied transaction ID, epoch and sequence number.
func SequenceCacheKey(rangeID roachpb.RangeID, id []byte, epoch uint32, seq uint32) roachpb.Key {
	return MakeRangeIDKey(rangeID, LocalSequenceCacheSuffix,
		encoding.EncodeUint32Decreasing(
			encoding.EncodeUint32Decreasing(
				encoding.EncodeBytes(nil, id), epoch), seq))
}
开发者ID:ming-hai,项目名称:cockroach,代码行数:9,代码来源:keys.go

示例15: MakeRangeKey

// MakeRangeKey creates a range-local key based on the range
// start key, metadata key suffix, and optional detail (e.g. the
// transaction UUID for a txn record, etc.).
func MakeRangeKey(key, suffix, detail proto.Key) proto.Key {
	if len(suffix) != KeyLocalSuffixLength {
		panic(fmt.Sprintf("suffix len(%q) != %d", suffix, KeyLocalSuffixLength))
	}
	return MakeKey(KeyLocalRangeKeyPrefix, encoding.EncodeBytes(nil, key), suffix, detail)
}
开发者ID:josephwinston,项目名称:cockroach,代码行数:9,代码来源:keys.go


注:本文中的github.com/cockroachdb/cockroach/util/encoding.EncodeBytes函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。