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
|
|
|
|
|
|
|
// MarshalSource encodes an source to binary protobuf format.
|
|
|
|
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,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// UnmarshalSource decodes an source from binary protobuf data.
|
|
|
|
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
|
|
|
|
|
|
|
// MarshalServer encodes an source to binary protobuf format.
|
|
|
|
func MarshalServer(s mrfusion.Server) ([]byte, error) {
|
|
|
|
return proto.Marshal(&Server{
|
|
|
|
ID: int64(s.ID),
|
|
|
|
Name: s.Name,
|
|
|
|
Username: s.Username,
|
|
|
|
Password: s.Password,
|
|
|
|
URL: s.URL,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// UnmarshalServer decodes an source from binary protobuf data.
|
|
|
|
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)
|
|
|
|
s.Name = pb.Name
|
|
|
|
s.Username = pb.Username
|
|
|
|
s.Password = pb.Password
|
|
|
|
s.URL = pb.URL
|
|
|
|
return nil
|
|
|
|
}
|