diff options
author | Luke Shumaker <lukeshu@lukeshu.com> | 2020-01-27 23:09:48 -0500 |
---|---|---|
committer | Luke Shumaker <lukeshu@lukeshu.com> | 2020-01-27 23:09:48 -0500 |
commit | 140ad92a3bbab485ef0f27c7be03d62d10ffd067 (patch) | |
tree | f3954785f43680acd90f0e741be44448dfa24ad2 /rrdformat | |
parent | a047b135ca416584178a6adde64cc156ab637431 (diff) |
fix
Diffstat (limited to 'rrdformat')
-rw-r--r-- | rrdformat/format.go | 19 | ||||
-rw-r--r-- | rrdformat/rrdbinary/decode.go | 11 | ||||
-rw-r--r-- | rrdformat/sniff.go | 2 | ||||
-rw-r--r-- | rrdformat/unmarshal_binary.go | 4 |
4 files changed, 23 insertions, 13 deletions
diff --git a/rrdformat/format.go b/rrdformat/format.go index 2900ce8..91e5669 100644 --- a/rrdformat/format.go +++ b/rrdformat/format.go @@ -1,6 +1,8 @@ package rrdformat import ( + "time" + "git.lukeshu.com/go/librrd/rrdformat/rrdbinary" ) @@ -58,9 +60,10 @@ type DSDef struct { } type RRADef struct { - CFName rrdbinary.String `rrdbinary:"size=20"` - RowCnt rrdbinary.Uint - PDPCnt rrdbinary.Uint + CFName rrdbinary.String `rrdbinary:"size=20"` + RowCnt rrdbinary.Uint + PDPCnt rrdbinary.Uint + Paameters [10]rrdbinary.Unival } type TimeWithUsec struct { @@ -68,8 +71,16 @@ type TimeWithUsec struct { Usec rrdbinary.Int // signed, but always >= 0 } +func (ts TimeWithUsec) Time() time.Time { + return time.Unix(int64(ts.Sec), int64(ts.Usec)*1000) +} + type TimeWithoutUsec struct { - Sec rrdbinary.Time + Sec rrdbinary.Time +} + +func (ts TimeWithoutUsec) Time() time.Time { + return time.Unix(int64(ts.Sec), 0) } type PDPPrep struct { diff --git a/rrdformat/rrdbinary/decode.go b/rrdformat/rrdbinary/decode.go index f3ae80e..cdaf49e 100644 --- a/rrdformat/rrdbinary/decode.go +++ b/rrdformat/rrdbinary/decode.go @@ -51,13 +51,16 @@ func (d *Decoder) Decode(ptr interface{}, tag string) error { if ptrValue.Kind() != reflect.Ptr { return typeErrorf("ptr is a %v, not a pointer", ptrValue.Kind()) } - return d.decode(ptrValue, tag) + return d.decode(ptrValue.Elem(), tag) } func (d *Decoder) decode(v reflect.Value, tag string) error { - if v.CanInterface() { - if u, ok := v.Interface().(unmarshaler); ok { - return u.unmarshalRRD(d, tag) + if v.Kind() != reflect.Ptr && v.CanAddr() { + vptr := v.Addr() + if vptr.CanInterface() { + if u, ok := vptr.Interface().(unmarshaler); ok { + return u.unmarshalRRD(d, tag) + } } } switch v.Type().Kind() { diff --git a/rrdformat/sniff.go b/rrdformat/sniff.go index db48959..104a8f7 100644 --- a/rrdformat/sniff.go +++ b/rrdformat/sniff.go @@ -15,7 +15,7 @@ func SniffArchitecture(data []byte) (rrdbinary.Architecture, error) { Cookie rrdbinary.String `rrdbinary:"size=4" xml:"-"` Version rrdbinary.String `rrdbinary:"size=5" xml:"version"` } - if err := rrdbinary.Unmarshal(arch, data, &header); err != nil { + if err := rrdbinary.NewDecoder(arch, data).Decode(&header, ""); err != nil { return rrdbinary.Architecture{}, err } diff --git a/rrdformat/unmarshal_binary.go b/rrdformat/unmarshal_binary.go index 70c06b7..923ccb1 100644 --- a/rrdformat/unmarshal_binary.go +++ b/rrdformat/unmarshal_binary.go @@ -26,7 +26,6 @@ func (rrd *RRD) UnmarshalBinary(data []byte) error { } // allocate memory based on .Header values parsed.DSDefs = make([]DSDef, parsed.Header.DSCnt) - parsed.DSDefs = make([]DSDef, parsed.Header.DSCnt) parsed.RRADefs = make([]RRADef, parsed.Header.RRACnt) parsed.PDPPreps = make([]PDPPrep, parsed.Header.DSCnt) parsed.CDPPreps = make([]CDPPrep, parsed.Header.DSCnt*parsed.Header.RRACnt) @@ -58,9 +57,6 @@ func (rrd *RRD) UnmarshalBinary(data []byte) error { if err := decoder.Decode(lastUpdatedPtr, ""); err != nil { return fmt.Errorf("field %s: %w", "LastUpdated", err) } - if err := decoder.Decode(&parsed.LastUpdated, ""); err != nil { - return fmt.Errorf("field %s: %w", "LastUpdated", err) - } if err := decoder.Decode(&parsed.PDPPreps, ""); err != nil { return fmt.Errorf("field %s: %w", "PDPPreps", err) } |