From 76fb9a95c4f904392918d3ba17ce240348feeef7 Mon Sep 17 00:00:00 2001 From: Jade McGough Date: Tue, 13 Dec 2016 02:25:26 -0800 Subject: [PATCH] add marshal/unmarshal for dashboards --- bolt/internal/internal.go | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/bolt/internal/internal.go b/bolt/internal/internal.go index a705a69af7..f847897cbb 100644 --- a/bolt/internal/internal.go +++ b/bolt/internal/internal.go @@ -188,12 +188,43 @@ func UnmarshalLayout(data []byte, l *chronograf.Layout) error { return nil } +// MarshalDashboard encodes a dashboard to binary protobuf format. func MarshalDashboard(d chronograf.Dashboard) ([]byte, error) { - return proto.Marshal(&Dashboard{ + cells := make([]*DashboardCell, len(l.Cells)) + for i, c := range l.Cells { + cells[i] = &DashboardCell{ + X: c.X, + Y: c.Y, + W: c.W, + H: c.H, + Name: c.Name, + Queries: c.Queries, + Type: c.Type, + } + } + + return proto.Marshal(&Dashboard{ + ID: d.ID, + Cells: cells, + Name: d.Name, }) } +// UnmarshalDashboard decodes a layout from binary protobuf data. +func UnmarshalDashboard(data []byte, d *chonograf.Dashboard) error { + var pb Dashboard + if err := proto.Unmarshal(data, &pb); err != nil { + return err + } + + d.ID = pb.ID + d.Cells = pb.Cells + d.Name = pb.Name + + return nil +} + // ScopedAlert contains the source and the kapacitor id type ScopedAlert struct { chronograf.AlertRule