2024-10-22 04:18:40 -05:00
|
|
|
package virtbuf
|
|
|
|
|
2024-10-22 04:37:28 -05:00
|
|
|
import (
|
2024-10-22 06:19:24 -05:00
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"google.golang.org/protobuf/encoding/protojson"
|
|
|
|
"google.golang.org/protobuf/encoding/prototext"
|
2024-10-22 04:37:28 -05:00
|
|
|
)
|
2024-10-22 04:26:29 -05:00
|
|
|
|
|
|
|
func (x *Hypervisor) SetMemoryGB(gb int) {
|
2024-10-22 04:18:40 -05:00
|
|
|
x.Memory = int64(gb * 1024 * 1024 * 1024)
|
|
|
|
}
|
2024-10-22 04:26:29 -05:00
|
|
|
|
|
|
|
func (x *Hypervisor) GetMemoryPrintable() string {
|
|
|
|
i := x.Memory / (1024 * 1024 * 1024)
|
|
|
|
return fmt.Sprintf("%d GB", i)
|
|
|
|
}
|
2024-10-22 04:37:28 -05:00
|
|
|
|
|
|
|
func (c *Cluster) MarshalJSON() ([]byte, error) {
|
2024-10-22 06:19:24 -05:00
|
|
|
return protojson.Marshal(c)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Cluster) FormatJSON() string {
|
|
|
|
return protojson.Format(c)
|
|
|
|
}
|
|
|
|
|
2024-10-22 04:37:28 -05:00
|
|
|
func (c *Cluster) UnmarshalJSON(data []byte) error {
|
2024-10-22 06:19:24 -05:00
|
|
|
return protojson.Unmarshal(data, c)
|
2024-10-22 04:37:28 -05:00
|
|
|
}
|
2024-10-22 06:25:31 -05:00
|
|
|
|
|
|
|
// 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 (c *Cluster) FormatTEXT() string {
|
|
|
|
return prototext.Format(c)
|
|
|
|
}
|