time.go 429 B

12345678910111213141516171819202122
  1. package protocol
  2. import (
  3. "math/rand"
  4. "github.com/v2ray/v2ray-core/common/serial"
  5. )
  6. type Timestamp int64
  7. func (this Timestamp) Bytes() []byte {
  8. return serial.Int64Literal(this).Bytes()
  9. }
  10. type TimestampGenerator func() Timestamp
  11. func NewTimestampGenerator(base Timestamp, delta int) TimestampGenerator {
  12. return func() Timestamp {
  13. rangeInDelta := rand.Intn(delta*2) - delta
  14. return base + Timestamp(rangeInDelta)
  15. }
  16. }