本文整理汇总了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())
}
}
开发者ID:rohanahata,项目名称:cockroach,代码行数:34,代码来源:table.go
示例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
}
开发者ID:kumarh1982,项目名称:cockroach,代码行数:9,代码来源:data.go
示例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
}
开发者ID:mbertschler,项目名称:cockroach,代码行数:12,代码来源:data.go
示例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()
}
开发者ID:nporsche,项目名称:cockroach,代码行数:53,代码来源:scan.go
示例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())
}
}
开发者ID:husttom,项目名称:cockroach,代码行数:38,代码来源:table.go
示例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()
}
开发者ID:kaustubhkurve,项目名称:cockroach,代码行数:48,代码来源:printer.go
注:本文中的github.com/cockroachdb/cockroach/util/encoding.DecodeTime函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论