本文整理汇总了Golang中github.com/cockroachdb/cockroach/util/encoding.EncodeTime函数的典型用法代码示例。如果您正苦于以下问题:Golang EncodeTime函数的具体用法?Golang EncodeTime怎么用?Golang EncodeTime使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了EncodeTime函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: encodeTableKey
func encodeTableKey(b []byte, val parser.Datum) ([]byte, error) {
if val == parser.DNull {
return encoding.EncodeNull(b), nil
}
switch t := val.(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.EncodeFloat(b, float64(t)), nil
case parser.DString:
return encoding.EncodeString(b, string(t)), nil
case parser.DBytes:
return encoding.EncodeString(b, string(t)), nil
case parser.DDate:
return encoding.EncodeTime(b, t.Time), nil
case parser.DTimestamp:
return encoding.EncodeTime(b, t.Time), nil
case parser.DInterval:
return encoding.EncodeVarint(b, int64(t.Duration)), nil
}
return nil, fmt.Errorf("unable to encode table key: %T", val)
}
示例2: SetTime
// SetTime encodes the specified time value into the bytes field of the
// receiver and sets the tag.
func (v *Value) SetTime(t time.Time) {
v.RawBytes = encoding.EncodeTime(nil, t)
v.Tag = ValueType_TIME
}
示例3: TestPrettyPrint
func TestPrettyPrint(t *testing.T) {
defer leaktest.AfterTest(t)
tm, _ := time.Parse(time.UnixDate, "Sat Mar 7 11:06:39 UTC 2015")
testCases := []struct {
key roachpb.Key
exp string
}{
// local
{StoreIdentKey(), "/Local/Store/storeIdent"},
{StoreGossipKey(), "/Local/Store/gossipBootstrap"},
{SequenceCacheKeyPrefix(roachpb.RangeID(1000001), []byte("test0")), `/Local/RangeID/1000001/SequenceCache/"test0"`},
{SequenceCacheKey(roachpb.RangeID(1000001), []byte("test0"), uint32(111), uint32(222)), `/Local/RangeID/1000001/SequenceCache/"test0"/epoch:111/seq:222`},
{RaftLeaderLeaseKey(roachpb.RangeID(1000001)), "/Local/RangeID/1000001/RaftLeaderLease"},
{RaftTombstoneKey(roachpb.RangeID(1000001)), "/Local/RangeID/1000001/RaftTombstone"},
{RaftHardStateKey(roachpb.RangeID(1000001)), "/Local/RangeID/1000001/RaftHardState"},
{RaftAppliedIndexKey(roachpb.RangeID(1000001)), "/Local/RangeID/1000001/RaftAppliedIndex"},
{RaftLogKey(roachpb.RangeID(1000001), uint64(200001)), "/Local/RangeID/1000001/RaftLog/logIndex:200001"},
{RaftTruncatedStateKey(roachpb.RangeID(1000001)), "/Local/RangeID/1000001/RaftTruncatedState"},
{RaftLastIndexKey(roachpb.RangeID(1000001)), "/Local/RangeID/1000001/RaftLastIndex"},
{RangeLastVerificationTimestampKey(roachpb.RangeID(1000001)), "/Local/RangeID/1000001/RangeLastVerificationTimestamp"},
{RangeStatsKey(roachpb.RangeID(1000001)), "/Local/RangeID/1000001/RangeStats"},
{MakeRangeKeyPrefix(roachpb.RKey("ok")), `/Local/Range/"ok"`},
{RangeDescriptorKey(roachpb.RKey("111")), `/Local/Range/RangeDescriptor/"111"`},
{RangeTreeNodeKey(roachpb.RKey("111")), `/Local/Range/RangeTreeNode/"111"`},
{TransactionKey(roachpb.Key("111"), []byte("22222")), `/Local/Range/Transaction/addrKey:/"111"/id:"22222"`},
{LocalMax, "/Local/Max"},
// system
{roachpb.MakeKey(Meta2Prefix, roachpb.Key("foo")), `/Meta2/"foo"`},
{roachpb.MakeKey(Meta1Prefix, roachpb.Key("foo")), `/Meta1/"foo"`},
{StoreStatusKey(2222), "/System/StatusStore/2222"},
{NodeStatusKey(1111), "/System/StatusNode/1111"},
{SystemMax, "/System/Max"},
// table
{UserTableDataMin, "/Table/50"},
{MakeTablePrefix(111), "/Table/111"},
{MakeKey(MakeTablePrefix(42), roachpb.RKey("foo")), `/Table/42/"foo"`},
{MakeKey(MakeTablePrefix(42), roachpb.RKey(encoding.EncodeFloat(nil, float64(233.221112)))), "/Table/42/233.221112"},
{MakeKey(MakeTablePrefix(42), roachpb.RKey(encoding.EncodeVarint(nil, 1222)), roachpb.RKey(encoding.EncodeString(nil, "handsome man"))), `/Table/42/1222/"handsome man"`},
{MakeKey(MakeTablePrefix(42), roachpb.RKey(encoding.EncodeBytes(nil, []byte{1, 2, 8, 255}))), `/Table/42/"\x01\x02\b\xff"`},
{MakeKey(MakeTablePrefix(42), roachpb.RKey(encoding.EncodeBytes(nil, []byte{1, 2, 8, 255})), roachpb.RKey("bar")), `/Table/42/"\x01\x02\b\xff"/"bar"`},
{MakeKey(MakeTablePrefix(42), roachpb.RKey(encoding.EncodeNull(nil))), "/Table/42/NULL"},
{MakeKey(MakeTablePrefix(42), roachpb.RKey(encoding.EncodeNotNull(nil))), "/Table/42/#"},
{MakeKey(MakeTablePrefix(42), roachpb.RKey(encoding.EncodeTime(nil, tm))), "/Table/42/Sat Mar 7 11:06:39 UTC 2015"},
// others
{MakeKey([]byte("")), "/Min"},
{MakeKey(MakeTablePrefix(42), roachpb.RKey([]byte{0x20, 'a', 0x00, 0x02})), "/Table/42/<util/encoding/encoding.go:407: unknown escape>"},
}
for i, test := range testCases {
keyInfo := PrettyPrint(test.key)
if test.exp != keyInfo {
t.Fatalf("%d: expected %s, got %s", i, test.exp, keyInfo)
}
if test.exp != test.key.String() {
t.Fatalf("%d: expected %s, got %s", i, test.exp, keyInfo)
}
}
}
示例4: SetTime
// SetTime encodes the specified time value into the bytes field of the
// receiver, sets the tag and clears the checksum.
func (v *Value) SetTime(t time.Time) {
v.RawBytes = make([]byte, headerSize, 16)
v.RawBytes = encoding.EncodeTime(v.RawBytes[:headerSize], t)
v.setTag(ValueType_TIME)
}