本文整理汇总了Golang中github.com/cockroachdb/cockroach/util/encoding.DecodeTime函数的典型用法代码示例。如果您正苦于以下问题:Golang DecodeTime函数的具体用法?Golang DecodeTime怎么用?Golang DecodeTime使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了DecodeTime函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: decodeTableKey
func decodeTableKey(valType parser.Datum, key []byte) (parser.Datum, []byte, error) {
var isNull bool
if key, isNull = encoding.DecodeIfNull(key); isNull {
return parser.DNull, key, nil
}
switch valType.(type) {
case parser.DBool:
rkey, i, err := encoding.DecodeVarint(key)
return parser.DBool(i != 0), rkey, err
case parser.DInt:
rkey, i, err := encoding.DecodeVarint(key)
return parser.DInt(i), rkey, err
case parser.DFloat:
rkey, f, err := encoding.DecodeFloat(key, nil)
return parser.DFloat(f), rkey, err
case parser.DString:
rkey, r, err := encoding.DecodeString(key, nil)
return parser.DString(r), rkey, err
case parser.DBytes:
rkey, r, err := encoding.DecodeString(key, nil)
return parser.DBytes(r), rkey, err
case parser.DDate:
rkey, t, err := encoding.DecodeTime(key)
return parser.DDate{Time: t}, rkey, err
case parser.DTimestamp:
rkey, t, err := encoding.DecodeTime(key)
return parser.DTimestamp{Time: t}, rkey, err
case parser.DInterval:
rkey, d, err := encoding.DecodeVarint(key)
return parser.DInterval{Duration: time.Duration(d)}, rkey, err
default:
return nil, nil, util.Errorf("TODO(pmattis): decoded index key: %s", valType.Type())
}
}
示例2: GetTime
// GetTime decodes a time value from the bytes field of the receiver. If the
// tag is not TIME an error will be returned.
func (v *Value) GetTime() (time.Time, error) {
if tag := v.GetTag(); tag != ValueType_TIME {
return time.Time{}, fmt.Errorf("value type is not TIME: %s", tag)
}
_, t := encoding.DecodeTime(v.Bytes)
return t, nil
}
示例3: GetTime
// GetTime decodes a time value from the bytes field of the receiver. If the
// tag is not TIME an error will be returned.
func (v Value) GetTime() (time.Time, error) {
if tag := v.Tag; tag != ValueType_TIME {
return time.Time{}, fmt.Errorf("value type is not %s: %s", ValueType_TIME, tag)
}
_, t, err := encoding.DecodeTime(v.RawBytes)
if err != nil {
return t, err
}
return t, nil
}
示例4: prettyKey
// prettyKey pretty-prints the specified key, skipping over the first skip
// fields.
func prettyKey(key roachpb.Key, skip int) string {
if !bytes.HasPrefix(key, keys.TableDataPrefix) {
return fmt.Sprintf("index key missing table data prefix: %q vs %q",
key, keys.TableDataPrefix)
}
key = key[len(keys.TableDataPrefix):]
var buf bytes.Buffer
for k := 0; len(key) > 0; k++ {
var d interface{}
var err error
switch encoding.PeekType(key) {
case encoding.Null:
key, _ = encoding.DecodeIfNull(key)
d = parser.DNull
case encoding.NotNull:
key, _ = encoding.DecodeIfNotNull(key)
d = "#"
case encoding.Int:
var i int64
key, i, err = encoding.DecodeVarint(key)
d = parser.DInt(i)
case encoding.Float:
var f float64
key, f, err = encoding.DecodeFloat(key, nil)
d = parser.DFloat(f)
case encoding.Bytes:
var s string
key, s, err = encoding.DecodeString(key, nil)
d = parser.DString(s)
case encoding.Time:
var t time.Time
key, t, err = encoding.DecodeTime(key)
d = parser.DTimestamp{Time: t}
default:
// This shouldn't ever happen, but if it does let the loop exit.
key = nil
d = "unknown"
}
if skip > 0 {
skip--
continue
}
if err != nil {
fmt.Fprintf(&buf, "/<%v>", err)
continue
}
fmt.Fprintf(&buf, "/%s", d)
}
return buf.String()
}
示例5: decodeTableKey
func decodeTableKey(valType parser.Datum, key []byte) (parser.Datum, []byte, error) {
var isNull bool
if key, isNull = encoding.DecodeIfNull(key); isNull {
return parser.DNull, key, nil
}
switch valType.(type) {
case parser.DBool:
var i int64
key, i = encoding.DecodeVarint(key)
return parser.DBool(i != 0), key, nil
case parser.DInt:
var i int64
key, i = encoding.DecodeVarint(key)
return parser.DInt(i), key, nil
case parser.DFloat:
var f float64
key, f = encoding.DecodeFloat(key, nil)
return parser.DFloat(f), key, nil
case parser.DString:
var r string
key, r = encoding.DecodeString(key, nil)
return parser.DString(r), key, nil
case parser.DDate:
var t time.Time
key, t = encoding.DecodeTime(key)
return parser.DDate{Time: t}, key, nil
case parser.DTimestamp:
var t time.Time
key, t = encoding.DecodeTime(key)
return parser.DTimestamp{Time: t}, key, nil
case parser.DInterval:
var d int64
key, d = encoding.DecodeVarint(key)
return parser.DInterval{Duration: time.Duration(d)}, key, nil
default:
return nil, nil, util.Errorf("TODO(pmattis): decoded index key: %s", valType.Type())
}
}
示例6: decodeKeyPrint
func decodeKeyPrint(key roachpb.Key) string {
var buf bytes.Buffer
for k := 0; len(key) > 0; k++ {
var err error
switch encoding.PeekType(key) {
case encoding.Null:
key, _ = encoding.DecodeIfNull(key)
fmt.Fprintf(&buf, "/NULL")
case encoding.NotNull:
key, _ = encoding.DecodeIfNotNull(key)
fmt.Fprintf(&buf, "/#")
case encoding.Int:
var i int64
key, i, err = encoding.DecodeVarint(key)
if err == nil {
fmt.Fprintf(&buf, "/%d", i)
}
case encoding.Float:
var f float64
key, f, err = encoding.DecodeFloat(key, nil)
if err == nil {
fmt.Fprintf(&buf, "/%f", f)
}
case encoding.Bytes:
var s string
key, s, err = encoding.DecodeString(key, nil)
if err == nil {
fmt.Fprintf(&buf, "/%q", s)
}
case encoding.Time:
var t time.Time
key, t, err = encoding.DecodeTime(key)
if err == nil {
fmt.Fprintf(&buf, "/%s", t.UTC().Format(time.UnixDate))
}
default:
// This shouldn't ever happen, but if it does let the loop exit.
fmt.Fprintf(&buf, "/%q", []byte(key))
key = nil
}
if err != nil {
fmt.Fprintf(&buf, "/<%v>", err)
continue
}
}
return buf.String()
}