mirror of
https://github.com/fhmq/hmq.git
synced 2026-08-31 23:04:52 +00:00
* modify * update * add acl * add feature * update dockerfile * add deploy * update * update * plugins * plugins * update * update * update * fixed * remove * fixed * add log * update * fixed * update * fix config * add http api * add http api * resp * add config for work chan * update * fixed * update * disable trace * fixed * change acl * fixed * fixed res * dd * dd * ddd * dd * update * fixed * update * add * fixed * update key * add log * update * format * update * update auth * update * update readme * added * update * fixed * fixed * fix * upade * update * update
41 lines
744 B
Go
41 lines
744 B
Go
package sarama
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
)
|
|
|
|
type Timestamp struct {
|
|
*time.Time
|
|
}
|
|
|
|
func (t Timestamp) encode(pe packetEncoder) error {
|
|
timestamp := int64(-1)
|
|
|
|
if !t.Before(time.Unix(0, 0)) {
|
|
timestamp = t.UnixNano() / int64(time.Millisecond)
|
|
} else if !t.IsZero() {
|
|
return PacketEncodingError{fmt.Sprintf("invalid timestamp (%v)", t)}
|
|
}
|
|
|
|
pe.putInt64(timestamp)
|
|
return nil
|
|
}
|
|
|
|
func (t Timestamp) decode(pd packetDecoder) error {
|
|
millis, err := pd.getInt64()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
// negative timestamps are invalid, in these cases we should return
|
|
// a zero time
|
|
timestamp := time.Time{}
|
|
if millis >= 0 {
|
|
timestamp = time.Unix(millis/1000, (millis%1000)*int64(time.Millisecond))
|
|
}
|
|
|
|
*t.Time = timestamp
|
|
return nil
|
|
}
|