[#255] pkg/object: Implement json.Marshaler/Unmarshaler on SearchFilters

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2021-02-10 01:32:13 +03:00 committed by Alex Vanin
parent f9939e8c90
commit e782531f25
2 changed files with 35 additions and 0 deletions

View file

@ -1,6 +1,7 @@
package object
import (
"encoding/json"
"fmt"
"github.com/nspcc-dev/neofs-api-go/pkg"
@ -255,3 +256,21 @@ func (f *SearchFilters) AddSplitIDFilter(m SearchMatchType, id *SplitID) {
func (f *SearchFilters) AddTypeFilter(m SearchMatchType, typ Type) {
f.addReservedFilter(m, fKeyType, typ)
}
// MarshalJSON encodes SearchFilters to protobuf JSON format.
func (f *SearchFilters) MarshalJSON() ([]byte, error) {
return json.Marshal(f.ToV2())
}
// UnmarshalJSON decodes SearchFilters from protobuf JSON format.
func (f *SearchFilters) UnmarshalJSON(data []byte) error {
var fsV2 []*v2object.SearchFilter
if err := json.Unmarshal(data, &fsV2); err != nil {
return err
}
*f = NewSearchFiltersFromV2(fsV2)
return nil
}