Commit 656e08ce authored by whyrusleeping's avatar whyrusleeping

use unix nanoseconds for encoding Cbortime

parent 9d087a72
......@@ -696,43 +696,22 @@ func (ci *CborInt) UnmarshalCBOR(r io.Reader) error {
type CborTime time.Time
func (ct *CborTime) MarshalCBOR(w io.Writer) error {
b, err := (*time.Time)(ct).MarshalBinary()
if err != nil {
return err
}
nsecs := ct.Time().UnixNano()
if err := CborWriteHeader(w, MajByteString, uint64(len(b))); err != nil {
return err
}
cbi := CborInt(nsecs)
if _, err := w.Write(b); err != nil {
return err
}
return nil
return cbi.MarshalCBOR(w)
}
func (ct *CborTime) UnmarshalCBOR(r io.Reader) error {
t, l, err := CborReadHeader(r)
if err != nil {
var cbi CborInt
if err := cbi.UnmarshalCBOR(r); err != nil {
return err
}
if t != MajByteString {
return fmt.Errorf("CborTime expects to find a byte array (got %d)", t)
}
buf := make([]byte, l)
if _, err := io.ReadFull(r, buf); err != nil {
return err
}
tm := time.Time{}
if err := tm.UnmarshalBinary(buf); err != nil {
return err
}
t := time.Unix(0, int64(cbi))
*ct = (CborTime)(tm)
*ct = (CborTime)(t)
return nil
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment