diff options
Diffstat (limited to 'go/operation')
| -rw-r--r-- | go/operation/system_message.pb.go | 189 | ||||
| -rw-r--r-- | go/operation/system_message_test.go | 58 |
2 files changed, 247 insertions, 0 deletions
diff --git a/go/operation/system_message.pb.go b/go/operation/system_message.pb.go new file mode 100644 index 000000000..45ae8a648 --- /dev/null +++ b/go/operation/system_message.pb.go @@ -0,0 +1,189 @@ +// Code generated by protoc-gen-go. +// source: system_message.proto +// DO NOT EDIT! + +/* +Package operation is a generated protocol buffer package. + +It is generated from these files: + system_message.proto + +It has these top-level messages: + VolumeInformationMessage + JoinMessage +*/ +package operation + +import proto "code.google.com/p/goprotobuf/proto" +import json "encoding/json" +import math "math" + +// Reference proto, json, and math imports to suppress error if they are not otherwise used. +var _ = proto.Marshal +var _ = &json.SyntaxError{} +var _ = math.Inf + +type VolumeInformationMessage struct { + Id *uint32 `protobuf:"varint,1,req,name=id" json:"id,omitempty"` + Size *uint64 `protobuf:"varint,2,req,name=size" json:"size,omitempty"` + Collection *string `protobuf:"bytes,3,opt,name=collection" json:"collection,omitempty"` + FileCount *uint64 `protobuf:"varint,4,req,name=file_count" json:"file_count,omitempty"` + DeleteCount *uint64 `protobuf:"varint,5,req,name=delete_count" json:"delete_count,omitempty"` + DeletedByteCount *uint64 `protobuf:"varint,6,req,name=deleted_byte_count" json:"deleted_byte_count,omitempty"` + ReadOnly *bool `protobuf:"varint,7,opt,name=read_only" json:"read_only,omitempty"` + ReplicaPlacement *uint32 `protobuf:"varint,8,req,name=replica_placement" json:"replica_placement,omitempty"` + Version *uint32 `protobuf:"varint,9,opt,name=version,def=2" json:"version,omitempty"` + XXX_unrecognized []byte `json:"-"` +} + +func (m *VolumeInformationMessage) Reset() { *m = VolumeInformationMessage{} } +func (m *VolumeInformationMessage) String() string { return proto.CompactTextString(m) } +func (*VolumeInformationMessage) ProtoMessage() {} + +const Default_VolumeInformationMessage_Version uint32 = 2 + +func (m *VolumeInformationMessage) GetId() uint32 { + if m != nil && m.Id != nil { + return *m.Id + } + return 0 +} + +func (m *VolumeInformationMessage) GetSize() uint64 { + if m != nil && m.Size != nil { + return *m.Size + } + return 0 +} + +func (m *VolumeInformationMessage) GetCollection() string { + if m != nil && m.Collection != nil { + return *m.Collection + } + return "" +} + +func (m *VolumeInformationMessage) GetFileCount() uint64 { + if m != nil && m.FileCount != nil { + return *m.FileCount + } + return 0 +} + +func (m *VolumeInformationMessage) GetDeleteCount() uint64 { + if m != nil && m.DeleteCount != nil { + return *m.DeleteCount + } + return 0 +} + +func (m *VolumeInformationMessage) GetDeletedByteCount() uint64 { + if m != nil && m.DeletedByteCount != nil { + return *m.DeletedByteCount + } + return 0 +} + +func (m *VolumeInformationMessage) GetReadOnly() bool { + if m != nil && m.ReadOnly != nil { + return *m.ReadOnly + } + return false +} + +func (m *VolumeInformationMessage) GetReplicaPlacement() uint32 { + if m != nil && m.ReplicaPlacement != nil { + return *m.ReplicaPlacement + } + return 0 +} + +func (m *VolumeInformationMessage) GetVersion() uint32 { + if m != nil && m.Version != nil { + return *m.Version + } + return Default_VolumeInformationMessage_Version +} + +type JoinMessage struct { + IsInit *bool `protobuf:"varint,1,opt,name=is_init" json:"is_init,omitempty"` + Ip *string `protobuf:"bytes,2,req,name=ip" json:"ip,omitempty"` + Port *uint32 `protobuf:"varint,3,req,name=port" json:"port,omitempty"` + PublicUrl *string `protobuf:"bytes,4,opt,name=public_url" json:"public_url,omitempty"` + MaxVolumeCount *uint32 `protobuf:"varint,5,req,name=max_volume_count" json:"max_volume_count,omitempty"` + MaxFileKey *uint64 `protobuf:"varint,6,req,name=max_file_key" json:"max_file_key,omitempty"` + DataCenter *string `protobuf:"bytes,7,opt,name=data_center" json:"data_center,omitempty"` + Rack *string `protobuf:"bytes,8,opt,name=rack" json:"rack,omitempty"` + Volumes []*VolumeInformationMessage `protobuf:"bytes,9,rep,name=volumes" json:"volumes,omitempty"` + XXX_unrecognized []byte `json:"-"` +} + +func (m *JoinMessage) Reset() { *m = JoinMessage{} } +func (m *JoinMessage) String() string { return proto.CompactTextString(m) } +func (*JoinMessage) ProtoMessage() {} + +func (m *JoinMessage) GetIsInit() bool { + if m != nil && m.IsInit != nil { + return *m.IsInit + } + return false +} + +func (m *JoinMessage) GetIp() string { + if m != nil && m.Ip != nil { + return *m.Ip + } + return "" +} + +func (m *JoinMessage) GetPort() uint32 { + if m != nil && m.Port != nil { + return *m.Port + } + return 0 +} + +func (m *JoinMessage) GetPublicUrl() string { + if m != nil && m.PublicUrl != nil { + return *m.PublicUrl + } + return "" +} + +func (m *JoinMessage) GetMaxVolumeCount() uint32 { + if m != nil && m.MaxVolumeCount != nil { + return *m.MaxVolumeCount + } + return 0 +} + +func (m *JoinMessage) GetMaxFileKey() uint64 { + if m != nil && m.MaxFileKey != nil { + return *m.MaxFileKey + } + return 0 +} + +func (m *JoinMessage) GetDataCenter() string { + if m != nil && m.DataCenter != nil { + return *m.DataCenter + } + return "" +} + +func (m *JoinMessage) GetRack() string { + if m != nil && m.Rack != nil { + return *m.Rack + } + return "" +} + +func (m *JoinMessage) GetVolumes() []*VolumeInformationMessage { + if m != nil { + return m.Volumes + } + return nil +} + +func init() { +} diff --git a/go/operation/system_message_test.go b/go/operation/system_message_test.go new file mode 100644 index 000000000..2731d0b2f --- /dev/null +++ b/go/operation/system_message_test.go @@ -0,0 +1,58 @@ +package operation + +import ( + proto "code.google.com/p/goprotobuf/proto" + "encoding/json" + "log" + "testing" +) + +func TestSerialDeserial(t *testing.T) { + volumeMessage := &VolumeInformationMessage{ + Id: proto.Uint32(12), + Size: proto.Uint64(2341234), + Collection: proto.String("benchmark"), + FileCount: proto.Uint64(2341234), + DeleteCount: proto.Uint64(234), + DeletedByteCount: proto.Uint64(21234), + ReadOnly: proto.Bool(false), + ReplicaPlacement: proto.Uint32(210), + Version: proto.Uint32(2), + } + var volumeMessages []*VolumeInformationMessage + volumeMessages = append(volumeMessages, volumeMessage) + + joinMessage := &JoinMessage{ + IsInit: proto.Bool(true), + Ip: proto.String("127.0.3.12"), + Port: proto.Uint32(34546), + PublicUrl: proto.String("localhost:2342"), + MaxVolumeCount: proto.Uint32(210), + MaxFileKey: proto.Uint64(324234423), + DataCenter: proto.String("dc1"), + Rack: proto.String("rack2"), + Volumes: volumeMessages, + } + + data, err := proto.Marshal(joinMessage) + if err != nil { + log.Fatal("marshaling error: ", err) + } + newMessage := &JoinMessage{} + err = proto.Unmarshal(data, newMessage) + if err != nil { + log.Fatal("unmarshaling error: ", err) + } + log.Println("The pb data size is", len(data)) + + jsonData, jsonError := json.Marshal(joinMessage) + if jsonError != nil { + log.Fatal("json marshaling error: ", jsonError) + } + log.Println("The json data size is", len(jsonData), string(jsonData)) + + // Now test and newTest contain the same data. + if *joinMessage.PublicUrl != *newMessage.PublicUrl { + log.Fatalf("data mismatch %q != %q", *joinMessage.PublicUrl, *newMessage.PublicUrl) + } +} |
