2016-09-22 23:22:41 +00:00
|
|
|
package internal
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/gogo/protobuf/proto"
|
|
|
|
"github.com/influxdata/mrfusion"
|
|
|
|
)
|
|
|
|
|
|
|
|
//go:generate protoc --gogo_out=. internal.proto
|
|
|
|
|
|
|
|
// MarshalExploration encodes an exploration to binary protobuf format.
|
|
|
|
func MarshalExploration(e *mrfusion.Exploration) ([]byte, error) {
|
|
|
|
return proto.Marshal(&Exploration{
|
|
|
|
ID: int64(e.ID),
|
|
|
|
Name: e.Name,
|
|
|
|
UserID: int64(e.UserID),
|
|
|
|
Data: e.Data,
|
|
|
|
CreatedAt: e.CreatedAt.UnixNano(),
|
|
|
|
UpdatedAt: e.UpdatedAt.UnixNano(),
|
2016-09-28 19:32:58 +00:00
|
|
|
Default: e.Default,
|
2016-09-22 23:22:41 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// UnmarshalExploration decodes an exploration from binary protobuf data.
|
|
|
|
func UnmarshalExploration(data []byte, e *mrfusion.Exploration) error {
|
|
|
|
var pb Exploration
|
|
|
|
if err := proto.Unmarshal(data, &pb); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
e.ID = mrfusion.ExplorationID(pb.ID)
|
|
|
|
e.Name = pb.Name
|
|
|
|
e.UserID = mrfusion.UserID(pb.UserID)
|
|
|
|
e.Data = pb.Data
|
|
|
|
e.CreatedAt = time.Unix(0, pb.CreatedAt).UTC()
|
|
|
|
e.UpdatedAt = time.Unix(0, pb.UpdatedAt).UTC()
|
2016-09-28 19:32:58 +00:00
|
|
|
e.Default = pb.Default
|
2016-09-22 23:22:41 +00:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
2016-09-30 20:39:27 +00:00
|
|
|
|
2016-10-06 04:26:39 +00:00
|
|
|
// MarshalSource encodes a source to binary protobuf format.
|
2016-09-30 20:39:27 +00:00
|
|
|
func MarshalSource(s mrfusion.Source) ([]byte, error) {
|
|
|
|
return proto.Marshal(&Source{
|
|
|
|
ID: int64(s.ID),
|
|
|
|
Name: s.Name,
|
|
|
|
Type: s.Type,
|
|
|
|
Username: s.Username,
|
|
|
|
Password: s.Password,
|
|
|
|
URLs: s.URL,
|
|
|
|
Default: s.Default,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2016-10-06 04:26:39 +00:00
|
|
|
// UnmarshalSource decodes a source from binary protobuf data.
|
2016-09-30 20:39:27 +00:00
|
|
|
func UnmarshalSource(data []byte, s *mrfusion.Source) error {
|
|
|
|
var pb Source
|
|
|
|
if err := proto.Unmarshal(data, &pb); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
s.ID = int(pb.ID)
|
|
|
|
s.Name = pb.Name
|
|
|
|
s.Type = pb.Type
|
|
|
|
s.Username = pb.Username
|
|
|
|
s.Password = pb.Password
|
|
|
|
s.URL = pb.URLs
|
|
|
|
s.Default = pb.Default
|
|
|
|
return nil
|
|
|
|
}
|
2016-09-30 23:46:28 +00:00
|
|
|
|
2016-10-06 04:26:39 +00:00
|
|
|
// MarshalServer encodes a server to binary protobuf format.
|
2016-09-30 23:46:28 +00:00
|
|
|
func MarshalServer(s mrfusion.Server) ([]byte, error) {
|
|
|
|
return proto.Marshal(&Server{
|
|
|
|
ID: int64(s.ID),
|
2016-10-03 17:41:50 +00:00
|
|
|
SrcID: int64(s.SrcID),
|
2016-09-30 23:46:28 +00:00
|
|
|
Name: s.Name,
|
|
|
|
Username: s.Username,
|
|
|
|
Password: s.Password,
|
|
|
|
URL: s.URL,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2016-10-06 04:26:39 +00:00
|
|
|
// UnmarshalServer decodes a server from binary protobuf data.
|
2016-09-30 23:46:28 +00:00
|
|
|
func UnmarshalServer(data []byte, s *mrfusion.Server) error {
|
|
|
|
var pb Server
|
|
|
|
if err := proto.Unmarshal(data, &pb); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
s.ID = int(pb.ID)
|
2016-10-03 17:41:50 +00:00
|
|
|
s.SrcID = int(pb.SrcID)
|
2016-09-30 23:46:28 +00:00
|
|
|
s.Name = pb.Name
|
|
|
|
s.Username = pb.Username
|
|
|
|
s.Password = pb.Password
|
|
|
|
s.URL = pb.URL
|
|
|
|
return nil
|
|
|
|
}
|
2016-10-06 04:26:39 +00:00
|
|
|
|
|
|
|
// MarshalLayout encodes a layout to binary protobuf format.
|
|
|
|
func MarshalLayout(l mrfusion.Layout) ([]byte, error) {
|
|
|
|
cells := make([]*Cell, len(l.Cells))
|
|
|
|
for i, c := range l.Cells {
|
|
|
|
queries := make([]*Query, len(c.Queries))
|
|
|
|
for j, q := range c.Queries {
|
|
|
|
queries[j] = &Query{
|
|
|
|
Command: q.Command,
|
|
|
|
DB: q.DB,
|
|
|
|
RP: q.RP,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cells[i] = &Cell{
|
|
|
|
X: c.X,
|
|
|
|
Y: c.Y,
|
|
|
|
W: c.W,
|
|
|
|
H: c.H,
|
|
|
|
Queries: queries,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return proto.Marshal(&Layout{
|
|
|
|
ID: int64(l.ID),
|
|
|
|
Cells: cells,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// UnmarshalLayout decodes a layout from binary protobuf data.
|
|
|
|
func UnmarshalLayout(data []byte, l *mrfusion.Layout) error {
|
|
|
|
var pb Layout
|
|
|
|
if err := proto.Unmarshal(data, &pb); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
l.ID = int(pb.ID)
|
|
|
|
cells := make([]mrfusion.Cell, len(pb.Cells))
|
|
|
|
for i, c := range pb.Cells {
|
|
|
|
queries := make([]mrfusion.Query, len(c.Queries))
|
|
|
|
for j, q := range c.Queries {
|
|
|
|
queries[j] = mrfusion.Query{
|
|
|
|
Command: q.Command,
|
|
|
|
DB: q.DB,
|
|
|
|
RP: q.RP,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cells[i] = mrfusion.Cell{
|
|
|
|
X: c.X,
|
|
|
|
Y: c.Y,
|
|
|
|
W: c.W,
|
|
|
|
H: c.H,
|
|
|
|
Queries: queries,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
l.Cells = cells
|
|
|
|
return nil
|
|
|
|
}
|