diff options
author | Luke Shumaker <lukeshu@lukeshu.com> | 2020-02-02 23:11:21 -0500 |
---|---|---|
committer | Luke Shumaker <lukeshu@lukeshu.com> | 2020-02-02 23:11:21 -0500 |
commit | 1e253b011f916544879ab3a2d3060c2e982a0c9d (patch) | |
tree | c96b1de5d159b9b4a29ba22e00e6f45d2fd1a037 /rrdformat/rrdbinary/types.go | |
parent | b3d7493f5e8b20378ec2e41a10459e4339d538e9 (diff) |
rrdbinary: Decode CDEF RPN tokens crammed in to Unival parameters
Diffstat (limited to 'rrdformat/rrdbinary/types.go')
-rw-r--r-- | rrdformat/rrdbinary/types.go | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/rrdformat/rrdbinary/types.go b/rrdformat/rrdbinary/types.go index e3011d5..b8001af 100644 --- a/rrdformat/rrdbinary/types.go +++ b/rrdformat/rrdbinary/types.go @@ -12,6 +12,9 @@ type Architecture struct { // C `double` DoubleWidth int // always 8 -- we assume IEEE 754 doubles DoubleAlign int + // C `short` + ShortWidth int + ShortAlign int // C `long` or `unsigned long` LongWidth int LongAlign int @@ -27,15 +30,21 @@ type String string // \0-terminated type Double float64 // 8 bytes type ULong uint64 // 4 or 8 bytes type Long int64 // 4 or 8 bytes -type Unival uint64 // 8 bytes type Time int64 // 4 or 8 bytes, only has second-precision type EOF struct{} // 0 bytes -func (u Unival) AsULong() ULong { return ULong(u) } -func (u Unival) AsDouble() Double { return Double(math.Float64frombits(uint64(u))) } +type Unival struct { + arch Architecture + data []byte // 8 bytes +} + +func (u Unival) AsULong() ULong { return ULong(u.arch.ByteOrder.Uint64(u.data)) } +func (u Unival) AsDouble() Double { + return Double(math.Float64frombits(u.arch.ByteOrder.Uint64(u.data))) +} func (u Unival) String() string { - return fmt.Sprintf("{ .ulong=%d; .double=%s }", u.AsULong(), u.AsDouble().String()) + return fmt.Sprintf("enum{ .ulong=%d; .double=%s; .cdefds=%v }", u.AsULong(), u.AsDouble(), u.AsRPNTokens()) } func (u Unival) MarshalText() ([]byte, error) { |