From d2ec40bb67846f34d3c1e59714351127a2e869e9 Mon Sep 17 00:00:00 2001 From: Jakob Borg Date: Wed, 25 Mar 2015 21:20:04 +0100 Subject: [PATCH] Add flags and options for future extensibility --- message.go | 5 +++- message_xdr.go | 65 ++++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 64 insertions(+), 6 deletions(-) diff --git a/message.go b/message.go index 3b91161bc..f6ed9e1a8 100644 --- a/message.go +++ b/message.go @@ -101,12 +101,15 @@ func (o *ClusterConfigMessage) GetOption(key string) string { type Folder struct { ID string // max:64 Devices []Device + Flags uint32 + Options []Option // max:64 } type Device struct { ID []byte // max:32 - Flags uint32 MaxLocalVersion int64 + Flags uint32 + Options []Option // max:64 } type Option struct { diff --git a/message_xdr.go b/message_xdr.go index 9e18f87b3..243aea879 100644 --- a/message_xdr.go +++ b/message_xdr.go @@ -664,11 +664,21 @@ Folder Structure: \ Zero or more Device Structures \ / / +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +| Flags | ++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +| Number of Options | ++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +/ / +\ Zero or more Option Structures \ +/ / ++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ struct Folder { string ID<64>; Device Devices<>; + unsigned int Flags; + Option Options<64>; } */ @@ -709,6 +719,17 @@ func (o Folder) encodeXDR(xw *xdr.Writer) (int, error) { return xw.Tot(), err } } + xw.WriteUint32(o.Flags) + if l := len(o.Options); l > 64 { + return xw.Tot(), xdr.ElementSizeExceeded("Options", l, 64) + } + xw.WriteUint32(uint32(len(o.Options))) + for i := range o.Options { + _, err := o.Options[i].encodeXDR(xw) + if err != nil { + return xw.Tot(), err + } + } return xw.Tot(), xw.Error() } @@ -730,6 +751,15 @@ func (o *Folder) decodeXDR(xr *xdr.Reader) error { for i := range o.Devices { (&o.Devices[i]).decodeXDR(xr) } + o.Flags = xr.ReadUint32() + _OptionsSize := int(xr.ReadUint32()) + if _OptionsSize > 64 { + return xdr.ElementSizeExceeded("Options", _OptionsSize, 64) + } + o.Options = make([]Option, _OptionsSize) + for i := range o.Options { + (&o.Options[i]).decodeXDR(xr) + } return xr.Error() } @@ -746,18 +776,25 @@ Device Structure: \ ID (variable length) \ / / +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -| Flags | -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | | + Max Local Version (64 bits) + | | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +| Flags | ++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +| Number of Options | ++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +/ / +\ Zero or more Option Structures \ +/ / ++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ struct Device { opaque ID<32>; - unsigned int Flags; hyper MaxLocalVersion; + unsigned int Flags; + Option Options<64>; } */ @@ -791,8 +828,18 @@ func (o Device) encodeXDR(xw *xdr.Writer) (int, error) { return xw.Tot(), xdr.ElementSizeExceeded("ID", l, 32) } xw.WriteBytes(o.ID) - xw.WriteUint32(o.Flags) xw.WriteUint64(uint64(o.MaxLocalVersion)) + xw.WriteUint32(o.Flags) + if l := len(o.Options); l > 64 { + return xw.Tot(), xdr.ElementSizeExceeded("Options", l, 64) + } + xw.WriteUint32(uint32(len(o.Options))) + for i := range o.Options { + _, err := o.Options[i].encodeXDR(xw) + if err != nil { + return xw.Tot(), err + } + } return xw.Tot(), xw.Error() } @@ -809,8 +856,16 @@ func (o *Device) UnmarshalXDR(bs []byte) error { func (o *Device) decodeXDR(xr *xdr.Reader) error { o.ID = xr.ReadBytesMax(32) - o.Flags = xr.ReadUint32() o.MaxLocalVersion = int64(xr.ReadUint64()) + o.Flags = xr.ReadUint32() + _OptionsSize := int(xr.ReadUint32()) + if _OptionsSize > 64 { + return xdr.ElementSizeExceeded("Options", _OptionsSize, 64) + } + o.Options = make([]Option, _OptionsSize) + for i := range o.Options { + (&o.Options[i]).decodeXDR(xr) + } return xr.Error() }