just make a .proto file for experiments
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
68ffae38b7
commit
6de8328027
6
Makefile
6
Makefile
|
@ -48,6 +48,12 @@ events.pb.go: events.proto
|
||||||
--go_opt=Mevents.proto=go.wit.com/lib/protobuf/virtbuf \
|
--go_opt=Mevents.proto=go.wit.com/lib/protobuf/virtbuf \
|
||||||
events.proto
|
events.proto
|
||||||
|
|
||||||
|
experiements.pb.go: experiements.proto
|
||||||
|
cd ~/go/src && protoc --go_out=. \
|
||||||
|
--proto_path=go.wit.com/lib/protobuf/virtbuf \
|
||||||
|
--go_opt=Mexperiements.proto=go.wit.com/lib/protobuf/virtbuf \
|
||||||
|
experiements.proto
|
||||||
|
|
||||||
cluster.pb.go: cluster.proto
|
cluster.pb.go: cluster.proto
|
||||||
cd ~/go/src && protoc --go_out=. --proto_path=go.wit.com/lib/protobuf/virtbuf \
|
cd ~/go/src && protoc --go_out=. --proto_path=go.wit.com/lib/protobuf/virtbuf \
|
||||||
--go_opt=Mdroplet.proto=go.wit.com/lib/protobuf/virtbuf \
|
--go_opt=Mdroplet.proto=go.wit.com/lib/protobuf/virtbuf \
|
||||||
|
|
|
@ -9,9 +9,6 @@ message Events {
|
||||||
string version = 2; // maybe can be used for protobuf schema change violations
|
string version = 2; // maybe can be used for protobuf schema change violations
|
||||||
int64 event_size = 3; // max events to store in a single
|
int64 event_size = 3; // max events to store in a single
|
||||||
repeated Event events = 4; // all the events
|
repeated Event events = 4; // all the events
|
||||||
|
|
||||||
// is it possible to have custom formatting in JSON and TEXT marshal/unmarshal ?
|
|
||||||
StorageInfo humantest = 5;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
message Event {
|
message Event {
|
||||||
|
@ -42,7 +39,3 @@ enum EventType {
|
||||||
CRASH = 11; // droplet hard crashed
|
CRASH = 11; // droplet hard crashed
|
||||||
CHANGE = 12; // droplet or hypervisor config change
|
CHANGE = 12; // droplet or hypervisor config change
|
||||||
}
|
}
|
||||||
|
|
||||||
message StorageInfo {
|
|
||||||
int64 capacity = 1; // Stores the storage capacity in bytes.
|
|
||||||
}
|
|
||||||
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
syntax = "proto3";
|
||||||
|
package virtbuf;
|
||||||
|
|
||||||
|
import "google/protobuf/timestamp.proto"; // Import the well-known type for Timestamp
|
||||||
|
import "google/protobuf/any.proto"; // Import the well-known type for Timestamp
|
||||||
|
|
||||||
|
message WhatsThis {
|
||||||
|
// is it possible to have custom formatting in JSON and TEXT marshal/unmarshal ?
|
||||||
|
WhatInfo humantest = 1;
|
||||||
|
|
||||||
|
google.protobuf.Timestamp end = 2; // end time
|
||||||
|
google.protobuf.Any orig_val = 3; // original value
|
||||||
|
google.protobuf.Any new_val = 4; // new value
|
||||||
|
}
|
||||||
|
|
||||||
|
// this is for exerimenting
|
||||||
|
message WhatInfo {
|
||||||
|
int64 capacity = 1; // Stores the storage capacity in bytes.
|
||||||
|
}
|
|
@ -40,19 +40,25 @@ func CreateSampleHypervisor(hostname string, mem int) *Hypervisor {
|
||||||
return h
|
return h
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateSampleEvents(total int) *Events {
|
func CreateExperiment(total int) *WhatsThis {
|
||||||
var e *Events
|
var e *WhatsThis
|
||||||
e = new(Events)
|
e = new(WhatsThis)
|
||||||
|
|
||||||
// info := StorageInfo{Capacity: 64}
|
// info := StorageInfo{Capacity: 64}
|
||||||
// e.Humantest = &info
|
// e.Humantest = &info
|
||||||
if e.Humantest == nil {
|
if e.Humantest == nil {
|
||||||
var newInfo StorageInfo
|
var newInfo WhatInfo
|
||||||
newInfo = StorageInfo{Capacity: 64}
|
newInfo = WhatInfo{Capacity: 64}
|
||||||
e.Humantest = &newInfo
|
e.Humantest = &newInfo
|
||||||
} else {
|
} else {
|
||||||
e.Humantest.Capacity = SetGB(total * 32)
|
e.Humantest.Capacity = SetGB(total * 32)
|
||||||
}
|
}
|
||||||
|
return e
|
||||||
|
}
|
||||||
|
|
||||||
|
func CreateSampleEvents(total int) *Events {
|
||||||
|
var e *Events
|
||||||
|
e = new(Events)
|
||||||
|
|
||||||
for i := 0; i < total; i++ {
|
for i := 0; i < total; i++ {
|
||||||
var newe *Event
|
var newe *Event
|
||||||
|
|
|
@ -6,20 +6,20 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
// MarshalJSON custom marshals the StorageInfo struct to JSON
|
// MarshalJSON custom marshals the WhatInfo struct to JSON
|
||||||
func (s StorageInfo) MarshalJSON() ([]byte, error) {
|
func (s WhatInfo) MarshalJSON() ([]byte, error) {
|
||||||
capacityStr := fmt.Sprintf("%d GB", s.Capacity)
|
capacityStr := fmt.Sprintf("%d GB", s.Capacity)
|
||||||
return json.Marshal(map[string]string{
|
return json.Marshal(map[string]string{
|
||||||
"capacity": capacityStr,
|
"capacity": capacityStr,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s StorageInfo) FormatJSON() string {
|
func (s WhatInfo) FormatJSON() string {
|
||||||
return fmt.Sprintf("\"capacity\": \"%d GB\"", s.Capacity)
|
return fmt.Sprintf("\"capacity\": \"%d GB\"", s.Capacity)
|
||||||
}
|
}
|
||||||
|
|
||||||
// UnmarshalJSON custom unmarshals JSON into the StorageInfo struct
|
// UnmarshalJSON custom unmarshals JSON into the WhatInfo struct
|
||||||
func (s *StorageInfo) UnmarshalJSON(data []byte) error {
|
func (s *WhatInfo) UnmarshalJSON(data []byte) error {
|
||||||
var raw map[string]string
|
var raw map[string]string
|
||||||
if err := json.Unmarshal(data, &raw); err != nil {
|
if err := json.Unmarshal(data, &raw); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -39,14 +39,14 @@ func (s *StorageInfo) UnmarshalJSON(data []byte) error {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
func main() {
|
func main() {
|
||||||
info := StorageInfo{Capacity: 64}
|
info := WhatInfo{Capacity: 64}
|
||||||
|
|
||||||
// Marshaling to JSON
|
// Marshaling to JSON
|
||||||
jsonData, _ := json.Marshal(info)
|
jsonData, _ := json.Marshal(info)
|
||||||
fmt.Println(string(jsonData)) // Output: {"capacity":"64 GB"}
|
fmt.Println(string(jsonData)) // Output: {"capacity":"64 GB"}
|
||||||
|
|
||||||
// Unmarshaling back to Go struct
|
// Unmarshaling back to Go struct
|
||||||
var newInfo StorageInfo
|
var newInfo WhatInfo
|
||||||
_ = json.Unmarshal(jsonData, &newInfo)
|
_ = json.Unmarshal(jsonData, &newInfo)
|
||||||
fmt.Println(newInfo.Capacity) // Output: 64
|
fmt.Println(newInfo.Capacity) // Output: 64
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue