From 051cba46669c10c836855dbeb8ac2954696f15f4 Mon Sep 17 00:00:00 2001 From: Thomas Roehl Date: Fri, 14 Apr 2023 18:24:40 +0200 Subject: [PATCH] Add unit for archive reader/writer --- archive.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/archive.go b/archive.go index 302afb3..c7d84e9 100644 --- a/archive.go +++ b/archive.go @@ -24,6 +24,7 @@ import ( type CheckpointMetrics struct { Frequency int64 `json:"frequency"` Start int64 `json:"start"` + Unit string `json:"unit"` Data []Float `json:"data"` } @@ -36,6 +37,7 @@ func (cm *CheckpointMetrics) MarshalJSON() ([]byte, error) { buf = strconv.AppendInt(buf, cm.Frequency, 10) buf = append(buf, `,"start":`...) buf = strconv.AppendInt(buf, cm.Start, 10) + buf = append(buf, fmt.Sprintf(`,"unit":"%s"`, cm.Unit)...) buf = append(buf, `,"data":[`...) for i, x := range cm.Data { if i != 0 { @@ -179,6 +181,7 @@ func (l *level) toCheckpointFile(from, to int64, m *MemoryStore) (*CheckpointFil Frequency: b.frequency, Start: start, Data: data, + Unit: b.unit, } } @@ -309,6 +312,7 @@ func (l *level) loadFile(cf *CheckpointFile, m *MemoryStore) error { frequency: metric.Frequency, start: metric.Start, data: metric.Data[0:n:n], // Space is wasted here :( + unit: "", prev: nil, next: nil, archived: true,