diff --git a/netmap/policy.go b/netmap/policy.go index 114866f..48c5ca2 100644 --- a/netmap/policy.go +++ b/netmap/policy.go @@ -393,49 +393,28 @@ func (p *PlacementPolicy) AddFilters(fs ...Filter) { // the result into w. Returns w's errors directly. // // See also DecodeString. -// -// nolint: funlen, gocognit func (p PlacementPolicy) WriteStringTo(w io.StringWriter) (err error) { - writtenSmth := false - - writeLnIfNeeded := func() error { - if writtenSmth { - _, err = w.WriteString("\n") - return err - } - - writtenSmth = true - - return nil - } + delim := "" for i := range p.replicas { - err = writeLnIfNeeded() - if err != nil { - return err - } - c := p.replicas[i].GetCount() s := p.replicas[i].GetSelector() if s != "" { - _, err = w.WriteString(fmt.Sprintf("REP %d IN %s", c, s)) + _, err = w.WriteString(fmt.Sprintf("%sREP %d IN %s", delim, c, s)) } else { - _, err = w.WriteString(fmt.Sprintf("REP %d", c)) + _, err = w.WriteString(fmt.Sprintf("%sREP %d", delim, c)) } if err != nil { return err } + + delim = "\n" } if p.backupFactor > 0 { - err = writeLnIfNeeded() - if err != nil { - return err - } - - _, err = w.WriteString(fmt.Sprintf("CBF %d", p.backupFactor)) + _, err = w.WriteString(fmt.Sprintf("\nCBF %d", p.backupFactor)) if err != nil { return err } @@ -444,12 +423,7 @@ func (p PlacementPolicy) WriteStringTo(w io.StringWriter) (err error) { var s string for i := range p.selectors { - err = writeLnIfNeeded() - if err != nil { - return err - } - - _, err = w.WriteString(fmt.Sprintf("SELECT %d", p.selectors[i].GetCount())) + _, err = w.WriteString(fmt.Sprintf("\nSELECT %d", p.selectors[i].GetCount())) if err != nil { return err } @@ -488,12 +462,7 @@ func (p PlacementPolicy) WriteStringTo(w io.StringWriter) (err error) { } for i := range p.filters { - err = writeLnIfNeeded() - if err != nil { - return err - } - - _, err = w.WriteString("FILTER ") + _, err = w.WriteString("\nFILTER ") if err != nil { return err }