(tm time.Time)
| 49 | } |
| 50 | |
| 51 | func (e *Encoder) encodeTime(tm time.Time) []byte { |
| 52 | if e.timeBuf == nil { |
| 53 | e.timeBuf = make([]byte, 12) |
| 54 | } |
| 55 | |
| 56 | secs := uint64(tm.Unix()) |
| 57 | if secs>>34 == 0 { |
| 58 | data := uint64(tm.Nanosecond())<<34 | secs |
| 59 | |
| 60 | if data&0xffffffff00000000 == 0 { |
| 61 | b := e.timeBuf[:4] |
| 62 | binary.BigEndian.PutUint32(b, uint32(data)) |
| 63 | return b |
| 64 | } |
| 65 | |
| 66 | b := e.timeBuf[:8] |
| 67 | binary.BigEndian.PutUint64(b, data) |
| 68 | return b |
| 69 | } |
| 70 | |
| 71 | b := e.timeBuf[:12] |
| 72 | binary.BigEndian.PutUint32(b, uint32(tm.Nanosecond())) |
| 73 | binary.BigEndian.PutUint64(b[4:], secs) |
| 74 | return b |
| 75 | } |
| 76 | |
| 77 | func (d *Decoder) DecodeTime() (time.Time, error) { |
| 78 | c, err := d.readCode() |
no outgoing calls
no test coverage detected