summaryrefslogtreecommitdiff
path: root/rrdformat/rrdbinary
diff options
context:
space:
mode:
Diffstat (limited to 'rrdformat/rrdbinary')
-rw-r--r--rrdformat/rrdbinary/decode.go68
-rw-r--r--rrdformat/rrdbinary/types.go34
2 files changed, 51 insertions, 51 deletions
diff --git a/rrdformat/rrdbinary/decode.go b/rrdformat/rrdbinary/decode.go
index cdaf49e..08c9141 100644
--- a/rrdformat/rrdbinary/decode.go
+++ b/rrdformat/rrdbinary/decode.go
@@ -153,9 +153,9 @@ func (obj *String) unmarshalRRD(d *Decoder, tag string) error {
return nil
}
-func (obj *Float) unmarshalRRD(d *Decoder, tag string) error {
- if d.arch.FloatWidth != 8 {
- return archErrorf("rrdbinary does not support FloatWidth=%d; only supports 8", d.arch.FloatWidth)
+func (obj *Double) unmarshalRRD(d *Decoder, tag string) error {
+ if d.arch.DoubleWidth != 8 {
+ return archErrorf("rrdbinary does not support DoubleWidth=%d; only supports 8", d.arch.DoubleWidth)
}
if tag != "" {
return typeErrorf("invalid rrdbinary struct tag for float: %q", tag)
@@ -164,26 +164,26 @@ func (obj *Float) unmarshalRRD(d *Decoder, tag string) error {
data := d.data[d.pos:]
padding := 0
- if d.pos%d.arch.FloatAlign != 0 {
- padding = d.arch.FloatAlign - (d.pos % d.arch.FloatAlign)
+ if d.pos%d.arch.DoubleAlign != 0 {
+ padding = d.arch.DoubleAlign - (d.pos % d.arch.DoubleAlign)
}
if len(data) < padding {
- return d.binErrorf(padding+d.arch.FloatWidth, "unexpected end-of-file in %d-byte padding-before-float", padding)
+ return d.binErrorf(padding+d.arch.DoubleWidth, "unexpected end-of-file in %d-byte padding-before-float", padding)
}
data = data[padding:]
- if len(data) < d.arch.FloatWidth {
- return d.binErrorf(d.arch.FloatWidth, "unexpected end-of-file in %d-byte float", d.arch.FloatWidth)
+ if len(data) < d.arch.DoubleWidth {
+ return d.binErrorf(d.arch.DoubleWidth, "unexpected end-of-file in %d-byte float", d.arch.DoubleWidth)
}
- *obj = Float(math.Float64frombits(d.arch.ByteOrder.Uint64(data)))
- d.pos += padding + d.arch.FloatWidth
+ *obj = Double(math.Float64frombits(d.arch.ByteOrder.Uint64(data)))
+ d.pos += padding + d.arch.DoubleWidth
return nil
}
-func (obj *Uint) unmarshalRRD(d *Decoder, tag string) error {
- if d.arch.IntWidth != 4 && d.arch.IntWidth != 8 {
- return archErrorf("rrdbinary does not support IntWidth=%d; only supports 4 or 8", d.arch.IntWidth)
+func (obj *ULong) unmarshalRRD(d *Decoder, tag string) error {
+ if d.arch.LongWidth != 4 && d.arch.LongWidth != 8 {
+ return archErrorf("rrdbinary does not support LongWidth=%d; only supports 4 or 8", d.arch.LongWidth)
}
if tag != "" {
return typeErrorf("invalid rrdbinary struct tag for uint: %q", tag)
@@ -192,31 +192,31 @@ func (obj *Uint) unmarshalRRD(d *Decoder, tag string) error {
data := d.data[d.pos:]
padding := 0
- if d.pos%d.arch.IntAlign != 0 {
- padding = d.arch.IntAlign - (d.pos % d.arch.IntAlign)
+ if d.pos%d.arch.LongAlign != 0 {
+ padding = d.arch.LongAlign - (d.pos % d.arch.LongAlign)
}
if len(data) < padding {
- return d.binErrorf(padding+d.arch.IntWidth, "unexpected end-of-file in %d-byte padding-before-uint", padding)
+ return d.binErrorf(padding+d.arch.LongWidth, "unexpected end-of-file in %d-byte padding-before-uint", padding)
}
data = data[padding:]
- if len(data) < d.arch.IntWidth {
- return d.binErrorf(d.arch.IntWidth, "unexpected end-of-file in %d-byte uint", d.arch.IntWidth)
+ if len(data) < d.arch.LongWidth {
+ return d.binErrorf(d.arch.LongWidth, "unexpected end-of-file in %d-byte uint", d.arch.LongWidth)
}
- switch d.arch.IntWidth {
+ switch d.arch.LongWidth {
case 4:
- *obj = Uint(d.arch.ByteOrder.Uint32(data))
+ *obj = ULong(d.arch.ByteOrder.Uint32(data))
case 8:
- *obj = Uint(d.arch.ByteOrder.Uint64(data))
+ *obj = ULong(d.arch.ByteOrder.Uint64(data))
}
- d.pos += padding + d.arch.IntWidth
+ d.pos += padding + d.arch.LongWidth
return nil
}
-func (obj *Int) unmarshalRRD(d *Decoder, tag string) error {
- if d.arch.IntWidth != 4 && d.arch.IntWidth != 8 {
- return archErrorf("rrdbinary does not support IntWidth=%d; only supports 4 or 8", d.arch.IntWidth)
+func (obj *Long) unmarshalRRD(d *Decoder, tag string) error {
+ if d.arch.LongWidth != 4 && d.arch.LongWidth != 8 {
+ return archErrorf("rrdbinary does not support LongWidth=%d; only supports 4 or 8", d.arch.LongWidth)
}
if tag != "" {
return typeErrorf("invalid rrdbinary struct tag for int: %q", tag)
@@ -225,25 +225,25 @@ func (obj *Int) unmarshalRRD(d *Decoder, tag string) error {
data := d.data[d.pos:]
padding := 0
- if d.pos%d.arch.IntAlign != 0 {
- padding = d.arch.IntAlign - (d.pos % d.arch.IntAlign)
+ if d.pos%d.arch.LongAlign != 0 {
+ padding = d.arch.LongAlign - (d.pos % d.arch.LongAlign)
}
if len(data) < padding {
- return d.binErrorf(padding+d.arch.IntWidth, "unexpected end-of-file in %d-byte padding-before-int", padding)
+ return d.binErrorf(padding+d.arch.LongWidth, "unexpected end-of-file in %d-byte padding-before-int", padding)
}
data = data[padding:]
- if len(data) < d.arch.IntWidth {
- return d.binErrorf(d.arch.IntWidth, "unexpected end-of-file in %d-byte int", d.arch.IntWidth)
+ if len(data) < d.arch.LongWidth {
+ return d.binErrorf(d.arch.LongWidth, "unexpected end-of-file in %d-byte int", d.arch.LongWidth)
}
- switch d.arch.IntWidth {
+ switch d.arch.LongWidth {
case 4:
- *obj = Int(int32(d.arch.ByteOrder.Uint32(data)))
+ *obj = Long(int32(d.arch.ByteOrder.Uint32(data)))
case 8:
- *obj = Int(d.arch.ByteOrder.Uint64(data))
+ *obj = Long(d.arch.ByteOrder.Uint64(data))
}
- d.pos += padding + d.arch.IntWidth
+ d.pos += padding + d.arch.LongWidth
return nil
}
diff --git a/rrdformat/rrdbinary/types.go b/rrdformat/rrdbinary/types.go
index a6fa881..47df26e 100644
--- a/rrdformat/rrdbinary/types.go
+++ b/rrdformat/rrdbinary/types.go
@@ -9,32 +9,32 @@ import (
type Architecture struct {
ByteOrder binary.ByteOrder
// C `double`
- FloatWidth int // always 8 -- we assume IEEE 754 doubles
- FloatAlign int
+ DoubleWidth int // always 8 -- we assume IEEE 754 doubles
+ DoubleAlign int
// C `long` or `unsigned long`
- IntWidth int
- IntAlign int
+ LongWidth int
+ LongAlign int
// C `union { unsigned long; double; }`
- UnivalWidth int // max(FloatWidth, IntWidth)
- UnivalAlign int // max(FloatAlign, IntAlign)
+ UnivalWidth int // max(DoubleWidth, LongWidth)
+ UnivalAlign int // max(DoubleAlign, LongAlign)
// C `time_t`
TimeWidth int
TimeAlign int
}
-type String string // \0-terminated
-type Float float64 // 8 bytes
-type Uint uint64 // 4 or 8 bytes
-type Int 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
+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) AsUint64() uint64 { return uint64(u) }
func (u Unival) AsFloat64() float64 { return math.Float64frombits(uint64(u)) }
// MarshalJSON is for my own debugging.
-func (f Float) MarshalJSON() ([]byte, error) {
+func (f Double) MarshalJSON() ([]byte, error) {
raw := float64(f)
if math.IsNaN(raw) {
return json.Marshal("NaN")
@@ -45,9 +45,9 @@ func (f Float) MarshalJSON() ([]byte, error) {
// Statically assert that each of the above types implements the
// 'unmarshaler' interface.
var _ unmarshaler = func() *String { return nil }()
-var _ unmarshaler = func() *Float { return nil }()
-var _ unmarshaler = func() *Uint { return nil }()
-var _ unmarshaler = func() *Int { return nil }()
+var _ unmarshaler = func() *Double { return nil }()
+var _ unmarshaler = func() *ULong { return nil }()
+var _ unmarshaler = func() *Long { return nil }()
var _ unmarshaler = func() *Unival { return nil }()
var _ unmarshaler = func() *Time { return nil }()
var _ unmarshaler = func() *EOF { return nil }()