本文整理汇总了Golang中Time.Time.UnmarshalBinary方法的典型用法代码示例。如果您正苦于以下问题:Golang Time.UnmarshalBinary方法的具体用法?Golang Time.UnmarshalBinary怎么用?Golang Time.UnmarshalBinary使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Time.Time
的用法示例。
在下文中一共展示了Time.UnmarshalBinary方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: unmarshalValue
func (n *scanNode) unmarshalValue(kv client.KeyValue) (parser.Datum, bool) {
kind, ok := n.colKind[n.colID]
if !ok {
n.err = fmt.Errorf("column-id \"%d\" does not exist", n.colID)
return nil, false
}
if kv.Exists() {
switch kind {
case ColumnType_INT:
return parser.DInt(kv.ValueInt()), true
case ColumnType_BOOL:
return parser.DBool(kv.ValueInt() != 0), true
case ColumnType_FLOAT:
return parser.DFloat(math.Float64frombits(uint64(kv.ValueInt()))), true
case ColumnType_STRING, ColumnType_BYTES:
return parser.DString(kv.ValueBytes()), true
case ColumnType_DATE:
var t time.Time
if err := t.UnmarshalBinary(kv.ValueBytes()); err != nil {
return nil, false
}
return parser.DDate{Time: t}, true
case ColumnType_TIMESTAMP:
var t time.Time
if err := t.UnmarshalBinary(kv.ValueBytes()); err != nil {
return nil, false
}
return parser.DTimestamp{Time: t}, true
case ColumnType_INTERVAL:
return parser.DInterval{Duration: time.Duration(kv.ValueInt())}, true
}
}
return parser.DNull, true
}
示例2: GetMtime
func (r *VirtualMtimeRepo) GetMtime(path string, diskMtime time.Time) time.Time {
data, exists := r.ns.Bytes(path)
if !exists {
// Absense of debug print is significant enough in itself here
return diskMtime
}
var mtime time.Time
if err := mtime.UnmarshalBinary(data[:len(data)/2]); err != nil {
panic(fmt.Sprintf("Can't unmarshal stored mtime at path %s: %v", path, err))
}
if mtime.Equal(diskMtime) {
if err := mtime.UnmarshalBinary(data[len(data)/2:]); err != nil {
panic(fmt.Sprintf("Can't unmarshal stored mtime at path %s: %v", path, err))
}
if debug {
l.Debugf("virtual mtime: return %v instead of %v for path: %s", mtime, diskMtime, path)
}
return mtime
}
if debug {
l.Debugf("virtual mtime: record exists, but mismatch inDisk: %v dbDisk: %v for path: %s", diskMtime, mtime, path)
}
return diskMtime
}
示例3: LoadAccess
// Returns a storage session
func (s *RedisStorage) LoadAccess(code string) (*osin.AccessData, error) {
logs.Debug("LoadAccess: %s", code)
d_map, err := s.client.HGetAllMap(code).Result()
if len(d_map) == 0 || err != nil {
return nil, errors.New("Authorize not found")
}
client, err := s.getClient(d_map["client"])
if err != nil {
return nil, err
}
expires_in, _ := strconv.Atoi(d_map["expires_in"])
created_at := new(time.Time)
created_at.UnmarshalBinary([]byte(d_map["created_at"]))
d := &osin.AccessData{
Client: client,
ExpiresIn: int32(expires_in),
Scope: d_map["scope"],
RedirectUri: d_map["redirect_uri"],
CreatedAt: *created_at,
UserData: d_map["user_data"],
}
return d, nil
}
示例4: CheckExpiration
func CheckExpiration() error {
return db.Update(func(tx *bolt.Tx) error {
files := tx.Bucket([]byte("files"))
filesCursor := files.Cursor()
for fileToken, _ := filesCursor.First(); fileToken != nil; fileToken, _ = filesCursor.Next() {
fileBucket := files.Bucket(fileToken)
log.Println("Scanning file token", string(fileToken))
possibleDeletionDate := time.Now()
var deleteDate time.Time
err := deleteDate.UnmarshalBinary(fileBucket.Get([]byte("delete-date")))
if err != nil {
log.Println("Delete date unmarshal error:", err)
continue
}
d, m, y := possibleDeletionDate.Date()
dd, mm, yy := deleteDate.Date()
if d == dd && m == mm && y == yy {
log.Println("Removing file...")
err = os.RemoveAll(path.Join(uppath.UploadedPath, string(fileToken)))
if err != nil {
log.Println("Failed to remove file:", fileToken, " -", err)
continue
}
files.DeleteBucket(fileToken)
}
}
return nil
})
}
示例5: FromProto
func (d *Directory) FromProto(pnd *wire.Node) error {
pbd := pnd.Directory
modTime := time.Time{}
if err := modTime.UnmarshalBinary(pnd.ModTime); err != nil {
return err
}
d.id = pnd.ID
d.modTime = modTime
d.parent = pbd.Parent
d.size = pnd.NodeSize
d.hash = &Hash{pnd.Hash}
d.name = pnd.Name
d.children = make(map[string]*Hash)
// Be cautious, input might come from everywhere:
links := pbd.Links
if len(pbd.Names) != len(links) {
return fmt.Errorf("Malformed input: More or less names than links in `%s`", d.name)
}
// Find our place in the world:
for idx, name := range pbd.Names {
d.children[name] = &Hash{links[idx]}
}
return nil
}
示例6: UnmarshalBinary
// UnmarshalBinary implements the encoding.BinaryUnmarshaler interface.
func (dt *DateTime) UnmarshalBinary(data []byte) error {
var t time.Time
if err := t.UnmarshalBinary(data); err != nil {
return err
}
*dt = DateTimeFromTime(t)
return nil
}
示例7: DeserializeTime
func DeserializeTime(chunk *Chunk, out *time.Time) error {
timeField, err := UnwrapField(chunk)
if err != nil {
return err
}
err = out.UnmarshalBinary(timeField)
return err
}
示例8: Decode
func (p *icmpEcho) Decode() (time.Time, error) {
t := time.Time{}
err := t.UnmarshalBinary(p.Data[:15])
if err != nil {
fmt.Printf("icmpEcho.UnmarshalBinary problem: %v\n", err)
}
return t, err
}
示例9: Time
// Time returns the stored value interpreted as a time.Time and a boolean
// that is false if no value was stored at the key.
func (n NamespacedKV) Time(key string) (time.Time, bool) {
var t time.Time
keyBs := append(n.prefix, []byte(key)...)
valBs, err := n.db.Get(keyBs, nil)
if err != nil {
return t, false
}
err = t.UnmarshalBinary(valBs)
return t, err == nil
}
示例10: GetLastSeen
func (s *DeviceStatisticsReference) GetLastSeen() time.Time {
value, err := s.db.Get(s.key(deviceStatisticTypeLastSeen), nil)
if err != nil {
if err != leveldb.ErrNotFound {
l.Warnln("DeviceStatisticsReference: Failed loading last seen value for", s.device, ":", err)
}
return time.Unix(0, 0)
}
rtime := time.Time{}
err = rtime.UnmarshalBinary(value)
if err != nil {
l.Warnln("DeviceStatisticsReference: Failed parsing last seen value for", s.device, ":", err)
return time.Unix(0, 0)
}
if debug {
l.Debugln("stats.DeviceStatisticsReference.GetLastSeen:", s.device, rtime)
}
return rtime
}
示例11: FromProto
func (f *File) FromProto(pnd *wire.Node) error {
pfi := pnd.File
if pfi == nil {
return fmt.Errorf("File attribute is empty. This is likely not a real file.")
}
modTime := time.Time{}
if err := modTime.UnmarshalBinary(pnd.ModTime); err != nil {
return err
}
f.id = pnd.ID
f.size = pnd.NodeSize
f.modTime = modTime
f.hash = &Hash{pnd.Hash}
f.parent = pfi.Parent
f.name = pnd.Name
f.key = pfi.Key
return nil
}
示例12: Inspect
func Inspect() ([]interface{}, error) {
ret := make([]interface{}, 0)
err := db.View(func(tx *bolt.Tx) error {
files := tx.Bucket([]byte("files"))
files.ForEach(func(fileToken, _ []byte) error {
fileInfo := files.Bucket(fileToken)
days, _ := strconv.Atoi(string(fileInfo.Get([]byte("expires-in"))))
var creationTime, deleteDate time.Time
var err error
err = creationTime.UnmarshalBinary(fileInfo.Get([]byte("creation-time")))
if err != nil {
log.Println("Created date unmarshal error:", err)
}
err = deleteDate.UnmarshalBinary(fileInfo.Get([]byte("delete-date")))
if err != nil {
log.Println("Delete date unmarshal error:", err)
}
data := struct {
Days int
Filename string
Created string
DeleteDate string
}{
days,
string(fileInfo.Get([]byte("filename"))),
creationTime.String(),
deleteDate.String(),
}
ret = append(ret, data)
return nil
})
return nil
})
if err != nil {
return nil, err
}
return ret, nil
}
示例13: parseMetadata
func parseMetadata(metadata []byte) (byte, *time.Time, error) {
if len(metadata) < 2 {
return None, nil, ErrMetaFormat
}
if metadata[0] != MetaVersion {
return None, nil, ErrMetaFormat
}
tipe := metadata[1] & 0x0F // lower 4 bits of metadata[1] is type
hasExpire := metadata[1]&byte(0xF0) == byte(0x10)
if !hasExpire {
return tipe, nil, nil
}
var expireAt time.Time
err := expireAt.UnmarshalBinary(metadata[2:])
if err != nil {
return None, nil, ErrMetaFormat
}
return tipe, &expireAt, nil
}
示例14: Fuzz
func Fuzz(data []byte) int {
var t time.Time
if err := t.UnmarshalText(data); err != nil {
return 0
}
data1, err := t.MarshalText()
if err != nil {
panic(err)
}
var t1 time.Time
if err := t1.UnmarshalText(data1); err != nil {
panic(err)
}
if !fuzz.DeepEqual(t, t1) {
fmt.Printf("t0: %#v\n", t)
fmt.Printf("t1: %#v\n", t1)
panic("bad MarshalText")
}
data2, err := t.GobEncode()
if err != nil {
panic(err)
}
var t2 time.Time
if err := t2.GobDecode(data2); err != nil {
panic(err)
}
if !fuzz.DeepEqual(t, t2) {
fmt.Printf("t0: %#v\n", t)
fmt.Printf("t2: %#v\n", t2)
panic("bad GobEncode")
}
data3, err := t.MarshalBinary()
if err != nil {
panic(err)
}
var t3 time.Time
if err := t3.UnmarshalBinary(data3); err != nil {
panic(err)
}
if !fuzz.DeepEqual(t, t3) {
fmt.Printf("t0: %#v\n", t)
fmt.Printf("t3: %#v\n", t3)
panic("bad MarshalBinary")
}
data4, err := t.MarshalJSON()
if err != nil {
panic(err)
}
var t4 time.Time
if err := t4.UnmarshalJSON(data4); err != nil {
panic(err)
}
if !fuzz.DeepEqual(t, t4) {
fmt.Printf("t0: %#v\n", t)
fmt.Printf("t4: %#v\n", t4)
panic("bad MarshalJSON")
}
data5, err := t.MarshalText()
if err != nil {
panic(err)
}
var t5 time.Time
if err := t5.UnmarshalText(data5); err != nil {
panic(err)
}
if !fuzz.DeepEqual(t, t5) {
fmt.Printf("t0: %#v\n", t)
fmt.Printf("t5: %#v\n", t5)
panic("bad MarshalText")
}
data6 := t.Format(time.RFC3339Nano)
t6, err := time.Parse(time.RFC3339Nano, data6)
if err != nil {
panic(err)
}
if !fuzz.DeepEqual(t, t6) {
fmt.Printf("t0: %#v\n", t)
fmt.Printf("t6: %#v\n", t6)
panic("bad Format")
}
return 1
}
示例15: main
//.........这里部分代码省略.........
cluster, err := builder.Build()
if err != nil {
fmt.Printf("cannot build cluster: %v\n", err.Error())
return
}
producer, err := client.NewProducer(cluster, client.ProducerConfig{
QueueTime: queueTime,
QueueSize: queueSize,
})
if err != nil {
println("failed to create producer: " + err.Error())
return
}
consumer, err := cluster.Consume(true, topic)
go func() {
for {
payload, _ := time.Now().UTC().MarshalBinary()
producer.Append(topic, 0, payload)
}
}()
timeInMessage := new(time.Time)
timer := time.NewTicker(1 * time.Second)
histogram := hdrhistogram.New(0, time.Minute.Nanoseconds(), 5)
for {
select {
case messages := <-consumer.Messages():
for _, rawMessage := range messages.Messages.Messages() {
payload := rawMessage[storage.HEADER_LENGTH:]
if err := timeInMessage.UnmarshalBinary(payload); err != nil {
fmt.Printf("skipping message: %v\n", err.Error())
continue
}
histogram.RecordValue(time.Since(*timeInMessage).Nanoseconds() / 1e6)
}
case <-timer.C:
fmt.Printf("p95: %vms\n", histogram.ValueAtQuantile(0.95))
fmt.Printf("p50: %vms\n", histogram.ValueAtQuantile(0.50))
fmt.Printf("mean: %vms\n", histogram.Mean())
fmt.Printf("min: %vms\n", histogram.Min())
fmt.Printf("max: %vms\n", histogram.Max())
fmt.Printf("count: %v\n", histogram.TotalCount())
}
}
},
},
cli.Command{
Name: "consume",
Flags: []cli.Flag{
cli.StringFlag{
Name: "hosts",
Value: "localhost:5050",
EnvVar: "EDGY_HOSTS",
},
cli.StringFlag{
Name: "topics",
Value: "writebench",
},
cli.BoolFlag{
Name: "devnull",