本文整理匯總了Golang中Time.Time.MarshalBinary方法的典型用法代碼示例。如果您正苦於以下問題:Golang Time.MarshalBinary方法的具體用法?Golang Time.MarshalBinary怎麽用?Golang Time.MarshalBinary使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Time.Time
的用法示例。
在下文中一共展示了Time.MarshalBinary方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: SaveTime
func (l *LoadSaver) SaveTime(t time.Time) {
byts, err := t.MarshalBinary()
if err != nil {
l.Err = err
return
}
l.put(byts)
}
示例2: SerializeTime
func SerializeTime(value time.Time) []byte {
buf, err := value.MarshalBinary()
if err != nil {
log.Errorf("Failed to serialize time value %v: %v", value, err)
return make([]byte, 0)
}
return WrapBufInLen(buf)
}
示例3: UpdateMtime
func (r *VirtualMtimeRepo) UpdateMtime(path string, diskMtime, actualMtime time.Time) {
l.Debugf("virtual mtime: storing values for path:%s disk:%v actual:%v", path, diskMtime, actualMtime)
diskBytes, _ := diskMtime.MarshalBinary()
actualBytes, _ := actualMtime.MarshalBinary()
data := append(diskBytes, actualBytes...)
r.ns.PutBytes(path, data)
}
示例4: NewCursorFromSource
func NewCursorFromSource(eventID uuid.UUID, createdAt time.Time) CursorEvents {
res := make([]byte, lengthCursor)
copy(res, eventID.Bytes())
b2, err := createdAt.MarshalBinary()
if err != nil {
println("[WARNING] marshal time", err.Error())
}
copy(res[16:], b2)
return CursorEvents(Base64(res))
}
示例5: encodeMetadata
func encodeMetadata(tipe byte, expireAt *time.Time) []byte {
if expireAt == nil || expireAt.IsZero() {
return []byte{MetaVersion, tipe}
}
expire, _ := expireAt.MarshalBinary()
metadata := make([]byte, 1 /*version*/ +1 /*hasExpire + type*/ +len(expire))
metadata[0] = MetaVersion
metadata[1] = 0x10 | tipe
copy(metadata[2:], expire)
return metadata
}
示例6: newSession
func (rh *RandHound) newSession(public abstract.Point, purpose string, time time.Time) (*Session, []byte, error) {
buf := new(bytes.Buffer)
pub, err := public.MarshalBinary()
if err != nil {
return nil, nil, err
}
if err = binary.Write(buf, binary.LittleEndian, pub); err != nil {
return nil, nil, err
}
tm, err := time.MarshalBinary()
if err != nil {
return nil, nil, err
}
if err = binary.Write(buf, binary.LittleEndian, tm); err != nil {
return nil, nil, err
}
if err = binary.Write(buf, binary.LittleEndian, []byte(purpose)); err != nil {
return nil, nil, err
}
return &Session{
Fingerprint: pub,
Purpose: purpose,
Time: time}, rh.hash(buf.Bytes()), nil
}
示例7: PutTime
// PutTime stores a new time.Time. Any existing value (even if of another
// type) is overwritten.
func (n *NamespacedKV) PutTime(key string, val time.Time) {
keyBs := append(n.prefix, []byte(key)...)
valBs, _ := val.MarshalBinary() // never returns an error
n.db.Put(keyBs, valBs, nil)
}
示例8: 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
}
示例9: sessionID
func (rh *RandHound) sessionID(nodes int, faulty int, purpose string, time time.Time, rand []byte, threshold []int, clientKey abstract.Point, serverKey [][]abstract.Point) ([]byte, error) {
buf := new(bytes.Buffer)
if len(threshold) != len(serverKey) {
return nil, fmt.Errorf("Non-matching number of group thresholds and keys")
}
if err := binary.Write(buf, binary.LittleEndian, uint32(nodes)); err != nil {
return nil, err
}
if err := binary.Write(buf, binary.LittleEndian, uint32(faulty)); err != nil {
return nil, err
}
if _, err := buf.WriteString(purpose); err != nil {
return nil, err
}
t, err := time.MarshalBinary()
if err != nil {
return nil, err
}
if _, err := buf.Write(t); err != nil {
return nil, err
}
if _, err := buf.Write(rand); err != nil {
return nil, err
}
cb, err := clientKey.MarshalBinary()
if err != nil {
return nil, err
}
if _, err := buf.Write(cb); err != nil {
return nil, err
}
for _, t := range threshold {
if err := binary.Write(buf, binary.LittleEndian, uint32(t)); err != nil {
return nil, err
}
}
for _, gk := range serverKey {
for _, k := range gk {
kb, err := k.MarshalBinary()
if err != nil {
return nil, err
}
if _, err := buf.Write(kb); err != nil {
return nil, err
}
}
}
return crypto.HashBytes(rh.Suite().Hash(), buf.Bytes())
}