[#189] sdk/netmap: Refactor Selector type
Replace alias to v2 type Selector with v2-compatible implementation. Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
fd0c10b832
commit
eb96fffa5c
3 changed files with 138 additions and 1 deletions
|
@ -8,6 +8,9 @@ import (
|
|||
"github.com/nspcc-dev/neofs-api-go/v2/netmap"
|
||||
)
|
||||
|
||||
// Selector represents v2-compatible netmap selector.
|
||||
type Selector netmap.Selector
|
||||
|
||||
// processSelectors processes selectors and returns error is any of them is invalid.
|
||||
func (c *Context) processSelectors(p *netmap.PlacementPolicy) error {
|
||||
for _, s := range p.GetSelectors() {
|
||||
|
@ -118,3 +121,80 @@ func (c *Context) getSelectionBase(s *netmap.Selector) []nodeAttrPair {
|
|||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// NewSelector creates and returns new Selector instance.
|
||||
func NewSelector() *Selector {
|
||||
return NewSelectorFromV2(new(netmap.Selector))
|
||||
}
|
||||
|
||||
// NewSelectorFromV2 converts v2 Selector to Selector.
|
||||
func NewSelectorFromV2(f *netmap.Selector) *Selector {
|
||||
return (*Selector)(f)
|
||||
}
|
||||
|
||||
// ToV2 converts Selector to v2 Selector.
|
||||
func (s *Selector) ToV2() *netmap.Selector {
|
||||
return (*netmap.Selector)(s)
|
||||
}
|
||||
|
||||
// Name returns selector name.
|
||||
func (s *Selector) Name() string {
|
||||
return (*netmap.Selector)(s).
|
||||
GetName()
|
||||
}
|
||||
|
||||
// SetName sets selector name.
|
||||
func (s *Selector) SetName(name string) {
|
||||
(*netmap.Selector)(s).
|
||||
SetName(name)
|
||||
}
|
||||
|
||||
// Count returns count of nodes to select from bucket.
|
||||
func (s *Selector) Count() uint32 {
|
||||
return (*netmap.Selector)(s).
|
||||
GetCount()
|
||||
}
|
||||
|
||||
// SetCount sets count of nodes to select from bucket.
|
||||
func (s *Selector) SetCount(c uint32) {
|
||||
(*netmap.Selector)(s).
|
||||
SetCount(c)
|
||||
}
|
||||
|
||||
// Clause returns modifier showing how to form a bucket.
|
||||
func (s *Selector) Clause() Clause {
|
||||
return ClauseFromV2(
|
||||
(*netmap.Selector)(s).
|
||||
GetClause(),
|
||||
)
|
||||
}
|
||||
|
||||
// SetClause sets modifier showing how to form a bucket.
|
||||
func (s *Selector) SetClause(c Clause) {
|
||||
(*netmap.Selector)(s).
|
||||
SetClause(c.ToV2())
|
||||
}
|
||||
|
||||
// Attribute returns attribute bucket to select from.
|
||||
func (s *Selector) Attribute() string {
|
||||
return (*netmap.Selector)(s).
|
||||
GetAttribute()
|
||||
}
|
||||
|
||||
// SetAttribute sets attribute bucket to select from.
|
||||
func (s *Selector) SetAttribute(a string) {
|
||||
(*netmap.Selector)(s).
|
||||
SetAttribute(a)
|
||||
}
|
||||
|
||||
// Filter returns filter reference to select from.
|
||||
func (s *Selector) Filter() string {
|
||||
return (*netmap.Selector)(s).
|
||||
GetFilter()
|
||||
}
|
||||
|
||||
// SetFilter sets filter reference to select from.
|
||||
func (s *Selector) SetFilter(f string) {
|
||||
(*netmap.Selector)(s).
|
||||
SetFilter(f)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue