123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- package gopacket
- import (
- "fmt"
- "math"
- "time"
- )
- type TimestampResolution struct {
- Base, Exponent int
- }
- func (t TimestampResolution) String() string {
- return fmt.Sprintf("%d^%d", t.Base, t.Exponent)
- }
- func (t TimestampResolution) ToDuration() time.Duration {
- if t.Base == 0 {
- return 0
- }
- if t.Exponent == 0 {
- return time.Second
- }
- switch t.Base {
- case 10:
- return time.Duration(math.Pow10(t.Exponent + 9))
- case 2:
- if t.Exponent < 0 {
- return time.Second >> uint(-t.Exponent)
- }
- return time.Second << uint(t.Exponent)
- default:
-
- return time.Duration(float64(time.Second) * math.Pow(float64(t.Base), float64(t.Exponent)))
- }
- }
- var TimestampResolutionInvalid = TimestampResolution{}
- var TimestampResolutionMillisecond = TimestampResolution{10, -3}
- var TimestampResolutionMicrosecond = TimestampResolution{10, -6}
- var TimestampResolutionNanosecond = TimestampResolution{10, -9}
- var TimestampResolutionNTP = TimestampResolution{2, -32}
- var TimestampResolutionCaptureInfo = TimestampResolutionNanosecond
- type PacketSourceResolution interface {
-
- Resolution() TimestampResolution
- }
|