summaryrefslogtreecommitdiff
path: root/rrdformat/unmarshal_binary.go
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2020-01-26 23:13:22 -0500
committerLuke Shumaker <lukeshu@lukeshu.com>2020-01-26 23:13:22 -0500
commit629cb407c10743b0033fdc648a3c876f244cf558 (patch)
tree016ff4bfde9e5f12c6b96a22ef2640b95c08bbaa /rrdformat/unmarshal_binary.go
parent72c4b2518a77ee9952a0fa25ae671f06d8d85570 (diff)
UnmarshalBinary, EOF
Diffstat (limited to 'rrdformat/unmarshal_binary.go')
-rw-r--r--rrdformat/unmarshal_binary.go67
1 files changed, 67 insertions, 0 deletions
diff --git a/rrdformat/unmarshal_binary.go b/rrdformat/unmarshal_binary.go
new file mode 100644
index 0000000..b9bafde
--- /dev/null
+++ b/rrdformat/unmarshal_binary.go
@@ -0,0 +1,67 @@
+package rrdformat
+
+import (
+ "encoding"
+
+ "git.lukeshu.com/go/librrd/rrdformat/rrdbinary"
+)
+
+type RRD struct {
+ Architecture rrdbinary.Architecture
+ Data RRDv0005
+}
+
+func (rrd *RRD) UnmarshalBinary(data []byte) error {
+ arch, err := SniffArchitecture(data)
+ if err != nil {
+ return err
+ }
+ var header Header
+ if err := rrdbinary.Unmarshal(arch, data, &header); err != nil {
+ return err
+ }
+
+ var parsed RRDv0005
+ parsed.DSDefs = make([]DSDef, header.DSCnt)
+ parsed.DSDefs = make([]DSDef, header.DSCnt)
+ parsed.RRADefs = make([]RRADef, header.RRACnt)
+ //LastUpdated
+ parsed.PDPPreps = make([]PDPPrep, header.DSCnt)
+ parsed.CDPPreps = make([]CDPPrep, header.DSCnt*header.RRACnt)
+ parsed.RRAPtrs = make([]RRAPtr, header.RRACnt)
+ //Values
+
+ switch header.Version {
+ case "0001", "0002":
+ _parsed := &RRDv0001{} //(*RRDv0001)(&parsed)
+ if err := rrdbinary.Unmarshal(arch, data, _parsed); err != nil {
+ return err
+ }
+ case "0003", "0004", "0005":
+ if err := rrdbinary.Unmarshal(arch, data, &parsed); err != nil {
+ return err
+ }
+ default:
+ // version number already validated by
+ // SniffArchitecture
+ panic("should not happen")
+ }
+
+ val_cnt := 0
+ for i := range parsed.RRADefs {
+ val_cnt += int(parsed.RRADefs[i].RowCnt * header.DSCnt)
+ }
+ parsed.Values = make([]RRDValue, val_cnt)
+ if err := rrdbinary.Unmarshal(arch, data, &parsed.Values); err != nil {
+ return err
+ }
+
+ *rrd = RRD{
+ Architecture: arch,
+ Data: parsed,
+ }
+ return nil
+}
+
+//var _ encoding.BinaryMarshaler = &RRD{}
+var _ encoding.BinaryUnmarshaler = &RRD{}