github.com/enbility/spine-go@v0.7.0/spine/operations.go (about) 1 package spine 2 3 import ( 4 "github.com/enbility/spine-go/api" 5 "github.com/enbility/spine-go/model" 6 ) 7 8 type Operations struct { 9 read, write bool 10 readPartial, writePartial bool 11 } 12 13 var _ api.OperationsInterface = (*Operations)(nil) 14 15 func NewOperations(read, readPartial, write, writePartial bool) *Operations { 16 return &Operations{ 17 read: read, 18 readPartial: readPartial, 19 write: write, 20 writePartial: writePartial, 21 } 22 } 23 func (r *Operations) Read() bool { 24 return r.read 25 } 26 27 func (r *Operations) ReadPartial() bool { 28 return r.readPartial 29 } 30 31 func (r *Operations) Write() bool { 32 return r.write 33 } 34 35 func (r *Operations) WritePartial() bool { 36 return r.writePartial 37 } 38 39 func (r *Operations) String() string { 40 switch { 41 case r.read && !r.write: 42 return "RO" 43 case r.read && r.write: 44 return "RW" 45 default: 46 return "--" 47 } 48 } 49 50 func (r *Operations) Information() *model.PossibleOperationsType { 51 res := new(model.PossibleOperationsType) 52 if r.read { 53 res.Read = &model.PossibleOperationsReadType{} 54 if r.readPartial { 55 res.Read = &model.PossibleOperationsReadType{ 56 Partial: &model.ElementTagType{}, 57 } 58 } 59 } 60 if r.write { 61 res.Write = &model.PossibleOperationsWriteType{} 62 if r.writePartial { 63 res.Write = &model.PossibleOperationsWriteType{ 64 Partial: &model.ElementTagType{}, 65 } 66 } 67 } 68 69 return res 70 }