From be65ef54f7d2371602ae5999d9955d4bf9f48cd5 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sat, 1 Feb 2020 10:01:22 -0500 Subject: Rename some of the rrdbinary types to be more C-like --- rrdformat/sniff.go | 54 +++++++++++++++++++++++++++--------------------------- 1 file changed, 27 insertions(+), 27 deletions(-) (limited to 'rrdformat/sniff.go') diff --git a/rrdformat/sniff.go b/rrdformat/sniff.go index 104a8f7..de1e67b 100644 --- a/rrdformat/sniff.go +++ b/rrdformat/sniff.go @@ -38,44 +38,44 @@ func SniffArchitecture(data []byte) (rrdbinary.Architecture, error) { // enough that I'm OK saying "you're going to need to use `rrdtool dump`". This lets us assume that: // - a 'double' is 8 bytes wide // - the value will be exactly equal, and we don't need to worry about weird rounding. - arch.FloatWidth = 8 + arch.DoubleWidth = 8 magicFloat := float64(8.642135e130) floatAddrPacked := 9 floatAddr32 := ((floatAddrPacked + 3) / 4) * 4 floatAddr64 := ((floatAddrPacked + 7) / 8) * 8 var restOffset int switch { - case len(data) < floatAddr32+arch.FloatWidth: - return rrdbinary.Architecture{}, rrdbinary.NewBinError("unexpected end-of-file", data, floatAddrPacked, floatAddr64+arch.FloatWidth-floatAddrPacked) + case len(data) < floatAddr32+arch.DoubleWidth: + return rrdbinary.Architecture{}, rrdbinary.NewBinError("unexpected end-of-file", data, floatAddrPacked, floatAddr64+arch.DoubleWidth-floatAddrPacked) case math.Float64frombits(binary.LittleEndian.Uint64(data[floatAddr32:])) == magicFloat: arch.ByteOrder = binary.LittleEndian - arch.FloatAlign = 4 - restOffset = floatAddr32 + arch.FloatWidth + arch.DoubleAlign = 4 + restOffset = floatAddr32 + arch.DoubleWidth case math.Float64frombits(binary.BigEndian.Uint64(data[floatAddr32:])) == magicFloat: arch.ByteOrder = binary.BigEndian - arch.FloatAlign = 4 - restOffset = floatAddr32 + arch.FloatWidth - case len(data) < floatAddr64+arch.FloatWidth: - return rrdbinary.Architecture{}, rrdbinary.NewBinError("unexpected end-of-file", data, floatAddrPacked, floatAddr64+arch.FloatWidth-floatAddrPacked) + arch.DoubleAlign = 4 + restOffset = floatAddr32 + arch.DoubleWidth + case len(data) < floatAddr64+arch.DoubleWidth: + return rrdbinary.Architecture{}, rrdbinary.NewBinError("unexpected end-of-file", data, floatAddrPacked, floatAddr64+arch.DoubleWidth-floatAddrPacked) case math.Float64frombits(binary.LittleEndian.Uint64(data[floatAddr64:])) == magicFloat: arch.ByteOrder = binary.LittleEndian - arch.FloatAlign = 8 - restOffset = floatAddr64 + arch.FloatWidth + arch.DoubleAlign = 8 + restOffset = floatAddr64 + arch.DoubleWidth case math.Float64frombits(binary.BigEndian.Uint64(data[floatAddr64:])) == magicFloat: arch.ByteOrder = binary.BigEndian - arch.FloatAlign = 8 - restOffset = floatAddr64 + arch.FloatWidth + arch.DoubleAlign = 8 + restOffset = floatAddr64 + arch.DoubleWidth default: return rrdbinary.Architecture{}, rrdbinary.NewBinError("failed to sniff byte-order and float-alignment", - data, floatAddrPacked, floatAddr64+arch.FloatWidth-floatAddrPacked) + data, floatAddrPacked, floatAddr64+arch.DoubleWidth-floatAddrPacked) } // 5, 6. ds_cnt, rra_cnt - switch arch.FloatAlign { + switch arch.DoubleAlign { case 4: // Assume that if floats are only 32-bit aligned, then everything is 32-bit - arch.IntWidth = 4 - arch.IntAlign = 4 + arch.LongWidth = 4 + arch.LongAlign = 4 case 8: // If floats are 64-bit aligned, then this might be all-in on 64-bit, or it might 32-bit ints. @@ -106,18 +106,18 @@ func SniffArchitecture(data []byte) (rrdbinary.Architecture, error) { binary.LittleEndian: restOffset + 4, // 28 in the above diagram }[arch.ByteOrder] if arch.ByteOrder.Uint32(data[offset:]) == 0 { - arch.IntWidth = 8 - arch.IntAlign = 8 + arch.LongWidth = 8 + arch.LongAlign = 8 } else { - arch.IntWidth = 4 - arch.IntAlign = 4 + arch.LongWidth = 4 + arch.LongAlign = 4 } } - // The above just os happens that FloatXXX >= IntXXX, so we - // can just set the Unival stuff to the Float Stuff. - arch.UnivalWidth = arch.FloatWidth // max(FloatWidth, IntWidth) - arch.UnivalAlign = arch.FloatAlign // max(FloatAlign, IntAlign) + // The above just os happens that DoubleXXX >= LongXXX, so we + // can just set the Unival stuff to the Double Stuff. + arch.UnivalWidth = arch.DoubleWidth // max(DoubleWidth, LongWidth) + arch.UnivalAlign = arch.DoubleAlign // max(DoubleAlign, LongAlign) // FIXME: Figure out how to sniff the sizeof(time_t). // @@ -125,8 +125,8 @@ func SniffArchitecture(data []byte) (rrdbinary.Architecture, error) { // which his historically been true, but // - isn't true of proprietary 32-bit Unixen that are 2038-safe // - isn't true of the Linux kernel with the x32 ABI - arch.TimeWidth = arch.IntWidth - arch.TimeAlign = arch.IntAlign + arch.TimeWidth = arch.LongWidth + arch.TimeAlign = arch.LongAlign return arch, nil } -- cgit v1.2.3