2024-10-30 11:06:14 -05:00
|
|
|
package virtbuf
|
|
|
|
|
|
|
|
// functions to import and export the protobuf
|
|
|
|
// data to and from config files
|
|
|
|
|
|
|
|
import (
|
|
|
|
"google.golang.org/protobuf/encoding/protojson"
|
|
|
|
"google.golang.org/protobuf/encoding/prototext"
|
2024-10-30 18:10:40 -05:00
|
|
|
"google.golang.org/protobuf/proto"
|
2024-10-30 11:06:14 -05:00
|
|
|
)
|
|
|
|
|
2024-10-31 13:12:11 -05:00
|
|
|
func InitCluster() *NewCluster {
|
|
|
|
var c *NewCluster
|
|
|
|
c = new(NewCluster)
|
|
|
|
c.d = new(Droplets)
|
|
|
|
c.h = new(Hypervisors)
|
|
|
|
c.e = new(Events)
|
|
|
|
return c
|
|
|
|
}
|
|
|
|
|
2024-10-30 11:06:14 -05:00
|
|
|
// human readable JSON
|
|
|
|
func (d *Droplets) FormatJSON() string {
|
|
|
|
return protojson.Format(d)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *Droplet) FormatJSON() string {
|
|
|
|
return protojson.Format(d)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *Events) FormatJSON() string {
|
|
|
|
return protojson.Format(e)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *Hypervisors) FormatJSON() string {
|
|
|
|
return protojson.Format(h)
|
|
|
|
}
|
|
|
|
|
|
|
|
// apparently this isn't supposed to be used?
|
|
|
|
// https://protobuf.dev/reference/go/faq/#unstable-text
|
|
|
|
// this is a shame because this is much nicer output than JSON Format()
|
|
|
|
func (d *Droplets) FormatTEXT() string {
|
|
|
|
return prototext.Format(d)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *Events) FormatTEXT() string {
|
|
|
|
return prototext.Format(e)
|
|
|
|
}
|
|
|
|
|
|
|
|
// marshal
|
|
|
|
func (d *Droplets) MarshalJSON() ([]byte, error) {
|
|
|
|
return protojson.Marshal(d)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *Droplet) MarshalJSON() ([]byte, error) {
|
|
|
|
return protojson.Marshal(d)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *Events) MarshalJSON() ([]byte, error) {
|
|
|
|
return protojson.Marshal(e)
|
|
|
|
}
|
|
|
|
|
|
|
|
// unmarshal
|
|
|
|
func (d *Droplets) UnmarshalJSON(data []byte) error {
|
|
|
|
return protojson.Unmarshal(data, d)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *Droplet) UnmarshalJSON(data []byte) error {
|
|
|
|
return protojson.Unmarshal(data, d)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *Events) UnmarshalJSON(data []byte) error {
|
|
|
|
return protojson.Unmarshal(data, e)
|
|
|
|
}
|
2024-10-30 18:10:40 -05:00
|
|
|
|
|
|
|
func (d *Droplet) Unmarshal(data []byte) error {
|
|
|
|
return proto.Unmarshal(data, d)
|
|
|
|
}
|