summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile6
-rw-r--r--events.proto7
-rw-r--r--experiements.proto19
-rw-r--r--sampleData.go16
-rw-r--r--storageinfo.go14
5 files changed, 43 insertions, 19 deletions
diff --git a/Makefile b/Makefile
index 9f4d4ce..b7daa74 100644
--- a/Makefile
+++ b/Makefile
@@ -48,6 +48,12 @@ events.pb.go: events.proto
--go_opt=Mevents.proto=go.wit.com/lib/protobuf/virtbuf \
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
cd ~/go/src && protoc --go_out=. --proto_path=go.wit.com/lib/protobuf/virtbuf \
--go_opt=Mdroplet.proto=go.wit.com/lib/protobuf/virtbuf \
diff --git a/events.proto b/events.proto
index 0b2fe2f..2b5146c 100644
--- a/events.proto
+++ b/events.proto
@@ -9,9 +9,6 @@ message Events {
string version = 2; // maybe can be used for protobuf schema change violations
int64 event_size = 3; // max events to store in a single
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 {
@@ -42,7 +39,3 @@ enum EventType {
CRASH = 11; // droplet hard crashed
CHANGE = 12; // droplet or hypervisor config change
}
-
-message StorageInfo {
- int64 capacity = 1; // Stores the storage capacity in bytes.
-}
diff --git a/experiements.proto b/experiements.proto
new file mode 100644
index 0000000..2db67b3
--- /dev/null
+++ b/experiements.proto
@@ -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.
+}
diff --git a/sampleData.go b/sampleData.go
index d0388aa..990eeb7 100644
--- a/sampleData.go
+++ b/sampleData.go
@@ -40,19 +40,25 @@ func CreateSampleHypervisor(hostname string, mem int) *Hypervisor {
return h
}
-func CreateSampleEvents(total int) *Events {
- var e *Events
- e = new(Events)
+func CreateExperiment(total int) *WhatsThis {
+ var e *WhatsThis
+ e = new(WhatsThis)
// info := StorageInfo{Capacity: 64}
// e.Humantest = &info
if e.Humantest == nil {
- var newInfo StorageInfo
- newInfo = StorageInfo{Capacity: 64}
+ var newInfo WhatInfo
+ newInfo = WhatInfo{Capacity: 64}
e.Humantest = &newInfo
} else {
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++ {
var newe *Event
diff --git a/storageinfo.go b/storageinfo.go
index 4e1e9b0..ea08bc6 100644
--- a/storageinfo.go
+++ b/storageinfo.go
@@ -6,20 +6,20 @@ import (
"strconv"
)
-// MarshalJSON custom marshals the StorageInfo struct to JSON
-func (s StorageInfo) MarshalJSON() ([]byte, error) {
+// MarshalJSON custom marshals the WhatInfo struct to JSON
+func (s WhatInfo) MarshalJSON() ([]byte, error) {
capacityStr := fmt.Sprintf("%d GB", s.Capacity)
return json.Marshal(map[string]string{
"capacity": capacityStr,
})
}
-func (s StorageInfo) FormatJSON() string {
+func (s WhatInfo) FormatJSON() string {
return fmt.Sprintf("\"capacity\": \"%d GB\"", s.Capacity)
}
-// UnmarshalJSON custom unmarshals JSON into the StorageInfo struct
-func (s *StorageInfo) UnmarshalJSON(data []byte) error {
+// UnmarshalJSON custom unmarshals JSON into the WhatInfo struct
+func (s *WhatInfo) UnmarshalJSON(data []byte) error {
var raw map[string]string
if err := json.Unmarshal(data, &raw); err != nil {
return err
@@ -39,14 +39,14 @@ func (s *StorageInfo) UnmarshalJSON(data []byte) error {
/*
func main() {
- info := StorageInfo{Capacity: 64}
+ info := WhatInfo{Capacity: 64}
// Marshaling to JSON
jsonData, _ := json.Marshal(info)
fmt.Println(string(jsonData)) // Output: {"capacity":"64 GB"}
// Unmarshaling back to Go struct
- var newInfo StorageInfo
+ var newInfo WhatInfo
_ = json.Unmarshal(jsonData, &newInfo)
fmt.Println(newInfo.Capacity) // Output: 64
}