diff --git a/Makefile b/Makefile index 6ceea25..8841929 100755 --- a/Makefile +++ b/Makefile @@ -46,7 +46,9 @@ protoc: @for f in `find . -type f -name '*.proto' -not -path './vendor/*'`; do \ echo "⇒ Processing $$f "; \ protoc \ - --proto_path=.:./vendor:/usr/local/include \ + --proto_path=.:./vendor:/usr/local/include:/home/aarifullin/ws/frostfs-api \ + --plugin=protoc-gen-go-frostfs=/home/aarifullin/ws/frostfs-api-go/util/protogen/protogen \ + --go-frostfs_out=. --go-frostfs_opt=paths=source_relative \ --go_out=. --go_opt=paths=source_relative \ --go-grpc_opt=require_unimplemented_servers=false \ --go-grpc_out=. --go-grpc_opt=paths=source_relative $$f; \ diff --git a/accounting/accounting.go b/accounting/accounting.go deleted file mode 100644 index af14a1a..0000000 --- a/accounting/accounting.go +++ /dev/null @@ -1,104 +0,0 @@ -package accounting - -import ( - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/session" -) - -type BalanceRequestBody struct { - ownerID *refs.OwnerID -} - -type BalanceResponseBody struct { - bal *Decimal -} - -type Decimal struct { - val int64 - - prec uint32 -} - -type BalanceRequest struct { - body *BalanceRequestBody - - session.RequestHeaders -} - -type BalanceResponse struct { - body *BalanceResponseBody - - session.ResponseHeaders -} - -func (b *BalanceRequestBody) GetOwnerID() *refs.OwnerID { - if b != nil { - return b.ownerID - } - - return nil -} - -func (b *BalanceRequestBody) SetOwnerID(v *refs.OwnerID) { - b.ownerID = v -} - -func (b *BalanceRequest) GetBody() *BalanceRequestBody { - if b != nil { - return b.body - } - - return nil -} - -func (b *BalanceRequest) SetBody(v *BalanceRequestBody) { - b.body = v -} - -func (d *Decimal) GetValue() int64 { - if d != nil { - return d.val - } - - return 0 -} - -func (d *Decimal) SetValue(v int64) { - d.val = v -} - -func (d *Decimal) GetPrecision() uint32 { - if d != nil { - return d.prec - } - - return 0 -} - -func (d *Decimal) SetPrecision(v uint32) { - d.prec = v -} - -func (br *BalanceResponseBody) GetBalance() *Decimal { - if br != nil { - return br.bal - } - - return nil -} - -func (br *BalanceResponseBody) SetBalance(v *Decimal) { - br.bal = v -} - -func (br *BalanceResponse) GetBody() *BalanceResponseBody { - if br != nil { - return br.body - } - - return nil -} - -func (br *BalanceResponse) SetBody(v *BalanceResponseBody) { - br.body = v -} diff --git a/accounting/convert.go b/accounting/convert.go deleted file mode 100644 index 7a7f250..0000000 --- a/accounting/convert.go +++ /dev/null @@ -1,178 +0,0 @@ -package accounting - -import ( - accounting "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/accounting/grpc" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs" - refsGRPC "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs/grpc" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/grpc" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message" -) - -func (b *BalanceRequestBody) ToGRPCMessage() grpc.Message { - var m *accounting.BalanceRequest_Body - - if b != nil { - m = new(accounting.BalanceRequest_Body) - - m.SetOwnerId(b.ownerID.ToGRPCMessage().(*refsGRPC.OwnerID)) - } - - return m -} - -func (b *BalanceRequestBody) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*accounting.BalanceRequest_Body) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var err error - - ownerID := v.GetOwnerId() - if ownerID == nil { - b.ownerID = nil - } else { - if b.ownerID == nil { - b.ownerID = new(refs.OwnerID) - } - - err = b.ownerID.FromGRPCMessage(ownerID) - } - - return err -} - -func (b *BalanceRequest) ToGRPCMessage() grpc.Message { - var m *accounting.BalanceRequest - - if b != nil { - m = new(accounting.BalanceRequest) - - m.SetBody(b.body.ToGRPCMessage().(*accounting.BalanceRequest_Body)) - b.RequestHeaders.ToMessage(m) - } - - return m -} - -func (b *BalanceRequest) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*accounting.BalanceRequest) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var err error - - body := v.GetBody() - if body == nil { - b.body = nil - } else { - if b.body == nil { - b.body = new(BalanceRequestBody) - } - - err = b.body.FromGRPCMessage(body) - if err != nil { - return err - } - } - - return b.RequestHeaders.FromMessage(v) -} - -func (d *Decimal) ToGRPCMessage() grpc.Message { - var m *accounting.Decimal - - if d != nil { - m = new(accounting.Decimal) - - m.SetValue(d.val) - m.SetPrecision(d.prec) - } - - return m -} - -func (d *Decimal) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*accounting.Decimal) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - d.val = v.GetValue() - d.prec = v.GetPrecision() - - return nil -} - -func (br *BalanceResponseBody) ToGRPCMessage() grpc.Message { - var m *accounting.BalanceResponse_Body - - if br != nil { - m = new(accounting.BalanceResponse_Body) - - m.SetBalance(br.bal.ToGRPCMessage().(*accounting.Decimal)) - } - - return m -} - -func (br *BalanceResponseBody) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*accounting.BalanceResponse_Body) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var err error - - bal := v.GetBalance() - if bal == nil { - br.bal = nil - } else { - if br.bal == nil { - br.bal = new(Decimal) - } - - err = br.bal.FromGRPCMessage(bal) - } - - return err -} - -func (br *BalanceResponse) ToGRPCMessage() grpc.Message { - var m *accounting.BalanceResponse - - if br != nil { - m = new(accounting.BalanceResponse) - - m.SetBody(br.body.ToGRPCMessage().(*accounting.BalanceResponse_Body)) - br.ResponseHeaders.ToMessage(m) - } - - return m -} - -func (br *BalanceResponse) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*accounting.BalanceResponse) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var err error - - body := v.GetBody() - if body == nil { - br.body = nil - } else { - if br.body == nil { - br.body = new(BalanceResponseBody) - } - - err = br.body.FromGRPCMessage(body) - if err != nil { - return err - } - } - - return br.ResponseHeaders.FromMessage(v) -} diff --git a/accounting/grpc/service.pb.go b/accounting/grpc/service.pb.go index 9699622..4c0e529 100644 Binary files a/accounting/grpc/service.pb.go and b/accounting/grpc/service.pb.go differ diff --git a/accounting/grpc/service_frostfs.pb.go b/accounting/grpc/service_frostfs.pb.go new file mode 100644 index 0000000..faacb90 Binary files /dev/null and b/accounting/grpc/service_frostfs.pb.go differ diff --git a/accounting/grpc/service_grpc.pb.go b/accounting/grpc/service_grpc.pb.go index 1e1b17e..c72e811 100644 Binary files a/accounting/grpc/service_grpc.pb.go and b/accounting/grpc/service_grpc.pb.go differ diff --git a/accounting/grpc/types.pb.go b/accounting/grpc/types.pb.go index b8dff21..da24b06 100644 Binary files a/accounting/grpc/types.pb.go and b/accounting/grpc/types.pb.go differ diff --git a/accounting/grpc/types_frostfs.pb.go b/accounting/grpc/types_frostfs.pb.go new file mode 100644 index 0000000..028311c Binary files /dev/null and b/accounting/grpc/types_frostfs.pb.go differ diff --git a/accounting/json.go b/accounting/json.go deleted file mode 100644 index 9ed5620..0000000 --- a/accounting/json.go +++ /dev/null @@ -1,14 +0,0 @@ -package accounting - -import ( - accounting "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/accounting/grpc" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message" -) - -func (d *Decimal) MarshalJSON() ([]byte, error) { - return message.MarshalJSON(d) -} - -func (d *Decimal) UnmarshalJSON(data []byte) error { - return message.UnmarshalJSON(d, data, new(accounting.Decimal)) -} diff --git a/accounting/marshal.go b/accounting/marshal.go deleted file mode 100644 index 6961b3e..0000000 --- a/accounting/marshal.go +++ /dev/null @@ -1,104 +0,0 @@ -package accounting - -import ( - accounting "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/accounting/grpc" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message" - protoutil "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/util/proto" -) - -const ( - decimalValueField = 1 - decimalPrecisionField = 2 - - balanceReqBodyOwnerField = 1 - - balanceRespBodyDecimalField = 1 -) - -func (d *Decimal) StableMarshal(buf []byte) []byte { - if d == nil { - return []byte{} - } - - if buf == nil { - buf = make([]byte, d.StableSize()) - } - - var offset int - - offset += protoutil.Int64Marshal(decimalValueField, buf[offset:], d.val) - protoutil.UInt32Marshal(decimalPrecisionField, buf[offset:], d.prec) - - return buf -} - -func (d *Decimal) StableSize() (size int) { - if d == nil { - return 0 - } - - size += protoutil.Int64Size(decimalValueField, d.val) - size += protoutil.UInt32Size(decimalPrecisionField, d.prec) - - return size -} - -func (d *Decimal) Unmarshal(data []byte) error { - return message.Unmarshal(d, data, new(accounting.Decimal)) -} - -func (b *BalanceRequestBody) StableMarshal(buf []byte) []byte { - if b == nil { - return []byte{} - } - - if buf == nil { - buf = make([]byte, b.StableSize()) - } - - protoutil.NestedStructureMarshal(balanceReqBodyOwnerField, buf, b.ownerID) - - return buf -} - -func (b *BalanceRequestBody) StableSize() (size int) { - if b == nil { - return 0 - } - - size = protoutil.NestedStructureSize(balanceReqBodyOwnerField, b.ownerID) - - return size -} - -func (b *BalanceRequestBody) Unmarshal(data []byte) error { - return message.Unmarshal(b, data, new(accounting.BalanceRequest_Body)) -} - -func (br *BalanceResponseBody) StableMarshal(buf []byte) []byte { - if br == nil { - return []byte{} - } - - if buf == nil { - buf = make([]byte, br.StableSize()) - } - - protoutil.NestedStructureMarshal(balanceRespBodyDecimalField, buf, br.bal) - - return buf -} - -func (br *BalanceResponseBody) StableSize() (size int) { - if br == nil { - return 0 - } - - size = protoutil.NestedStructureSize(balanceRespBodyDecimalField, br.bal) - - return size -} - -func (br *BalanceResponseBody) Unmarshal(data []byte) error { - return message.Unmarshal(br, data, new(accounting.BalanceResponse_Body)) -} diff --git a/accounting/message_test.go b/accounting/message_test.go index d193558..52289a7 100644 --- a/accounting/message_test.go +++ b/accounting/message_test.go @@ -4,16 +4,16 @@ import ( "testing" accountingtest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/accounting/test" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message" messagetest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message/test" + "google.golang.org/protobuf/proto" ) func TestMessage(t *testing.T) { messagetest.TestRPCMessage(t, - func(empty bool) message.Message { return accountingtest.GenerateDecimal(empty) }, - func(empty bool) message.Message { return accountingtest.GenerateBalanceRequestBody(empty) }, - func(empty bool) message.Message { return accountingtest.GenerateBalanceRequest(empty) }, - func(empty bool) message.Message { return accountingtest.GenerateBalanceResponseBody(empty) }, - func(empty bool) message.Message { return accountingtest.GenerateBalanceResponse(empty) }, + func(empty bool) proto.Message { return accountingtest.GenerateDecimal(empty) }, + func(empty bool) proto.Message { return accountingtest.GenerateBalanceRequestBody(empty) }, + func(empty bool) proto.Message { return accountingtest.GenerateBalanceRequest(empty) }, + func(empty bool) proto.Message { return accountingtest.GenerateBalanceResponseBody(empty) }, + func(empty bool) proto.Message { return accountingtest.GenerateBalanceResponse(empty) }, ) } diff --git a/accounting/test/generate.go b/accounting/test/generate.go index 1eaf9f4..9d9820c 100644 --- a/accounting/test/generate.go +++ b/accounting/test/generate.go @@ -1,7 +1,7 @@ package accountingtest import ( - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/accounting" + accounting "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/accounting/grpc" accountingtest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs/test" sessiontest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/session/test" ) @@ -14,16 +14,16 @@ func GenerateBalanceRequest(empty bool) *accounting.BalanceRequest { } m.SetMetaHeader(sessiontest.GenerateRequestMetaHeader(empty)) - m.SetVerificationHeader(sessiontest.GenerateRequestVerificationHeader(empty)) + m.SetVerifyHeader(sessiontest.GenerateRequestVerificationHeader(empty)) return m } -func GenerateBalanceRequestBody(empty bool) *accounting.BalanceRequestBody { - m := new(accounting.BalanceRequestBody) +func GenerateBalanceRequestBody(empty bool) *accounting.BalanceRequest_Body { + m := new(accounting.BalanceRequest_Body) if !empty { - m.SetOwnerID(accountingtest.GenerateOwnerID(false)) + m.SetOwnerId(accountingtest.GenerateOwnerID(false)) } return m @@ -37,13 +37,13 @@ func GenerateBalanceResponse(empty bool) *accounting.BalanceResponse { } m.SetMetaHeader(sessiontest.GenerateResponseMetaHeader(empty)) - m.SetVerificationHeader(sessiontest.GenerateResponseVerificationHeader(empty)) + m.SetVerifyHeader(sessiontest.GenerateResponseVerificationHeader(empty)) return m } -func GenerateBalanceResponseBody(empty bool) *accounting.BalanceResponseBody { - m := new(accounting.BalanceResponseBody) +func GenerateBalanceResponseBody(empty bool) *accounting.BalanceResponse_Body { + m := new(accounting.BalanceResponse_Body) if !empty { m.SetBalance(GenerateDecimal(false)) @@ -54,7 +54,6 @@ func GenerateBalanceResponseBody(empty bool) *accounting.BalanceResponseBody { func GenerateDecimal(empty bool) *accounting.Decimal { m := new(accounting.Decimal) - if !empty { m.SetValue(1) m.SetPrecision(2) diff --git a/acl/bench_test.go b/acl/bench_test.go index 8d6352b..da6e496 100644 --- a/acl/bench_test.go +++ b/acl/bench_test.go @@ -3,24 +3,23 @@ package acl_test import ( "testing" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/acl" - aclGrpc "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/acl/grpc" + acl "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/acl/grpc" acltest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/acl/test" ) -func BenchmarkTable_ToGRPCMessage(b *testing.B) { +func BenchmarkTable_StableMarshal(b *testing.B) { const size = 4 - tb := new(acl.Table) - rs := make([]acl.Record, size) + tb := new(acl.EACLTable) + rs := acltest.GenerateRecords(true) for i := range rs { - fs := make([]acl.HeaderFilter, size) + fs := make([]*acl.EACLRecord_Filter, size) for j := range fs { - fs[j] = *acltest.GenerateFilter(false) + fs[j] = acltest.GenerateFilter(false) } - ts := make([]acl.Target, size) + ts := make([]*acl.EACLRecord_Target, size) for j := range ts { - ts[j] = *acltest.GenerateTarget(false) + ts[j] = acltest.GenerateTarget(false) } rs[i].SetFilters(fs) @@ -28,24 +27,10 @@ func BenchmarkTable_ToGRPCMessage(b *testing.B) { } tb.SetRecords(rs) - raw := tb.ToGRPCMessage() - - b.Run("to grpc message", func(b *testing.B) { - b.ReportAllocs() - for i := 0; i < b.N; i++ { - raw := tb.ToGRPCMessage() - if len(tb.GetRecords()) != len(raw.(*aclGrpc.EACLTable).Records) { - b.FailNow() - } + b.ReportAllocs() + for i := 0; i < b.N; i++ { + if len(tb.StableMarshal(nil)) != tb.StableSize() { + b.FailNow() } - }) - b.Run("from grpc message", func(b *testing.B) { - b.ReportAllocs() - for i := 0; i < b.N; i++ { - tb := new(acl.Table) - if tb.FromGRPCMessage(raw) != nil { - b.FailNow() - } - } - }) + } } diff --git a/acl/convert.go b/acl/convert.go deleted file mode 100644 index 3020f4d..0000000 --- a/acl/convert.go +++ /dev/null @@ -1,535 +0,0 @@ -package acl - -import ( - acl "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/acl/grpc" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs" - refsGRPC "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs/grpc" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/grpc" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message" -) - -// RoleToGRPCField converts unified role enum into grpc enum. -func RoleToGRPCField(t Role) acl.Role { - switch t { - case RoleUser: - return acl.Role_USER - case RoleSystem: - return acl.Role_SYSTEM - case RoleOthers: - return acl.Role_OTHERS - default: - return acl.Role_ROLE_UNSPECIFIED - } -} - -// RoleFromGRPCField converts grpc enum into unified role enum. -func RoleFromGRPCField(t acl.Role) Role { - switch t { - case acl.Role_USER: - return RoleUser - case acl.Role_SYSTEM: - return RoleSystem - case acl.Role_OTHERS: - return RoleOthers - default: - return RoleUnknown - } -} - -// OperationToGRPCField converts unified operation enum into grpc enum. -func OperationToGRPCField(t Operation) acl.Operation { - switch t { - case OperationPut: - return acl.Operation_PUT - case OperationDelete: - return acl.Operation_DELETE - case OperationGet: - return acl.Operation_GET - case OperationHead: - return acl.Operation_HEAD - case OperationSearch: - return acl.Operation_SEARCH - case OperationRange: - return acl.Operation_GETRANGE - case OperationRangeHash: - return acl.Operation_GETRANGEHASH - default: - return acl.Operation_OPERATION_UNSPECIFIED - } -} - -// OperationFromGRPCField converts grpc enum into unified operation enum. -func OperationFromGRPCField(t acl.Operation) Operation { - switch t { - case acl.Operation_PUT: - return OperationPut - case acl.Operation_DELETE: - return OperationDelete - case acl.Operation_GET: - return OperationGet - case acl.Operation_HEAD: - return OperationHead - case acl.Operation_SEARCH: - return OperationSearch - case acl.Operation_GETRANGE: - return OperationRange - case acl.Operation_GETRANGEHASH: - return OperationRangeHash - default: - return OperationUnknown - } -} - -// ActionToGRPCField converts unified action enum into grpc enum. -func ActionToGRPCField(t Action) acl.Action { - switch t { - case ActionDeny: - return acl.Action_DENY - case ActionAllow: - return acl.Action_ALLOW - default: - return acl.Action_ACTION_UNSPECIFIED - } -} - -// ActionFromGRPCField converts grpc enum into unified action enum. -func ActionFromGRPCField(t acl.Action) Action { - switch t { - case acl.Action_DENY: - return ActionDeny - case acl.Action_ALLOW: - return ActionAllow - default: - return ActionUnknown - } -} - -// HeaderTypeToGRPCField converts unified header type enum into grpc enum. -func HeaderTypeToGRPCField(t HeaderType) acl.HeaderType { - switch t { - case HeaderTypeRequest: - return acl.HeaderType_REQUEST - case HeaderTypeObject: - return acl.HeaderType_OBJECT - case HeaderTypeService: - return acl.HeaderType_SERVICE - default: - return acl.HeaderType_HEADER_UNSPECIFIED - } -} - -// HeaderTypeFromGRPCField converts grpc enum into unified header type enum. -func HeaderTypeFromGRPCField(t acl.HeaderType) HeaderType { - switch t { - case acl.HeaderType_REQUEST: - return HeaderTypeRequest - case acl.HeaderType_OBJECT: - return HeaderTypeObject - case acl.HeaderType_SERVICE: - return HeaderTypeService - default: - return HeaderTypeUnknown - } -} - -// MatchTypeToGRPCField converts unified match type enum into grpc enum. -func MatchTypeToGRPCField(t MatchType) acl.MatchType { - switch t { - case MatchTypeStringEqual: - return acl.MatchType_STRING_EQUAL - case MatchTypeStringNotEqual: - return acl.MatchType_STRING_NOT_EQUAL - default: - return acl.MatchType_MATCH_TYPE_UNSPECIFIED - } -} - -// MatchTypeFromGRPCField converts grpc enum into unified match type enum. -func MatchTypeFromGRPCField(t acl.MatchType) MatchType { - switch t { - case acl.MatchType_STRING_EQUAL: - return MatchTypeStringEqual - case acl.MatchType_STRING_NOT_EQUAL: - return MatchTypeStringNotEqual - default: - return MatchTypeUnknown - } -} - -func (f *HeaderFilter) ToGRPCMessage() grpc.Message { - var m *acl.EACLRecord_Filter - - if f != nil { - m = new(acl.EACLRecord_Filter) - - m.SetKey(f.key) - m.SetValue(f.value) - m.SetHeader(HeaderTypeToGRPCField(f.hdrType)) - m.SetMatchType(MatchTypeToGRPCField(f.matchType)) - } - - return m -} - -func (f *HeaderFilter) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*acl.EACLRecord_Filter) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - f.key = v.GetKey() - f.value = v.GetValue() - f.hdrType = HeaderTypeFromGRPCField(v.GetHeaderType()) - f.matchType = MatchTypeFromGRPCField(v.GetMatchType()) - - return nil -} - -func HeaderFiltersToGRPC(fs []HeaderFilter) (res []*acl.EACLRecord_Filter) { - if fs != nil { - res = make([]*acl.EACLRecord_Filter, 0, len(fs)) - - for i := range fs { - res = append(res, fs[i].ToGRPCMessage().(*acl.EACLRecord_Filter)) - } - } - - return -} - -func HeaderFiltersFromGRPC(fs []*acl.EACLRecord_Filter) (res []HeaderFilter, err error) { - if fs != nil { - res = make([]HeaderFilter, len(fs)) - - for i := range fs { - if fs[i] != nil { - err = res[i].FromGRPCMessage(fs[i]) - if err != nil { - return - } - } - } - } - - return -} - -func (t *Target) ToGRPCMessage() grpc.Message { - var m *acl.EACLRecord_Target - - if t != nil { - m = new(acl.EACLRecord_Target) - - m.SetRole(RoleToGRPCField(t.role)) - m.SetKeys(t.keys) - } - - return m -} - -func (t *Target) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*acl.EACLRecord_Target) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - t.role = RoleFromGRPCField(v.GetRole()) - t.keys = v.GetKeys() - - return nil -} - -func TargetsToGRPC(ts []Target) (res []*acl.EACLRecord_Target) { - if ts != nil { - res = make([]*acl.EACLRecord_Target, 0, len(ts)) - - for i := range ts { - res = append(res, ts[i].ToGRPCMessage().(*acl.EACLRecord_Target)) - } - } - - return -} - -func TargetsFromGRPC(fs []*acl.EACLRecord_Target) (res []Target, err error) { - if fs != nil { - res = make([]Target, len(fs)) - - for i := range fs { - if fs[i] != nil { - err = res[i].FromGRPCMessage(fs[i]) - if err != nil { - return - } - } - } - } - - return -} - -func (r *Record) ToGRPCMessage() grpc.Message { - var m *acl.EACLRecord - - if r != nil { - m = new(acl.EACLRecord) - - m.SetOperation(OperationToGRPCField(r.op)) - m.SetAction(ActionToGRPCField(r.action)) - m.SetFilters(HeaderFiltersToGRPC(r.filters)) - m.SetTargets(TargetsToGRPC(r.targets)) - } - - return m -} - -func (r *Record) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*acl.EACLRecord) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var err error - - r.filters, err = HeaderFiltersFromGRPC(v.GetFilters()) - if err != nil { - return err - } - - r.targets, err = TargetsFromGRPC(v.GetTargets()) - if err != nil { - return err - } - - r.op = OperationFromGRPCField(v.GetOperation()) - r.action = ActionFromGRPCField(v.GetAction()) - - return nil -} - -func RecordsToGRPC(ts []Record) (res []*acl.EACLRecord) { - if ts != nil { - res = make([]*acl.EACLRecord, 0, len(ts)) - - for i := range ts { - res = append(res, ts[i].ToGRPCMessage().(*acl.EACLRecord)) - } - } - - return -} - -func RecordsFromGRPC(fs []*acl.EACLRecord) (res []Record, err error) { - if fs != nil { - res = make([]Record, len(fs)) - - for i := range fs { - if fs[i] != nil { - err = res[i].FromGRPCMessage(fs[i]) - if err != nil { - return - } - } - } - } - - return -} - -func (t *Table) ToGRPCMessage() grpc.Message { - var m *acl.EACLTable - - if t != nil { - m = new(acl.EACLTable) - - m.SetVersion(t.version.ToGRPCMessage().(*refsGRPC.Version)) - m.SetContainerId(t.cid.ToGRPCMessage().(*refsGRPC.ContainerID)) - m.SetRecords(RecordsToGRPC(t.records)) - } - - return m -} - -func (t *Table) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*acl.EACLTable) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var err error - - cid := v.GetContainerId() - if cid == nil { - t.cid = nil - } else { - if t.cid == nil { - t.cid = new(refs.ContainerID) - } - - err = t.cid.FromGRPCMessage(cid) - if err != nil { - return err - } - } - - version := v.GetVersion() - if version == nil { - t.version = nil - } else { - if t.version == nil { - t.version = new(refs.Version) - } - - err = t.version.FromGRPCMessage(version) - if err != nil { - return err - } - } - - t.records, err = RecordsFromGRPC(v.GetRecords()) - - return err -} - -func (l *TokenLifetime) ToGRPCMessage() grpc.Message { - var m *acl.BearerToken_Body_TokenLifetime - - if l != nil { - m = new(acl.BearerToken_Body_TokenLifetime) - - m.SetExp(l.exp) - m.SetIat(l.iat) - m.SetNbf(l.nbf) - } - - return m -} - -func (l *TokenLifetime) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*acl.BearerToken_Body_TokenLifetime) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - l.exp = v.GetExp() - l.iat = v.GetIat() - l.nbf = v.GetNbf() - - return nil -} - -func (bt *BearerTokenBody) ToGRPCMessage() grpc.Message { - var m *acl.BearerToken_Body - - if bt != nil { - m = new(acl.BearerToken_Body) - - m.SetOwnerId(bt.ownerID.ToGRPCMessage().(*refsGRPC.OwnerID)) - m.SetLifetime(bt.lifetime.ToGRPCMessage().(*acl.BearerToken_Body_TokenLifetime)) - m.SetEaclTable(bt.eacl.ToGRPCMessage().(*acl.EACLTable)) - m.SetImpersonate(bt.impersonate) - } - - return m -} - -func (bt *BearerTokenBody) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*acl.BearerToken_Body) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var err error - - ownerID := v.GetOwnerId() - if ownerID == nil { - bt.ownerID = nil - } else { - if bt.ownerID == nil { - bt.ownerID = new(refs.OwnerID) - } - - err = bt.ownerID.FromGRPCMessage(ownerID) - if err != nil { - return err - } - } - - lifetime := v.GetLifetime() - if lifetime == nil { - bt.lifetime = nil - } else { - if bt.lifetime == nil { - bt.lifetime = new(TokenLifetime) - } - - err = bt.lifetime.FromGRPCMessage(lifetime) - if err != nil { - return err - } - } - - eacl := v.GetEaclTable() - if eacl == nil { - bt.eacl = nil - } else { - if bt.eacl == nil { - bt.eacl = new(Table) - } - - err = bt.eacl.FromGRPCMessage(eacl) - } - - bt.impersonate = v.GetAllowImpersonate() - - return err -} - -func (bt *BearerToken) ToGRPCMessage() grpc.Message { - var m *acl.BearerToken - - if bt != nil { - m = new(acl.BearerToken) - - m.SetBody(bt.body.ToGRPCMessage().(*acl.BearerToken_Body)) - m.SetSignature(bt.sig.ToGRPCMessage().(*refsGRPC.Signature)) - } - - return m -} - -func (bt *BearerToken) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*acl.BearerToken) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var err error - - body := v.GetBody() - if body == nil { - bt.body = nil - } else { - if bt.body == nil { - bt.body = new(BearerTokenBody) - } - - err = bt.body.FromGRPCMessage(body) - if err != nil { - return err - } - } - - sig := v.GetSignature() - if sig == nil { - bt.sig = nil - } else { - if bt.sig == nil { - bt.sig = new(refs.Signature) - } - - err = bt.sig.FromGRPCMessage(sig) - } - - return err -} diff --git a/acl/grpc/types.pb.go b/acl/grpc/types.pb.go index 94a8e47..8ca9677 100644 Binary files a/acl/grpc/types.pb.go and b/acl/grpc/types.pb.go differ diff --git a/acl/grpc/types_frostfs.pb.go b/acl/grpc/types_frostfs.pb.go new file mode 100644 index 0000000..bb571f0 Binary files /dev/null and b/acl/grpc/types_frostfs.pb.go differ diff --git a/acl/json.go b/acl/json.go deleted file mode 100644 index 0e2078b..0000000 --- a/acl/json.go +++ /dev/null @@ -1,62 +0,0 @@ -package acl - -import ( - acl "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/acl/grpc" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message" -) - -func (f *HeaderFilter) MarshalJSON() ([]byte, error) { - return message.MarshalJSON(f) -} - -func (f *HeaderFilter) UnmarshalJSON(data []byte) error { - return message.UnmarshalJSON(f, data, new(acl.EACLRecord_Filter)) -} - -func (t *Target) MarshalJSON() ([]byte, error) { - return message.MarshalJSON(t) -} - -func (t *Target) UnmarshalJSON(data []byte) error { - return message.UnmarshalJSON(t, data, new(acl.EACLRecord_Target)) -} - -func (r *Record) MarshalJSON() ([]byte, error) { - return message.MarshalJSON(r) -} - -func (r *Record) UnmarshalJSON(data []byte) error { - return message.UnmarshalJSON(r, data, new(acl.EACLRecord)) -} - -func (t *Table) MarshalJSON() ([]byte, error) { - return message.MarshalJSON(t) -} - -func (t *Table) UnmarshalJSON(data []byte) error { - return message.UnmarshalJSON(t, data, new(acl.EACLTable)) -} - -func (l *TokenLifetime) MarshalJSON() ([]byte, error) { - return message.MarshalJSON(l) -} - -func (l *TokenLifetime) UnmarshalJSON(data []byte) error { - return message.UnmarshalJSON(l, data, new(acl.BearerToken_Body_TokenLifetime)) -} - -func (bt *BearerTokenBody) MarshalJSON() ([]byte, error) { - return message.MarshalJSON(bt) -} - -func (bt *BearerTokenBody) UnmarshalJSON(data []byte) error { - return message.UnmarshalJSON(bt, data, new(acl.BearerToken_Body)) -} - -func (bt *BearerToken) MarshalJSON() ([]byte, error) { - return message.MarshalJSON(bt) -} - -func (bt *BearerToken) UnmarshalJSON(data []byte) error { - return message.UnmarshalJSON(bt, data, new(acl.BearerToken)) -} diff --git a/acl/marshal.go b/acl/marshal.go deleted file mode 100644 index cd6c6dd..0000000 --- a/acl/marshal.go +++ /dev/null @@ -1,308 +0,0 @@ -package acl - -import ( - acl "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/acl/grpc" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message" - protoutil "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/util/proto" -) - -const ( - filterHeaderTypeField = 1 - filterMatchTypeField = 2 - filterNameField = 3 - filterValueField = 4 - - targetTypeField = 1 - targetKeysField = 2 - - recordOperationField = 1 - recordActionField = 2 - recordFiltersField = 3 - recordTargetsField = 4 - - tableVersionField = 1 - tableContainerIDField = 2 - tableRecordsField = 3 - - lifetimeExpirationField = 1 - lifetimeNotValidBeforeField = 2 - lifetimeIssuedAtField = 3 - - bearerTokenBodyACLField = 1 - bearerTokenBodyOwnerField = 2 - bearerTokenBodyLifetimeField = 3 - bearerTokenBodyImpersonate = 4 - - bearerTokenBodyField = 1 - bearerTokenSignatureField = 2 -) - -// StableMarshal marshals unified acl table structure in a protobuf -// compatible way without field order shuffle. -func (t *Table) StableMarshal(buf []byte) []byte { - if t == nil { - return []byte{} - } - - if buf == nil { - buf = make([]byte, t.StableSize()) - } - - var offset int - - offset += protoutil.NestedStructureMarshal(tableVersionField, buf[offset:], t.version) - offset += protoutil.NestedStructureMarshal(tableContainerIDField, buf[offset:], t.cid) - - for i := range t.records { - offset += protoutil.NestedStructureMarshal(tableRecordsField, buf[offset:], &t.records[i]) - } - - return buf -} - -// StableSize of acl table structure marshalled by StableMarshal function. -func (t *Table) StableSize() (size int) { - if t == nil { - return 0 - } - - size += protoutil.NestedStructureSize(tableVersionField, t.version) - size += protoutil.NestedStructureSize(tableContainerIDField, t.cid) - - for i := range t.records { - size += protoutil.NestedStructureSize(tableRecordsField, &t.records[i]) - } - - return size -} - -func (t *Table) Unmarshal(data []byte) error { - return message.Unmarshal(t, data, new(acl.EACLTable)) -} - -// StableMarshal marshals unified acl record structure in a protobuf -// compatible way without field order shuffle. -func (r *Record) StableMarshal(buf []byte) []byte { - if r == nil { - return []byte{} - } - - if buf == nil { - buf = make([]byte, r.StableSize()) - } - - var offset int - - offset += protoutil.EnumMarshal(recordOperationField, buf[offset:], int32(r.op)) - offset += protoutil.EnumMarshal(recordActionField, buf[offset:], int32(r.action)) - - for i := range r.filters { - offset += protoutil.NestedStructureMarshal(recordFiltersField, buf[offset:], &r.filters[i]) - } - - for i := range r.targets { - offset += protoutil.NestedStructureMarshal(recordTargetsField, buf[offset:], &r.targets[i]) - } - - return buf -} - -// StableSize of acl record structure marshalled by StableMarshal function. -func (r *Record) StableSize() (size int) { - if r == nil { - return 0 - } - - size += protoutil.EnumSize(recordOperationField, int32(r.op)) - size += protoutil.EnumSize(recordActionField, int32(r.action)) - - for i := range r.filters { - size += protoutil.NestedStructureSize(recordFiltersField, &r.filters[i]) - } - - for i := range r.targets { - size += protoutil.NestedStructureSize(recordTargetsField, &r.targets[i]) - } - - return size -} - -func (r *Record) Unmarshal(data []byte) error { - return message.Unmarshal(r, data, new(acl.EACLRecord)) -} - -// StableMarshal marshals unified header filter structure in a protobuf -// compatible way without field order shuffle. -func (f *HeaderFilter) StableMarshal(buf []byte) []byte { - if f == nil { - return []byte{} - } - - if buf == nil { - buf = make([]byte, f.StableSize()) - } - - var offset int - - offset += protoutil.EnumMarshal(filterHeaderTypeField, buf[offset:], int32(f.hdrType)) - offset += protoutil.EnumMarshal(filterMatchTypeField, buf[offset:], int32(f.matchType)) - offset += protoutil.StringMarshal(filterNameField, buf[offset:], f.key) - protoutil.StringMarshal(filterValueField, buf[offset:], f.value) - - return buf -} - -// StableSize of header filter structure marshalled by StableMarshal function. -func (f *HeaderFilter) StableSize() (size int) { - if f == nil { - return 0 - } - - size += protoutil.EnumSize(filterHeaderTypeField, int32(f.hdrType)) - size += protoutil.EnumSize(filterMatchTypeField, int32(f.matchType)) - size += protoutil.StringSize(filterNameField, f.key) - size += protoutil.StringSize(filterValueField, f.value) - - return size -} - -func (f *HeaderFilter) Unmarshal(data []byte) error { - return message.Unmarshal(f, data, new(acl.EACLRecord_Filter)) -} - -// StableMarshal marshals unified role info structure in a protobuf -// compatible way without field order shuffle. -func (t *Target) StableMarshal(buf []byte) []byte { - if t == nil { - return []byte{} - } - - if buf == nil { - buf = make([]byte, t.StableSize()) - } - - var offset int - - offset += protoutil.EnumMarshal(targetTypeField, buf[offset:], int32(t.role)) - protoutil.RepeatedBytesMarshal(targetKeysField, buf[offset:], t.keys) - - return buf -} - -// StableSize of role info structure marshalled by StableMarshal function. -func (t *Target) StableSize() (size int) { - if t == nil { - return 0 - } - - size += protoutil.EnumSize(targetTypeField, int32(t.role)) - size += protoutil.RepeatedBytesSize(targetKeysField, t.keys) - - return size -} - -func (t *Target) Unmarshal(data []byte) error { - return message.Unmarshal(t, data, new(acl.EACLRecord_Target)) -} - -func (l *TokenLifetime) StableMarshal(buf []byte) []byte { - if l == nil { - return []byte{} - } - - if buf == nil { - buf = make([]byte, l.StableSize()) - } - - var offset int - - offset += protoutil.UInt64Marshal(lifetimeExpirationField, buf[offset:], l.exp) - offset += protoutil.UInt64Marshal(lifetimeNotValidBeforeField, buf[offset:], l.nbf) - protoutil.UInt64Marshal(lifetimeIssuedAtField, buf[offset:], l.iat) - - return buf -} - -func (l *TokenLifetime) StableSize() (size int) { - if l == nil { - return 0 - } - - size += protoutil.UInt64Size(lifetimeExpirationField, l.exp) - size += protoutil.UInt64Size(lifetimeNotValidBeforeField, l.nbf) - size += protoutil.UInt64Size(lifetimeIssuedAtField, l.iat) - - return size -} - -func (l *TokenLifetime) Unmarshal(data []byte) error { - return message.Unmarshal(l, data, new(acl.BearerToken_Body_TokenLifetime)) -} - -func (bt *BearerTokenBody) StableMarshal(buf []byte) []byte { - if bt == nil { - return []byte{} - } - - if buf == nil { - buf = make([]byte, bt.StableSize()) - } - - var offset int - - offset += protoutil.NestedStructureMarshal(bearerTokenBodyACLField, buf[offset:], bt.eacl) - offset += protoutil.NestedStructureMarshal(bearerTokenBodyOwnerField, buf[offset:], bt.ownerID) - offset += protoutil.NestedStructureMarshal(bearerTokenBodyLifetimeField, buf[offset:], bt.lifetime) - protoutil.BoolMarshal(bearerTokenBodyImpersonate, buf[offset:], bt.impersonate) - - return buf -} - -func (bt *BearerTokenBody) StableSize() (size int) { - if bt == nil { - return 0 - } - - size += protoutil.NestedStructureSize(bearerTokenBodyACLField, bt.eacl) - size += protoutil.NestedStructureSize(bearerTokenBodyOwnerField, bt.ownerID) - size += protoutil.NestedStructureSize(bearerTokenBodyLifetimeField, bt.lifetime) - size += protoutil.BoolSize(bearerTokenBodyImpersonate, bt.impersonate) - - return size -} - -func (bt *BearerTokenBody) Unmarshal(data []byte) error { - return message.Unmarshal(bt, data, new(acl.BearerToken_Body)) -} - -func (bt *BearerToken) StableMarshal(buf []byte) []byte { - if bt == nil { - return []byte{} - } - - if buf == nil { - buf = make([]byte, bt.StableSize()) - } - - var offset int - - offset += protoutil.NestedStructureMarshal(bearerTokenBodyField, buf[offset:], bt.body) - protoutil.NestedStructureMarshal(bearerTokenSignatureField, buf[offset:], bt.sig) - - return buf -} - -func (bt *BearerToken) StableSize() (size int) { - if bt == nil { - return 0 - } - - size += protoutil.NestedStructureSize(bearerTokenBodyField, bt.body) - size += protoutil.NestedStructureSize(bearerTokenSignatureField, bt.sig) - - return size -} - -func (bt *BearerToken) Unmarshal(data []byte) error { - return message.Unmarshal(bt, data, new(acl.BearerToken)) -} diff --git a/acl/message_test.go b/acl/message_test.go index 8f340f1..517b2bb 100644 --- a/acl/message_test.go +++ b/acl/message_test.go @@ -4,18 +4,18 @@ import ( "testing" acltest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/acl/test" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message" messagetest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message/test" + "google.golang.org/protobuf/proto" ) func TestMessageConvert(t *testing.T) { messagetest.TestRPCMessage(t, - func(empty bool) message.Message { return acltest.GenerateFilter(empty) }, - func(empty bool) message.Message { return acltest.GenerateTarget(empty) }, - func(empty bool) message.Message { return acltest.GenerateRecord(empty) }, - func(empty bool) message.Message { return acltest.GenerateTable(empty) }, - func(empty bool) message.Message { return acltest.GenerateTokenLifetime(empty) }, - func(empty bool) message.Message { return acltest.GenerateBearerTokenBody(empty) }, - func(empty bool) message.Message { return acltest.GenerateBearerToken(empty) }, + func(empty bool) proto.Message { return acltest.GenerateFilter(empty) }, + func(empty bool) proto.Message { return acltest.GenerateTarget(empty) }, + func(empty bool) proto.Message { return acltest.GenerateRecord(empty) }, + func(empty bool) proto.Message { return acltest.GenerateTable(empty) }, + func(empty bool) proto.Message { return acltest.GenerateTokenLifetime(empty) }, + func(empty bool) proto.Message { return acltest.GenerateBearerTokenBody(empty) }, + func(empty bool) proto.Message { return acltest.GenerateBearerToken(empty) }, ) } diff --git a/acl/string.go b/acl/string.go deleted file mode 100644 index 6dab037..0000000 --- a/acl/string.go +++ /dev/null @@ -1,110 +0,0 @@ -package acl - -import ( - acl "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/acl/grpc" -) - -// String returns string representation of Action. -func (x Action) String() string { - return ActionToGRPCField(x).String() -} - -// FromString parses Action from a string representation. -// It is a reverse action to String(). -// -// Returns true if s was parsed successfully. -func (x *Action) FromString(s string) bool { - var g acl.Action - - ok := g.FromString(s) - - if ok { - *x = ActionFromGRPCField(g) - } - - return ok -} - -// String returns string representation of Role. -func (x Role) String() string { - return RoleToGRPCField(x).String() -} - -// FromString parses Role from a string representation. -// It is a reverse action to String(). -// -// Returns true if s was parsed successfully. -func (x *Role) FromString(s string) bool { - var g acl.Role - - ok := g.FromString(s) - - if ok { - *x = RoleFromGRPCField(g) - } - - return ok -} - -// String returns string representation of Operation. -func (x Operation) String() string { - return OperationToGRPCField(x).String() -} - -// FromString parses Operation from a string representation. -// It is a reverse action to String(). -// -// Returns true if s was parsed successfully. -func (x *Operation) FromString(s string) bool { - var g acl.Operation - - ok := g.FromString(s) - - if ok { - *x = OperationFromGRPCField(g) - } - - return ok -} - -// String returns string representation of MatchType. -func (x MatchType) String() string { - return MatchTypeToGRPCField(x).String() -} - -// FromString parses MatchType from a string representation. -// It is a reverse action to String(). -// -// Returns true if s was parsed successfully. -func (x *MatchType) FromString(s string) bool { - var g acl.MatchType - - ok := g.FromString(s) - - if ok { - *x = MatchTypeFromGRPCField(g) - } - - return ok -} - -// String returns string representation of HeaderType. -func (x HeaderType) String() string { - return HeaderTypeToGRPCField(x).String() -} - -// FromString parses HeaderType from a string representation. -// It is a reverse action to String(). -// -// Returns true if s was parsed successfully. -func (x *HeaderType) FromString(s string) bool { - var g acl.HeaderType - - ok := g.FromString(s) - - if ok { - *x = HeaderTypeFromGRPCField(g) - } - - return ok -} diff --git a/acl/test/generate.go b/acl/test/generate.go index 3151c52..8698784 100644 --- a/acl/test/generate.go +++ b/acl/test/generate.go @@ -1,7 +1,7 @@ package acltest import ( - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/acl" + acl "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/acl/grpc" accountingtest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs/test" ) @@ -17,24 +17,24 @@ func GenerateBearerToken(empty bool) *acl.BearerToken { return m } -func GenerateBearerTokenBody(empty bool) *acl.BearerTokenBody { - m := new(acl.BearerTokenBody) +func GenerateBearerTokenBody(empty bool) *acl.BearerToken_Body { + m := new(acl.BearerToken_Body) if !empty { - m.SetOwnerID(accountingtest.GenerateOwnerID(false)) - m.SetEACL(GenerateTable(false)) + m.SetOwnerId(accountingtest.GenerateOwnerID(false)) + m.SetEaclTable(GenerateTable(false)) m.SetLifetime(GenerateTokenLifetime(false)) } return m } -func GenerateTable(empty bool) *acl.Table { - m := new(acl.Table) +func GenerateTable(empty bool) *acl.EACLTable { + m := new(acl.EACLTable) if !empty { m.SetRecords(GenerateRecords(false)) - m.SetContainerID(accountingtest.GenerateContainerID(false)) + m.SetContainerId(accountingtest.GenerateContainerID(false)) } m.SetVersion(accountingtest.GenerateVersion(empty)) @@ -42,25 +42,25 @@ func GenerateTable(empty bool) *acl.Table { return m } -func GenerateRecords(empty bool) []acl.Record { - var rs []acl.Record +func GenerateRecords(empty bool) []*acl.EACLRecord { + var rs []*acl.EACLRecord if !empty { rs = append(rs, - *GenerateRecord(false), - *GenerateRecord(false), + GenerateRecord(false), + GenerateRecord(false), ) } return rs } -func GenerateRecord(empty bool) *acl.Record { - m := new(acl.Record) +func GenerateRecord(empty bool) *acl.EACLRecord { + m := new(acl.EACLRecord) if !empty { - m.SetAction(acl.ActionAllow) - m.SetOperation(acl.OperationGet) + m.SetAction(acl.Action_ALLOW) + m.SetOperation(acl.Operation_GET) m.SetFilters(GenerateFilters(false)) m.SetTargets(GenerateTargets(false)) } @@ -68,58 +68,58 @@ func GenerateRecord(empty bool) *acl.Record { return m } -func GenerateFilters(empty bool) []acl.HeaderFilter { - var fs []acl.HeaderFilter +func GenerateFilters(empty bool) []*acl.EACLRecord_Filter { + var fs []*acl.EACLRecord_Filter if !empty { fs = append(fs, - *GenerateFilter(false), - *GenerateFilter(false), + GenerateFilter(false), + GenerateFilter(false), ) } return fs } -func GenerateFilter(empty bool) *acl.HeaderFilter { - m := new(acl.HeaderFilter) +func GenerateFilter(empty bool) *acl.EACLRecord_Filter { + m := new(acl.EACLRecord_Filter) if !empty { m.SetKey("key") m.SetValue("val") - m.SetHeaderType(acl.HeaderTypeRequest) - m.SetMatchType(acl.MatchTypeStringEqual) + m.SetHeader(acl.HeaderType_REQUEST) + m.SetMatchType(acl.MatchType_STRING_EQUAL) } return m } -func GenerateTargets(empty bool) []acl.Target { - var ts []acl.Target +func GenerateTargets(empty bool) []*acl.EACLRecord_Target { + var ts []*acl.EACLRecord_Target if !empty { ts = append(ts, - *GenerateTarget(false), - *GenerateTarget(false), + GenerateTarget(false), + GenerateTarget(false), ) } return ts } -func GenerateTarget(empty bool) *acl.Target { - m := new(acl.Target) +func GenerateTarget(empty bool) *acl.EACLRecord_Target { + m := new(acl.EACLRecord_Target) if !empty { - m.SetRole(acl.RoleSystem) + m.SetRole(acl.Role_SYSTEM) m.SetKeys([][]byte{{1}, {2}}) } return m } -func GenerateTokenLifetime(empty bool) *acl.TokenLifetime { - m := new(acl.TokenLifetime) +func GenerateTokenLifetime(empty bool) *acl.BearerToken_Body_TokenLifetime { + m := new(acl.BearerToken_Body_TokenLifetime) if !empty { m.SetExp(1) diff --git a/acl/types.go b/acl/types.go deleted file mode 100644 index 1524e7b..0000000 --- a/acl/types.go +++ /dev/null @@ -1,379 +0,0 @@ -package acl - -import "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs" - -// HeaderFilter is a unified structure of FilterInfo -// message from proto definition. -type HeaderFilter struct { - hdrType HeaderType - - matchType MatchType - - key, value string -} - -// Target is a unified structure of Target -// message from proto definition. -type Target struct { - role Role - - keys [][]byte -} - -// Record is a unified structure of EACLRecord -// message from proto definition. -type Record struct { - op Operation - - action Action - - filters []HeaderFilter - - targets []Target -} - -// Table is a unified structure of EACLTable -// message from proto definition. -type Table struct { - version *refs.Version - - cid *refs.ContainerID - - records []Record -} - -type TokenLifetime struct { - exp, nbf, iat uint64 -} - -type BearerTokenBody struct { - eacl *Table - - ownerID *refs.OwnerID - - lifetime *TokenLifetime - - impersonate bool -} - -type BearerToken struct { - body *BearerTokenBody - - sig *refs.Signature -} - -// Target is a unified enum of MatchType enum from proto definition. -type MatchType uint32 - -// HeaderType is a unified enum of HeaderType enum from proto definition. -type HeaderType uint32 - -// Action is a unified enum of Action enum from proto definition. -type Action uint32 - -// Operation is a unified enum of Operation enum from proto definition. -type Operation uint32 - -// Role is a unified enum of Role enum from proto definition. -type Role uint32 - -const ( - MatchTypeUnknown MatchType = iota - MatchTypeStringEqual - MatchTypeStringNotEqual -) - -const ( - HeaderTypeUnknown HeaderType = iota - HeaderTypeRequest - HeaderTypeObject - HeaderTypeService -) - -const ( - ActionUnknown Action = iota - ActionAllow - ActionDeny -) - -const ( - OperationUnknown Operation = iota - OperationGet - OperationHead - OperationPut - OperationDelete - OperationSearch - OperationRange - OperationRangeHash -) - -const ( - RoleUnknown Role = iota - RoleUser - RoleSystem - RoleOthers -) - -func (f *HeaderFilter) GetHeaderType() HeaderType { - if f != nil { - return f.hdrType - } - - return HeaderTypeUnknown -} - -func (f *HeaderFilter) SetHeaderType(v HeaderType) { - f.hdrType = v -} - -func (f *HeaderFilter) GetMatchType() MatchType { - if f != nil { - return f.matchType - } - - return MatchTypeUnknown -} - -func (f *HeaderFilter) SetMatchType(v MatchType) { - f.matchType = v -} - -func (f *HeaderFilter) GetKey() string { - if f != nil { - return f.key - } - - return "" -} - -func (f *HeaderFilter) SetKey(v string) { - f.key = v -} - -func (f *HeaderFilter) GetValue() string { - if f != nil { - return f.value - } - - return "" -} - -func (f *HeaderFilter) SetValue(v string) { - f.value = v -} - -func (t *Target) GetRole() Role { - if t != nil { - return t.role - } - - return RoleUnknown -} - -func (t *Target) SetRole(v Role) { - t.role = v -} - -func (t *Target) GetKeys() [][]byte { - if t != nil { - return t.keys - } - - return nil -} - -func (t *Target) SetKeys(v [][]byte) { - t.keys = v -} - -func (r *Record) GetOperation() Operation { - if r != nil { - return r.op - } - - return OperationUnknown -} - -func (r *Record) SetOperation(v Operation) { - r.op = v -} - -func (r *Record) GetAction() Action { - if r != nil { - return r.action - } - - return ActionUnknown -} - -func (r *Record) SetAction(v Action) { - r.action = v -} - -func (r *Record) GetFilters() []HeaderFilter { - if r != nil { - return r.filters - } - - return nil -} - -func (r *Record) SetFilters(v []HeaderFilter) { - r.filters = v -} - -func (r *Record) GetTargets() []Target { - if r != nil { - return r.targets - } - - return nil -} - -func (r *Record) SetTargets(v []Target) { - r.targets = v -} - -func (t *Table) GetVersion() *refs.Version { - if t != nil { - return t.version - } - - return nil -} - -func (t *Table) SetVersion(v *refs.Version) { - t.version = v -} - -func (t *Table) GetContainerID() *refs.ContainerID { - if t != nil { - return t.cid - } - - return nil -} - -func (t *Table) SetContainerID(v *refs.ContainerID) { - t.cid = v -} - -func (t *Table) GetRecords() []Record { - if t != nil { - return t.records - } - - return nil -} - -func (t *Table) SetRecords(v []Record) { - t.records = v -} - -func (l *TokenLifetime) GetExp() uint64 { - if l != nil { - return l.exp - } - - return 0 -} - -func (l *TokenLifetime) SetExp(v uint64) { - l.exp = v -} - -func (l *TokenLifetime) GetNbf() uint64 { - if l != nil { - return l.nbf - } - - return 0 -} - -func (l *TokenLifetime) SetNbf(v uint64) { - l.nbf = v -} - -func (l *TokenLifetime) GetIat() uint64 { - if l != nil { - return l.iat - } - - return 0 -} - -func (l *TokenLifetime) SetIat(v uint64) { - l.iat = v -} - -func (bt *BearerTokenBody) GetEACL() *Table { - if bt != nil { - return bt.eacl - } - - return nil -} - -func (bt *BearerTokenBody) SetEACL(v *Table) { - bt.eacl = v -} - -func (bt *BearerTokenBody) GetOwnerID() *refs.OwnerID { - if bt != nil { - return bt.ownerID - } - - return nil -} - -func (bt *BearerTokenBody) SetOwnerID(v *refs.OwnerID) { - bt.ownerID = v -} - -func (bt *BearerTokenBody) GetLifetime() *TokenLifetime { - if bt != nil { - return bt.lifetime - } - - return nil -} - -func (bt *BearerTokenBody) SetLifetime(v *TokenLifetime) { - bt.lifetime = v -} - -func (bt *BearerTokenBody) GetImpersonate() bool { - if bt != nil { - return bt.impersonate - } - - return false -} - -func (bt *BearerTokenBody) SetImpersonate(v bool) { - bt.impersonate = v -} - -func (bt *BearerToken) GetBody() *BearerTokenBody { - if bt != nil { - return bt.body - } - - return nil -} - -func (bt *BearerToken) SetBody(v *BearerTokenBody) { - bt.body = v -} - -func (bt *BearerToken) GetSignature() *refs.Signature { - if bt != nil { - return bt.sig - } - - return nil -} - -func (bt *BearerToken) SetSignature(v *refs.Signature) { - bt.sig = v -} diff --git a/audit/convert.go b/audit/convert.go deleted file mode 100644 index a841928..0000000 --- a/audit/convert.go +++ /dev/null @@ -1,94 +0,0 @@ -package audit - -import ( - audit "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/audit/grpc" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs" - refsGRPC "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs/grpc" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/grpc" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message" -) - -func (a *DataAuditResult) ToGRPCMessage() grpc.Message { - var m *audit.DataAuditResult - - if a != nil { - m = new(audit.DataAuditResult) - - m.SetAuditEpoch(a.auditEpoch) - m.SetPublicKey(a.pubKey) - m.SetContainerId(a.cid.ToGRPCMessage().(*refsGRPC.ContainerID)) - m.SetComplete(a.complete) - m.SetVersion(a.version.ToGRPCMessage().(*refsGRPC.Version)) - m.SetPassNodes(a.passNodes) - m.SetFailNodes(a.failNodes) - m.SetRetries(a.retries) - m.SetRequests(a.requests) - m.SetHit(a.hit) - m.SetMiss(a.miss) - m.SetFail(a.fail) - m.SetPassSg(refs.ObjectIDListToGRPCMessage(a.passSG)) - m.SetFailSg(refs.ObjectIDListToGRPCMessage(a.failSG)) - } - - return m -} - -func (a *DataAuditResult) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*audit.DataAuditResult) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var err error - - cid := v.GetContainerId() - if cid == nil { - a.cid = nil - } else { - if a.cid == nil { - a.cid = new(refs.ContainerID) - } - - err = a.cid.FromGRPCMessage(cid) - if err != nil { - return err - } - } - - version := v.GetVersion() - if version == nil { - a.version = nil - } else { - if a.version == nil { - a.version = new(refs.Version) - } - - err = a.version.FromGRPCMessage(version) - if err != nil { - return err - } - } - - a.passSG, err = refs.ObjectIDListFromGRPCMessage(v.GetPassSg()) - if err != nil { - return err - } - - a.failSG, err = refs.ObjectIDListFromGRPCMessage(v.GetFailSg()) - if err != nil { - return err - } - - a.auditEpoch = v.GetAuditEpoch() - a.pubKey = v.GetPublicKey() - a.complete = v.GetComplete() - a.passNodes = v.GetPassNodes() - a.failNodes = v.GetFailNodes() - a.retries = v.GetRetries() - a.requests = v.GetRequests() - a.hit = v.GetHit() - a.miss = v.GetMiss() - a.fail = v.GetFail() - - return err -} diff --git a/audit/grpc/types.pb.go b/audit/grpc/types.pb.go index a2cac43..ef5795b 100644 Binary files a/audit/grpc/types.pb.go and b/audit/grpc/types.pb.go differ diff --git a/audit/grpc/types_frostfs.pb.go b/audit/grpc/types_frostfs.pb.go new file mode 100644 index 0000000..636aa70 Binary files /dev/null and b/audit/grpc/types_frostfs.pb.go differ diff --git a/audit/json.go b/audit/json.go deleted file mode 100644 index cbcf41f..0000000 --- a/audit/json.go +++ /dev/null @@ -1,14 +0,0 @@ -package audit - -import ( - audit "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/audit/grpc" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message" -) - -func (a *DataAuditResult) MarshalJSON() ([]byte, error) { - return message.MarshalJSON(a) -} - -func (a *DataAuditResult) UnmarshalJSON(data []byte) error { - return message.UnmarshalJSON(a, data, new(audit.DataAuditResult)) -} diff --git a/audit/marshal.go b/audit/marshal.go deleted file mode 100644 index a039baf..0000000 --- a/audit/marshal.go +++ /dev/null @@ -1,88 +0,0 @@ -package audit - -import ( - audit "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/audit/grpc" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/util/proto" -) - -const ( - _ = iota - versionFNum - auditEpochFNum - cidFNum - pubKeyFNum - completeFNum - requestsFNum - retriesFNum - passSGFNum - failSGFNum - hitFNum - missFNum - failFNum - passNodesFNum - failNodesFNum -) - -// StableMarshal marshals unified DataAuditResult structure into a protobuf -// binary format without field order shuffle. -func (a *DataAuditResult) StableMarshal(buf []byte) []byte { - if a == nil { - return []byte{} - } - - if buf == nil { - buf = make([]byte, a.StableSize()) - } - - var offset int - - offset += proto.NestedStructureMarshal(versionFNum, buf[offset:], a.version) - offset += proto.Fixed64Marshal(auditEpochFNum, buf[offset:], a.auditEpoch) - offset += proto.NestedStructureMarshal(cidFNum, buf[offset:], a.cid) - offset += proto.BytesMarshal(pubKeyFNum, buf[offset:], a.pubKey) - offset += proto.BoolMarshal(completeFNum, buf[offset:], a.complete) - offset += proto.UInt32Marshal(requestsFNum, buf[offset:], a.requests) - offset += proto.UInt32Marshal(retriesFNum, buf[offset:], a.retries) - offset += refs.ObjectIDNestedListMarshal(passSGFNum, buf[offset:], a.passSG) - offset += refs.ObjectIDNestedListMarshal(failSGFNum, buf[offset:], a.failSG) - offset += proto.UInt32Marshal(hitFNum, buf[offset:], a.hit) - offset += proto.UInt32Marshal(missFNum, buf[offset:], a.miss) - offset += proto.UInt32Marshal(failFNum, buf[offset:], a.fail) - offset += proto.RepeatedBytesMarshal(passNodesFNum, buf[offset:], a.passNodes) - proto.RepeatedBytesMarshal(failNodesFNum, buf[offset:], a.failNodes) - - return buf -} - -// StableSize returns byte length of DataAuditResult structure -// marshaled by StableMarshal function. -func (a *DataAuditResult) StableSize() (size int) { - if a == nil { - return 0 - } - - size += proto.NestedStructureSize(versionFNum, a.version) - size += proto.Fixed64Size(auditEpochFNum, a.auditEpoch) - size += proto.NestedStructureSize(cidFNum, a.cid) - size += proto.BytesSize(pubKeyFNum, a.pubKey) - size += proto.BoolSize(completeFNum, a.complete) - size += proto.UInt32Size(requestsFNum, a.requests) - size += proto.UInt32Size(retriesFNum, a.retries) - size += refs.ObjectIDNestedListSize(passSGFNum, a.passSG) - size += refs.ObjectIDNestedListSize(failSGFNum, a.failSG) - size += proto.UInt32Size(hitFNum, a.hit) - size += proto.UInt32Size(missFNum, a.miss) - size += proto.UInt32Size(failFNum, a.fail) - size += proto.RepeatedBytesSize(passNodesFNum, a.passNodes) - size += proto.RepeatedBytesSize(failNodesFNum, a.failNodes) - - return size -} - -// Unmarshal unmarshals DataAuditResult structure from its protobuf -// binary representation. -func (a *DataAuditResult) Unmarshal(data []byte) error { - return message.Unmarshal(a, data, new(audit.DataAuditResult)) -} diff --git a/audit/message_test.go b/audit/message_test.go index 02c7f78..e9a0991 100644 --- a/audit/message_test.go +++ b/audit/message_test.go @@ -4,12 +4,12 @@ import ( "testing" audittest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/audit/test" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message" messagetest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message/test" + "google.golang.org/protobuf/proto" ) func TestMessageConvert(t *testing.T) { messagetest.TestRPCMessage(t, - func(empty bool) message.Message { return audittest.GenerateDataAuditResult(empty) }, + func(empty bool) proto.Message { return audittest.GenerateDataAuditResult(empty) }, ) } diff --git a/audit/test/generate.go b/audit/test/generate.go index 093cbfe..cc3aa15 100644 --- a/audit/test/generate.go +++ b/audit/test/generate.go @@ -1,7 +1,7 @@ package audittest import ( - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/audit" + audit "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/audit/grpc" refstest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs/test" ) @@ -20,9 +20,9 @@ func GenerateDataAuditResult(empty bool) *audit.DataAuditResult { m.SetRequests(666) m.SetRetries(777) m.SetVersion(refstest.GenerateVersion(false)) - m.SetContainerID(refstest.GenerateContainerID(false)) - m.SetPassSG(refstest.GenerateObjectIDs(false)) - m.SetFailSG(refstest.GenerateObjectIDs(false)) + m.SetContainerId(refstest.GenerateContainerID(false)) + m.SetPassSg(refstest.GenerateObjectIDs(false)) + m.SetFailSg(refstest.GenerateObjectIDs(false)) } return m diff --git a/audit/types.go b/audit/types.go deleted file mode 100644 index 6f856f0..0000000 --- a/audit/types.go +++ /dev/null @@ -1,243 +0,0 @@ -package audit - -import ( - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs" -) - -// DataAuditResult is a unified structure of -// DataAuditResult message from proto definition. -type DataAuditResult struct { - version *refs.Version - - auditEpoch uint64 - - requests, retries uint32 - - hit, miss, fail uint32 - - cid *refs.ContainerID - - pubKey []byte - - passSG, failSG []refs.ObjectID - - failNodes, passNodes [][]byte - - complete bool -} - -// GetVersion returns version of Data Audit structure. -func (a *DataAuditResult) GetVersion() *refs.Version { - if a != nil { - return a.version - } - - return nil -} - -// SetVersion sets version of Data Audit structure. -func (a *DataAuditResult) SetVersion(v *refs.Version) { - a.version = v -} - -// GetAuditEpoch returns epoch number when the Data Audit was conducted. -func (a *DataAuditResult) GetAuditEpoch() uint64 { - if a != nil { - return a.auditEpoch - } - - return 0 -} - -// SetAuditEpoch sets epoch number when the Data Audit was conducted. -func (a *DataAuditResult) SetAuditEpoch(v uint64) { - a.auditEpoch = v -} - -// GetContainerID returns container under audit. -func (a *DataAuditResult) GetContainerID() *refs.ContainerID { - if a != nil { - return a.cid - } - - return nil -} - -// SetContainerID sets container under audit. -func (a *DataAuditResult) SetContainerID(v *refs.ContainerID) { - a.cid = v -} - -// GetPublicKey returns public key of the auditing InnerRing node in a binary format. -func (a *DataAuditResult) GetPublicKey() []byte { - if a != nil { - return a.pubKey - } - - return nil -} - -// SetPublicKey sets public key of the auditing InnerRing node in a binary format. -func (a *DataAuditResult) SetPublicKey(v []byte) { - a.pubKey = v -} - -// GetPassSG returns list of Storage Groups that passed audit PoR stage. -func (a *DataAuditResult) GetPassSG() []refs.ObjectID { - if a != nil { - return a.passSG - } - - return nil -} - -// SetPassSG sets list of Storage Groups that passed audit PoR stage. -func (a *DataAuditResult) SetPassSG(v []refs.ObjectID) { - a.passSG = v -} - -// GetFailSG returns list of Storage Groups that failed audit PoR stage. -func (a *DataAuditResult) GetFailSG() []refs.ObjectID { - if a != nil { - return a.failSG - } - - return nil -} - -// SetFailSG sets list of Storage Groups that failed audit PoR stage. -func (a *DataAuditResult) SetFailSG(v []refs.ObjectID) { - a.failSG = v -} - -// GetRequests returns number of requests made by PoR audit check to get -// all headers of the objects inside storage groups. -func (a *DataAuditResult) GetRequests() uint32 { - if a != nil { - return a.requests - } - - return 0 -} - -// SetRequests sets number of requests made by PoR audit check to get -// all headers of the objects inside storage groups. -func (a *DataAuditResult) SetRequests(v uint32) { - a.requests = v -} - -// GetRetries returns number of retries made by PoR audit check to get -// all headers of the objects inside storage groups. -func (a *DataAuditResult) GetRetries() uint32 { - if a != nil { - return a.retries - } - - return 0 -} - -// SetRetries sets number of retries made by PoR audit check to get -// all headers of the objects inside storage groups. -func (a *DataAuditResult) SetRetries(v uint32) { - a.retries = v -} - -// GetHit returns number of sampled objects under audit placed -// in an optimal way according to the containers placement policy -// when checking PoP. -func (a *DataAuditResult) GetHit() uint32 { - if a != nil { - return a.hit - } - - return 0 -} - -// SetHit sets number of sampled objects under audit placed -// in an optimal way according to the containers placement policy -// when checking PoP. -func (a *DataAuditResult) SetHit(v uint32) { - a.hit = v -} - -// GetMiss returns number of sampled objects under audit placed -// in suboptimal way according to the containers placement policy, -// but still at a satisfactory level when checking PoP. -func (a *DataAuditResult) GetMiss() uint32 { - if a != nil { - return a.miss - } - - return 0 -} - -// SetMiss sets number of sampled objects under audit placed -// in suboptimal way according to the containers placement policy, -// but still at a satisfactory level when checking PoP. -func (a *DataAuditResult) SetMiss(v uint32) { - a.miss = v -} - -// GetFail returns number of sampled objects under audit stored -// in a way not confirming placement policy or not found at all -// when checking PoP. -func (a *DataAuditResult) GetFail() uint32 { - if a != nil { - return a.fail - } - - return 0 -} - -// SetFail sets number of sampled objects under audit stored -// in a way not confirming placement policy or not found at all -// when checking PoP. -func (a *DataAuditResult) SetFail(v uint32) { - a.fail = v -} - -// GetPassNodes returns list of storage node public keys that -// passed at least one PDP. -func (a *DataAuditResult) GetPassNodes() [][]byte { - if a != nil { - return a.passNodes - } - - return nil -} - -// SetPassNodes sets list of storage node public keys that -// passed at least one PDP. -func (a *DataAuditResult) SetPassNodes(v [][]byte) { - a.passNodes = v -} - -// GetFailNodes returns list of storage node public keys that -// failed at least one PDP. -func (a *DataAuditResult) GetFailNodes() [][]byte { - if a != nil { - return a.failNodes - } - - return nil -} - -// SetFailNodes sets list of storage node public keys that -// failed at least one PDP. -func (a *DataAuditResult) SetFailNodes(v [][]byte) { - a.failNodes = v -} - -// GetComplete returns boolean completion statement of audit result. -func (a *DataAuditResult) GetComplete() bool { - if a != nil { - return a.complete - } - - return false // bool default -} - -// SetComplete sets boolean completion statement of audit result. -func (a *DataAuditResult) SetComplete(v bool) { - a.complete = v -} diff --git a/container/attributes_test.go b/container/attributes_test.go index fc5678c..29a6f16 100644 --- a/container/attributes_test.go +++ b/container/attributes_test.go @@ -3,7 +3,7 @@ package container_test import ( "testing" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/container" + container "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/container/grpc" containertest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/container/test" "github.com/stretchr/testify/require" ) @@ -16,7 +16,7 @@ func TestContainer_HomomorphicHashingDisabled(t *testing.T) { }) t.Run("disabled", func(t *testing.T) { - attr := container.Attribute{} + attr := new(container.Container_Attribute) attr.SetKey(container.SysAttributeHomomorphicHashing) attr.SetValue("NOT_true") @@ -25,7 +25,7 @@ func TestContainer_HomomorphicHashingDisabled(t *testing.T) { attr.SetValue("true") - cnr.SetAttributes([]container.Attribute{attr}) + cnr.SetAttributes([]*container.Container_Attribute{attr}) require.False(t, cnr.HomomorphicHashingState()) }) } diff --git a/container/convert.go b/container/convert.go deleted file mode 100644 index 0753755..0000000 --- a/container/convert.go +++ /dev/null @@ -1,1280 +0,0 @@ -package container - -import ( - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/acl" - aclGRPC "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/acl/grpc" - container "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/container/grpc" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/netmap" - netmapGRPC "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/netmap/grpc" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs" - refsGRPC "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs/grpc" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/grpc" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/session" - sessionGRPC "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/session/grpc" -) - -func (a *Attribute) ToGRPCMessage() grpc.Message { - var m *container.Container_Attribute - - if a != nil { - m = new(container.Container_Attribute) - - m.SetKey(a.key) - m.SetValue(a.val) - } - - return m -} - -func (a *Attribute) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*container.Container_Attribute) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - a.key = v.GetKey() - a.val = v.GetValue() - - return nil -} - -func AttributesToGRPC(xs []Attribute) (res []*container.Container_Attribute) { - if xs != nil { - res = make([]*container.Container_Attribute, 0, len(xs)) - - for i := range xs { - res = append(res, xs[i].ToGRPCMessage().(*container.Container_Attribute)) - } - } - - return -} - -func AttributesFromGRPC(xs []*container.Container_Attribute) (res []Attribute, err error) { - if xs != nil { - res = make([]Attribute, len(xs)) - - for i := range xs { - if xs[i] != nil { - err = res[i].FromGRPCMessage(xs[i]) - if err != nil { - return - } - } - } - } - - return -} - -func (c *Container) ToGRPCMessage() grpc.Message { - var m *container.Container - - if c != nil { - m = new(container.Container) - - m.SetVersion(c.version.ToGRPCMessage().(*refsGRPC.Version)) - m.SetOwnerId(c.ownerID.ToGRPCMessage().(*refsGRPC.OwnerID)) - m.SetPlacementPolicy(c.policy.ToGRPCMessage().(*netmapGRPC.PlacementPolicy)) - m.SetAttributes(AttributesToGRPC(c.attr)) - m.SetBasicAcl(c.basicACL) - m.SetNonce(c.nonce) - } - - return m -} - -func (c *Container) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*container.Container) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var err error - - version := v.GetVersion() - if version == nil { - c.version = nil - } else { - if c.version == nil { - c.version = new(refs.Version) - } - - err = c.version.FromGRPCMessage(version) - if err != nil { - return err - } - } - - ownerID := v.GetOwnerId() - if ownerID == nil { - c.ownerID = nil - } else { - if c.ownerID == nil { - c.ownerID = new(refs.OwnerID) - } - - err = c.ownerID.FromGRPCMessage(ownerID) - if err != nil { - return err - } - } - - policy := v.GetPlacementPolicy() - if policy == nil { - c.policy = nil - } else { - if c.policy == nil { - c.policy = new(netmap.PlacementPolicy) - } - - err = c.policy.FromGRPCMessage(policy) - if err != nil { - return err - } - } - - c.attr, err = AttributesFromGRPC(v.GetAttributes()) - if err != nil { - return err - } - - c.basicACL = v.GetBasicAcl() - c.nonce = v.GetNonce() - - return nil -} - -func toSignatureRFC6979(s *refs.Signature) *refsGRPC.SignatureRFC6979 { - var res *refsGRPC.SignatureRFC6979 - - if s != nil { - res = new(refsGRPC.SignatureRFC6979) - res.SetKey(s.GetKey()) - res.SetSign(s.GetSign()) - } - - return res -} - -func (r *PutRequestBody) ToGRPCMessage() grpc.Message { - var m *container.PutRequest_Body - - if r != nil { - m = new(container.PutRequest_Body) - - m.SetContainer(r.cnr.ToGRPCMessage().(*container.Container)) - m.SetSignature(toSignatureRFC6979(r.sig)) - } - - return m -} - -func (r *PutRequestBody) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*container.PutRequest_Body) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var err error - - cnr := v.GetContainer() - if cnr == nil { - r.cnr = nil - } else { - if r.cnr == nil { - r.cnr = new(Container) - } - - err = r.cnr.FromGRPCMessage(cnr) - if err != nil { - return err - } - } - - sig := v.GetSignature() - if sig == nil { - r.sig = nil - } else { - if r.sig == nil { - r.sig = new(refs.Signature) - } - - r.sig.SetKey(sig.GetKey()) - r.sig.SetSign(sig.GetSign()) - } - - return err -} - -func (r *PutRequest) ToGRPCMessage() grpc.Message { - var m *container.PutRequest - - if r != nil { - m = new(container.PutRequest) - - m.SetBody(r.body.ToGRPCMessage().(*container.PutRequest_Body)) - r.RequestHeaders.ToMessage(m) - } - - return m -} - -func (r *PutRequest) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*container.PutRequest) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var err error - - body := v.GetBody() - if body == nil { - r.body = nil - } else { - if r.body == nil { - r.body = new(PutRequestBody) - } - - err = r.body.FromGRPCMessage(body) - if err != nil { - return err - } - } - - return r.RequestHeaders.FromMessage(v) -} - -func (r *PutResponseBody) ToGRPCMessage() grpc.Message { - var m *container.PutResponse_Body - - if r != nil { - m = new(container.PutResponse_Body) - - m.SetContainerId(r.cid.ToGRPCMessage().(*refsGRPC.ContainerID)) - } - - return m -} - -func (r *PutResponseBody) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*container.PutResponse_Body) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var err error - - cid := v.GetContainerId() - if cid == nil { - r.cid = nil - } else { - if r.cid == nil { - r.cid = new(refs.ContainerID) - } - - err = r.cid.FromGRPCMessage(cid) - } - - return err -} - -func (r *PutResponse) ToGRPCMessage() grpc.Message { - var m *container.PutResponse - - if r != nil { - m = new(container.PutResponse) - - m.SetBody(r.body.ToGRPCMessage().(*container.PutResponse_Body)) - r.ResponseHeaders.ToMessage(m) - } - - return m -} - -func (r *PutResponse) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*container.PutResponse) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var err error - - body := v.GetBody() - if body == nil { - r.body = nil - } else { - if r.body == nil { - r.body = new(PutResponseBody) - } - - err = r.body.FromGRPCMessage(body) - if err != nil { - return err - } - } - - return r.ResponseHeaders.FromMessage(v) -} - -func (r *GetRequestBody) ToGRPCMessage() grpc.Message { - var m *container.GetRequest_Body - - if r != nil { - m = new(container.GetRequest_Body) - - m.SetContainerId(r.cid.ToGRPCMessage().(*refsGRPC.ContainerID)) - } - - return m -} - -func (r *GetRequestBody) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*container.GetRequest_Body) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var err error - - cid := v.GetContainerId() - if cid == nil { - r.cid = nil - } else { - if r.cid == nil { - r.cid = new(refs.ContainerID) - } - - err = r.cid.FromGRPCMessage(cid) - } - - return err -} - -func (r *GetRequest) ToGRPCMessage() grpc.Message { - var m *container.GetRequest - - if r != nil { - m = new(container.GetRequest) - - m.SetBody(r.body.ToGRPCMessage().(*container.GetRequest_Body)) - r.RequestHeaders.ToMessage(m) - } - - return m -} - -func (r *GetRequest) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*container.GetRequest) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var err error - - body := v.GetBody() - if body == nil { - r.body = nil - } else { - if r.body == nil { - r.body = new(GetRequestBody) - } - - err = r.body.FromGRPCMessage(body) - if err != nil { - return err - } - } - - return r.RequestHeaders.FromMessage(v) -} - -func (r *GetResponseBody) ToGRPCMessage() grpc.Message { - var m *container.GetResponse_Body - - if r != nil { - m = new(container.GetResponse_Body) - - m.SetContainer(r.cnr.ToGRPCMessage().(*container.Container)) - m.SetSessionToken(r.token.ToGRPCMessage().(*sessionGRPC.SessionToken)) - m.SetSignature(toSignatureRFC6979(r.sig)) - } - - return m -} - -func (r *GetResponseBody) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*container.GetResponse_Body) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var err error - - cnr := v.GetContainer() - if cnr == nil { - r.cnr = nil - } else { - if r.cnr == nil { - r.cnr = new(Container) - } - - err = r.cnr.FromGRPCMessage(cnr) - } - - sig := v.GetSignature() - if sig == nil { - r.sig = nil - } else { - if r.sig == nil { - r.sig = new(refs.Signature) - } - - r.sig.SetKey(sig.GetKey()) - r.sig.SetSign(sig.GetSign()) - } - - token := v.GetSessionToken() - if token == nil { - r.token = nil - } else { - if r.token == nil { - r.token = new(session.Token) - } - - err = r.token.FromGRPCMessage(token) - } - - return err -} - -func (r *GetResponse) ToGRPCMessage() grpc.Message { - var m *container.GetResponse - - if r != nil { - m = new(container.GetResponse) - - m.SetBody(r.body.ToGRPCMessage().(*container.GetResponse_Body)) - r.ResponseHeaders.ToMessage(m) - } - - return m -} - -func (r *GetResponse) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*container.GetResponse) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var err error - - body := v.GetBody() - if body == nil { - r.body = nil - } else { - if r.body == nil { - r.body = new(GetResponseBody) - } - - err = r.body.FromGRPCMessage(body) - if err != nil { - return err - } - } - - return r.ResponseHeaders.FromMessage(v) -} - -func (r *DeleteRequestBody) ToGRPCMessage() grpc.Message { - var m *container.DeleteRequest_Body - - if r != nil { - m = new(container.DeleteRequest_Body) - - m.SetContainerId(r.cid.ToGRPCMessage().(*refsGRPC.ContainerID)) - m.SetSignature(toSignatureRFC6979(r.sig)) - } - - return m -} - -func (r *DeleteRequestBody) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*container.DeleteRequest_Body) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var err error - - cid := v.GetContainerId() - if cid == nil { - r.cid = nil - } else { - if r.cid == nil { - r.cid = new(refs.ContainerID) - } - - err = r.cid.FromGRPCMessage(cid) - if err != nil { - return err - } - } - - sig := v.GetSignature() - if sig == nil { - r.sig = nil - } else { - if r.sig == nil { - r.sig = new(refs.Signature) - } - - r.sig.SetKey(sig.GetKey()) - r.sig.SetSign(sig.GetSign()) - } - - return err -} - -func (r *DeleteRequest) ToGRPCMessage() grpc.Message { - var m *container.DeleteRequest - - if r != nil { - m = new(container.DeleteRequest) - - m.SetBody(r.body.ToGRPCMessage().(*container.DeleteRequest_Body)) - r.RequestHeaders.ToMessage(m) - } - - return m -} - -func (r *DeleteRequest) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*container.DeleteRequest) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var err error - - body := v.GetBody() - if body == nil { - r.body = nil - } else { - if r.body == nil { - r.body = new(DeleteRequestBody) - } - - err = r.body.FromGRPCMessage(body) - if err != nil { - return err - } - } - - return r.RequestHeaders.FromMessage(v) -} - -func (r *DeleteResponseBody) ToGRPCMessage() grpc.Message { - var m *container.DeleteResponse_Body - - if r != nil { - m = new(container.DeleteResponse_Body) - } - - return m -} - -func (r *DeleteResponseBody) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*container.DeleteResponse_Body) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - return nil -} - -func (r *DeleteResponse) ToGRPCMessage() grpc.Message { - var m *container.DeleteResponse - - if r != nil { - m = new(container.DeleteResponse) - - m.SetBody(r.body.ToGRPCMessage().(*container.DeleteResponse_Body)) - r.ResponseHeaders.ToMessage(m) - } - - return m -} - -func (r *DeleteResponse) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*container.DeleteResponse) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var err error - - body := v.GetBody() - if body == nil { - r.body = nil - } else { - if r.body == nil { - r.body = new(DeleteResponseBody) - } - - err = r.body.FromGRPCMessage(body) - if err != nil { - return err - } - } - - return r.ResponseHeaders.FromMessage(v) -} - -func (r *ListRequestBody) ToGRPCMessage() grpc.Message { - var m *container.ListRequest_Body - - if r != nil { - m = new(container.ListRequest_Body) - - m.SetOwnerId(r.ownerID.ToGRPCMessage().(*refsGRPC.OwnerID)) - } - - return m -} - -func (r *ListRequestBody) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*container.ListRequest_Body) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var err error - - ownerID := v.GetOwnerId() - if ownerID == nil { - r.ownerID = nil - } else { - if r.ownerID == nil { - r.ownerID = new(refs.OwnerID) - } - - err = r.ownerID.FromGRPCMessage(ownerID) - } - - return err -} - -func (r *ListRequest) ToGRPCMessage() grpc.Message { - var m *container.ListRequest - - if r != nil { - m = new(container.ListRequest) - - m.SetBody(r.body.ToGRPCMessage().(*container.ListRequest_Body)) - r.RequestHeaders.ToMessage(m) - } - - return m -} - -func (r *ListRequest) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*container.ListRequest) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var err error - - body := v.GetBody() - if body == nil { - r.body = nil - } else { - if r.body == nil { - r.body = new(ListRequestBody) - } - - err = r.body.FromGRPCMessage(body) - if err != nil { - return err - } - } - - return r.RequestHeaders.FromMessage(v) -} - -func (r *ListResponseBody) ToGRPCMessage() grpc.Message { - var m *container.ListResponse_Body - - if r != nil { - m = new(container.ListResponse_Body) - - m.SetContainerIds(refs.ContainerIDsToGRPCMessage(r.cidList)) - } - - return m -} - -func (r *ListResponseBody) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*container.ListResponse_Body) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var err error - - r.cidList, err = refs.ContainerIDsFromGRPCMessage(v.GetContainerIds()) - - return err -} - -func (r *ListResponse) ToGRPCMessage() grpc.Message { - var m *container.ListResponse - - if r != nil { - m = new(container.ListResponse) - - m.SetBody(r.body.ToGRPCMessage().(*container.ListResponse_Body)) - r.ResponseHeaders.ToMessage(m) - } - - return m -} - -func (r *ListResponse) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*container.ListResponse) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var err error - - body := v.GetBody() - if body == nil { - r.body = nil - } else { - if r.body == nil { - r.body = new(ListResponseBody) - } - - err = r.body.FromGRPCMessage(body) - if err != nil { - return err - } - } - - return r.ResponseHeaders.FromMessage(v) -} - -func (r *SetExtendedACLRequestBody) ToGRPCMessage() grpc.Message { - var m *container.SetExtendedACLRequest_Body - - if r != nil { - m = new(container.SetExtendedACLRequest_Body) - - m.SetEacl(r.eacl.ToGRPCMessage().(*aclGRPC.EACLTable)) - m.SetSignature(toSignatureRFC6979(r.sig)) - } - - return m -} - -func (r *SetExtendedACLRequestBody) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*container.SetExtendedACLRequest_Body) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var err error - - eacl := v.GetEacl() - if eacl == nil { - r.eacl = nil - } else { - if r.eacl == nil { - r.eacl = new(acl.Table) - } - - err = r.eacl.FromGRPCMessage(eacl) - if err != nil { - return err - } - } - - sig := v.GetSignature() - if sig == nil { - r.sig = nil - } else { - if r.sig == nil { - r.sig = new(refs.Signature) - } - - r.sig.SetKey(sig.GetKey()) - r.sig.SetSign(sig.GetSign()) - } - - return err -} - -func (r *SetExtendedACLRequest) ToGRPCMessage() grpc.Message { - var m *container.SetExtendedACLRequest - - if r != nil { - m = new(container.SetExtendedACLRequest) - - m.SetBody(r.body.ToGRPCMessage().(*container.SetExtendedACLRequest_Body)) - r.RequestHeaders.ToMessage(m) - } - - return m -} - -func (r *SetExtendedACLRequest) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*container.SetExtendedACLRequest) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var err error - - body := v.GetBody() - if body == nil { - r.body = nil - } else { - if r.body == nil { - r.body = new(SetExtendedACLRequestBody) - } - - err = r.body.FromGRPCMessage(body) - if err != nil { - return err - } - } - - return r.RequestHeaders.FromMessage(v) -} - -func (r *SetExtendedACLResponseBody) ToGRPCMessage() grpc.Message { - var m *container.SetExtendedACLResponse_Body - - if r != nil { - m = new(container.SetExtendedACLResponse_Body) - } - - return m -} - -func (r *SetExtendedACLResponseBody) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*container.SetExtendedACLResponse_Body) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - return nil -} - -func (r *SetExtendedACLResponse) ToGRPCMessage() grpc.Message { - var m *container.SetExtendedACLResponse - - if r != nil { - m = new(container.SetExtendedACLResponse) - - m.SetBody(r.body.ToGRPCMessage().(*container.SetExtendedACLResponse_Body)) - r.ResponseHeaders.ToMessage(m) - } - - return m -} - -func (r *SetExtendedACLResponse) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*container.SetExtendedACLResponse) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var err error - - body := v.GetBody() - if body == nil { - r.body = nil - } else { - if r.body == nil { - r.body = new(SetExtendedACLResponseBody) - } - - err = r.body.FromGRPCMessage(body) - if err != nil { - return err - } - } - - return r.ResponseHeaders.FromMessage(v) -} - -func (r *GetExtendedACLRequestBody) ToGRPCMessage() grpc.Message { - var m *container.GetExtendedACLRequest_Body - - if r != nil { - m = new(container.GetExtendedACLRequest_Body) - - m.SetContainerId(r.cid.ToGRPCMessage().(*refsGRPC.ContainerID)) - } - - return m -} - -func (r *GetExtendedACLRequestBody) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*container.GetExtendedACLRequest_Body) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var err error - - cid := v.GetContainerId() - if cid == nil { - r.cid = nil - } else { - if r.cid == nil { - r.cid = new(refs.ContainerID) - } - - err = r.cid.FromGRPCMessage(cid) - } - - return err -} - -func (r *GetExtendedACLRequest) ToGRPCMessage() grpc.Message { - var m *container.GetExtendedACLRequest - - if r != nil { - m = new(container.GetExtendedACLRequest) - - m.SetBody(r.body.ToGRPCMessage().(*container.GetExtendedACLRequest_Body)) - r.RequestHeaders.ToMessage(m) - } - - return m -} - -func (r *GetExtendedACLRequest) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*container.GetExtendedACLRequest) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var err error - - body := v.GetBody() - if body == nil { - r.body = nil - } else { - if r.body == nil { - r.body = new(GetExtendedACLRequestBody) - } - - err = r.body.FromGRPCMessage(body) - if err != nil { - return err - } - } - - return r.RequestHeaders.FromMessage(v) -} - -func (r *GetExtendedACLResponseBody) ToGRPCMessage() grpc.Message { - var m *container.GetExtendedACLResponse_Body - - if r != nil { - m = new(container.GetExtendedACLResponse_Body) - - m.SetEacl(r.eacl.ToGRPCMessage().(*aclGRPC.EACLTable)) - m.SetSignature(toSignatureRFC6979(r.sig)) - m.SetSessionToken(r.token.ToGRPCMessage().(*sessionGRPC.SessionToken)) - } - - return m -} - -func (r *GetExtendedACLResponseBody) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*container.GetExtendedACLResponse_Body) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var err error - - eacl := v.GetEacl() - if eacl == nil { - r.eacl = nil - } else { - if r.eacl == nil { - r.eacl = new(acl.Table) - } - - err = r.eacl.FromGRPCMessage(eacl) - if err != nil { - return err - } - } - - sig := v.GetSignature() - if sig == nil { - r.sig = nil - } else { - if r.sig == nil { - r.sig = new(refs.Signature) - } - - r.sig.SetKey(sig.GetKey()) - r.sig.SetSign(sig.GetSign()) - } - - token := v.GetSessionToken() - if token == nil { - r.token = nil - } else { - if r.token == nil { - r.token = new(session.Token) - } - - err = r.token.FromGRPCMessage(token) - } - - return err -} - -func (r *GetExtendedACLResponse) ToGRPCMessage() grpc.Message { - var m *container.GetExtendedACLResponse - - if r != nil { - m = new(container.GetExtendedACLResponse) - - m.SetBody(r.body.ToGRPCMessage().(*container.GetExtendedACLResponse_Body)) - r.ResponseHeaders.ToMessage(m) - } - - return m -} - -func (r *GetExtendedACLResponse) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*container.GetExtendedACLResponse) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var err error - - body := v.GetBody() - if body == nil { - r.body = nil - } else { - if r.body == nil { - r.body = new(GetExtendedACLResponseBody) - } - - err = r.body.FromGRPCMessage(body) - if err != nil { - return err - } - } - - return r.ResponseHeaders.FromMessage(v) -} - -func (a *UsedSpaceAnnouncement) ToGRPCMessage() grpc.Message { - var m *container.AnnounceUsedSpaceRequest_Body_Announcement - - if a != nil { - m = new(container.AnnounceUsedSpaceRequest_Body_Announcement) - - m.SetContainerId(a.cid.ToGRPCMessage().(*refsGRPC.ContainerID)) - m.SetEpoch(a.epoch) - m.SetUsedSpace(a.usedSpace) - } - - return m -} - -func (a *UsedSpaceAnnouncement) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*container.AnnounceUsedSpaceRequest_Body_Announcement) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var err error - - cid := v.GetContainerId() - if cid == nil { - a.cid = nil - } else { - if a.cid == nil { - a.cid = new(refs.ContainerID) - } - - err = a.cid.FromGRPCMessage(cid) - if err != nil { - return err - } - } - - a.epoch = v.GetEpoch() - a.usedSpace = v.GetUsedSpace() - - return nil -} - -func UsedSpaceAnnouncementsToGRPCMessage( - ids []UsedSpaceAnnouncement, -) (res []*container.AnnounceUsedSpaceRequest_Body_Announcement) { - if ids != nil { - res = make([]*container.AnnounceUsedSpaceRequest_Body_Announcement, 0, len(ids)) - - for i := range ids { - res = append(res, ids[i].ToGRPCMessage().(*container.AnnounceUsedSpaceRequest_Body_Announcement)) - } - } - - return -} - -func UsedSpaceAnnouncementssFromGRPCMessage( - asV2 []*container.AnnounceUsedSpaceRequest_Body_Announcement, -) (res []UsedSpaceAnnouncement, err error) { - if asV2 != nil { - res = make([]UsedSpaceAnnouncement, len(asV2)) - - for i := range asV2 { - if asV2[i] != nil { - err = res[i].FromGRPCMessage(asV2[i]) - if err != nil { - return - } - } - } - } - - return -} - -func (r *AnnounceUsedSpaceRequestBody) ToGRPCMessage() grpc.Message { - var m *container.AnnounceUsedSpaceRequest_Body - - if r != nil { - m = new(container.AnnounceUsedSpaceRequest_Body) - - m.SetAnnouncements(UsedSpaceAnnouncementsToGRPCMessage(r.announcements)) - } - - return m -} - -func (r *AnnounceUsedSpaceRequestBody) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*container.AnnounceUsedSpaceRequest_Body) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var err error - - r.announcements, err = UsedSpaceAnnouncementssFromGRPCMessage(v.GetAnnouncements()) - - return err -} - -func (r *AnnounceUsedSpaceRequest) ToGRPCMessage() grpc.Message { - var m *container.AnnounceUsedSpaceRequest - - if r != nil { - m = new(container.AnnounceUsedSpaceRequest) - - m.SetBody(r.body.ToGRPCMessage().(*container.AnnounceUsedSpaceRequest_Body)) - r.RequestHeaders.ToMessage(m) - } - - return m -} - -func (r *AnnounceUsedSpaceRequest) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*container.AnnounceUsedSpaceRequest) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var err error - - body := v.GetBody() - if body == nil { - r.body = nil - } else { - if r.body == nil { - r.body = new(AnnounceUsedSpaceRequestBody) - } - - err = r.body.FromGRPCMessage(body) - if err != nil { - return err - } - } - - return r.RequestHeaders.FromMessage(v) -} - -func (r *AnnounceUsedSpaceResponseBody) ToGRPCMessage() grpc.Message { - var m *container.AnnounceUsedSpaceResponse_Body - - if r != nil { - m = new(container.AnnounceUsedSpaceResponse_Body) - } - - return m -} - -func (r *AnnounceUsedSpaceResponseBody) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*container.AnnounceUsedSpaceResponse_Body) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - return nil -} - -func (r *AnnounceUsedSpaceResponse) ToGRPCMessage() grpc.Message { - var m *container.AnnounceUsedSpaceResponse - - if r != nil { - m = new(container.AnnounceUsedSpaceResponse) - - m.SetBody(r.body.ToGRPCMessage().(*container.AnnounceUsedSpaceResponse_Body)) - r.ResponseHeaders.ToMessage(m) - } - - return m -} - -func (r *AnnounceUsedSpaceResponse) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*container.AnnounceUsedSpaceResponse) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var err error - - body := v.GetBody() - if body == nil { - r.body = nil - } else { - if r.body == nil { - r.body = new(AnnounceUsedSpaceResponseBody) - } - - err = r.body.FromGRPCMessage(body) - if err != nil { - return err - } - } - - return r.ResponseHeaders.FromMessage(v) -} diff --git a/container/attributes.go b/container/grpc/attributes.go similarity index 77% rename from container/attributes.go rename to container/grpc/attributes.go index 288d048..b55870f 100644 --- a/container/attributes.go +++ b/container/grpc/attributes.go @@ -46,10 +46,10 @@ const disabledHomomorphicHashingValue = "true" // is undefined. // // See also SetHomomorphicHashingState. -func (c Container) HomomorphicHashingState() bool { - for i := range c.attr { - if c.attr[i].GetKey() == SysAttributeHomomorphicHashing || c.attr[i].GetKey() == SysAttributeHomomorphicHashingNeoFS { - return c.attr[i].GetValue() != disabledHomomorphicHashingValue +func (c *Container) HomomorphicHashingState() bool { + for i := range c.Attributes { + if c.Attributes[i].GetKey() == SysAttributeHomomorphicHashing || c.Attributes[i].GetKey() == SysAttributeHomomorphicHashingNeoFS { + return c.Attributes[i].GetValue() != disabledHomomorphicHashingValue } } @@ -64,16 +64,17 @@ func (c Container) HomomorphicHashingState() bool { // // See also HomomorphicHashingState. func (c *Container) SetHomomorphicHashingState(enable bool) { - for i := range c.attr { - if c.attr[i].GetKey() == SysAttributeHomomorphicHashing || c.attr[i].GetKey() == SysAttributeHomomorphicHashingNeoFS { + attributes := c.GetAttributes() + for _, attr := range attributes { + if attr.GetKey() == SysAttributeHomomorphicHashing || attr.GetKey() == SysAttributeHomomorphicHashingNeoFS { if enable { // approach without allocation/waste // coping works since the attributes // order is not important - c.attr[i] = c.attr[len(c.attr)-1] - c.attr = c.attr[:len(c.attr)-1] + attr = attributes[len(attributes)-1] + c.SetAttributes(attributes[:len(attributes)-1]) } else { - c.attr[i].SetValue(disabledHomomorphicHashingValue) + attr.SetValue(disabledHomomorphicHashingValue) } return @@ -81,10 +82,10 @@ func (c *Container) SetHomomorphicHashingState(enable bool) { } if !enable { - attr := Attribute{} + attr := new(Container_Attribute) attr.SetKey(SysAttributeHomomorphicHashing) attr.SetValue(disabledHomomorphicHashingValue) - c.attr = append(c.attr, attr) + c.SetAttributes(append(c.Attributes, attr)) } } diff --git a/container/grpc/service.pb.go b/container/grpc/service.pb.go index e3bdaf0..c2f4e5f 100644 Binary files a/container/grpc/service.pb.go and b/container/grpc/service.pb.go differ diff --git a/container/grpc/service_frostfs.pb.go b/container/grpc/service_frostfs.pb.go new file mode 100644 index 0000000..13dd0be Binary files /dev/null and b/container/grpc/service_frostfs.pb.go differ diff --git a/container/grpc/service_grpc.pb.go b/container/grpc/service_grpc.pb.go index c70bce7..7d4888f 100644 Binary files a/container/grpc/service_grpc.pb.go and b/container/grpc/service_grpc.pb.go differ diff --git a/container/grpc/types.pb.go b/container/grpc/types.pb.go index 0cd53eb..9634ff7 100644 Binary files a/container/grpc/types.pb.go and b/container/grpc/types.pb.go differ diff --git a/container/grpc/types_frostfs.pb.go b/container/grpc/types_frostfs.pb.go new file mode 100644 index 0000000..bc7e62b Binary files /dev/null and b/container/grpc/types_frostfs.pb.go differ diff --git a/container/json.go b/container/json.go deleted file mode 100644 index d9fc4f6..0000000 --- a/container/json.go +++ /dev/null @@ -1,22 +0,0 @@ -package container - -import ( - container "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/container/grpc" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message" -) - -func (a *Attribute) MarshalJSON() ([]byte, error) { - return message.MarshalJSON(a) -} - -func (a *Attribute) UnmarshalJSON(data []byte) error { - return message.UnmarshalJSON(a, data, new(container.Container_Attribute)) -} - -func (c *Container) MarshalJSON() ([]byte, error) { - return message.MarshalJSON(c) -} - -func (c *Container) UnmarshalJSON(data []byte) error { - return message.UnmarshalJSON(c, data, new(container.Container)) -} diff --git a/container/marshal.go b/container/marshal.go deleted file mode 100644 index a7c57aa..0000000 --- a/container/marshal.go +++ /dev/null @@ -1,546 +0,0 @@ -package container - -import ( - container "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/container/grpc" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message" - protoutil "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/util/proto" -) - -const ( - attributeKeyField = 1 - attributeValueField = 2 - - containerVersionField = 1 - containerOwnerField = 2 - containerNonceField = 3 - containerBasicACLField = 4 - containerAttributesField = 5 - containerPlacementField = 6 - - putReqBodyContainerField = 1 - putReqBodySignatureField = 2 - - putRespBodyIDField = 1 - - deleteReqBodyIDField = 1 - deleteReqBodySignatureField = 2 - - getReqBodyIDField = 1 - - getRespBodyContainerField = 1 - getRespBodySignatureField = 2 - getRespBodyTokenField = 3 - - listReqBodyOwnerField = 1 - - listRespBodyIDsField = 1 - - setEACLReqBodyTableField = 1 - setEACLReqBodySignatureField = 2 - - getEACLReqBodyIDField = 1 - - getEACLRespBodyTableField = 1 - getEACLRespBodySignatureField = 2 - getEACLRespBodyTokenField = 3 - - usedSpaceAnnounceEpochField = 1 - usedSpaceAnnounceCIDField = 2 - usedSpaceAnnounceUsedSpaceField = 3 - - usedSpaceReqBodyAnnouncementsField = 1 -) - -func (a *Attribute) StableMarshal(buf []byte) []byte { - if a == nil { - return []byte{} - } - - if buf == nil { - buf = make([]byte, a.StableSize()) - } - - var offset int - - offset += protoutil.StringMarshal(attributeKeyField, buf[offset:], a.key) - protoutil.StringMarshal(attributeValueField, buf[offset:], a.val) - - return buf -} - -func (a *Attribute) StableSize() (size int) { - if a == nil { - return 0 - } - - size += protoutil.StringSize(attributeKeyField, a.key) - size += protoutil.StringSize(attributeValueField, a.val) - - return size -} - -func (a *Attribute) Unmarshal(data []byte) error { - return message.Unmarshal(a, data, new(container.Container_Attribute)) -} - -func (c *Container) StableMarshal(buf []byte) []byte { - if c == nil { - return []byte{} - } - - if buf == nil { - buf = make([]byte, c.StableSize()) - } - - var offset int - - offset += protoutil.NestedStructureMarshal(containerVersionField, buf[offset:], c.version) - offset += protoutil.NestedStructureMarshal(containerOwnerField, buf[offset:], c.ownerID) - offset += protoutil.BytesMarshal(containerNonceField, buf[offset:], c.nonce) - offset += protoutil.UInt32Marshal(containerBasicACLField, buf[offset:], c.basicACL) - - for i := range c.attr { - offset += protoutil.NestedStructureMarshal(containerAttributesField, buf[offset:], &c.attr[i]) - } - - protoutil.NestedStructureMarshal(containerPlacementField, buf[offset:], c.policy) - - return buf -} - -func (c *Container) StableSize() (size int) { - if c == nil { - return 0 - } - - size += protoutil.NestedStructureSize(containerVersionField, c.version) - size += protoutil.NestedStructureSize(containerOwnerField, c.ownerID) - size += protoutil.BytesSize(containerNonceField, c.nonce) - size += protoutil.UInt32Size(containerBasicACLField, c.basicACL) - - for i := range c.attr { - size += protoutil.NestedStructureSize(containerAttributesField, &c.attr[i]) - } - - size += protoutil.NestedStructureSize(containerPlacementField, c.policy) - - return size -} - -func (c *Container) Unmarshal(data []byte) error { - return message.Unmarshal(c, data, new(container.Container)) -} - -func (r *PutRequestBody) StableMarshal(buf []byte) []byte { - if r == nil { - return []byte{} - } - - if buf == nil { - buf = make([]byte, r.StableSize()) - } - - var offset int - - offset += protoutil.NestedStructureMarshal(putReqBodyContainerField, buf[offset:], r.cnr) - protoutil.NestedStructureMarshal(putReqBodySignatureField, buf[offset:], r.sig) - - return buf -} - -func (r *PutRequestBody) StableSize() (size int) { - if r == nil { - return 0 - } - - size += protoutil.NestedStructureSize(putReqBodyContainerField, r.cnr) - size += protoutil.NestedStructureSize(putReqBodySignatureField, r.sig) - - return size -} - -func (r *PutRequestBody) Unmarshal(data []byte) error { - return message.Unmarshal(r, data, new(container.PutRequest_Body)) -} - -func (r *PutResponseBody) StableMarshal(buf []byte) []byte { - if r == nil { - return []byte{} - } - - if buf == nil { - buf = make([]byte, r.StableSize()) - } - - protoutil.NestedStructureMarshal(putRespBodyIDField, buf, r.cid) - - return buf -} - -func (r *PutResponseBody) StableSize() (size int) { - if r == nil { - return 0 - } - - size += protoutil.NestedStructureSize(putRespBodyIDField, r.cid) - - return size -} - -func (r *PutResponseBody) Unmarshal(data []byte) error { - return message.Unmarshal(r, data, new(container.PutResponse_Body)) -} - -func (r *DeleteRequestBody) StableMarshal(buf []byte) []byte { - if r == nil { - return []byte{} - } - - if buf == nil { - buf = make([]byte, r.StableSize()) - } - - var offset int - - offset += protoutil.NestedStructureMarshal(deleteReqBodyIDField, buf[offset:], r.cid) - protoutil.NestedStructureMarshal(deleteReqBodySignatureField, buf[offset:], r.sig) - - return buf -} - -func (r *DeleteRequestBody) StableSize() (size int) { - if r == nil { - return 0 - } - - size += protoutil.NestedStructureSize(deleteReqBodyIDField, r.cid) - size += protoutil.NestedStructureSize(deleteReqBodySignatureField, r.sig) - - return size -} - -func (r *DeleteRequestBody) Unmarshal(data []byte) error { - return message.Unmarshal(r, data, new(container.DeleteRequest_Body)) -} - -func (r *DeleteResponseBody) StableMarshal(_ []byte) []byte { - return nil -} - -func (r *DeleteResponseBody) StableSize() (size int) { - return 0 -} - -func (r *DeleteResponseBody) Unmarshal([]byte) error { - return nil -} - -func (r *GetRequestBody) StableMarshal(buf []byte) []byte { - if r == nil { - return []byte{} - } - - if buf == nil { - buf = make([]byte, r.StableSize()) - } - - protoutil.NestedStructureMarshal(getReqBodyIDField, buf, r.cid) - - return buf -} - -func (r *GetRequestBody) StableSize() (size int) { - if r == nil { - return 0 - } - - size += protoutil.NestedStructureSize(getReqBodyIDField, r.cid) - - return size -} - -func (r *GetRequestBody) Unmarshal(data []byte) error { - return message.Unmarshal(r, data, new(container.GetRequest_Body)) -} - -func (r *GetResponseBody) StableMarshal(buf []byte) []byte { - if r == nil { - return []byte{} - } - - if buf == nil { - buf = make([]byte, r.StableSize()) - } - - var offset int - - offset += protoutil.NestedStructureMarshal(getRespBodyContainerField, buf, r.cnr) - offset += protoutil.NestedStructureMarshal(getRespBodySignatureField, buf[offset:], r.sig) - protoutil.NestedStructureMarshal(getRespBodyTokenField, buf[offset:], r.token) - - return buf -} - -func (r *GetResponseBody) StableSize() (size int) { - if r == nil { - return 0 - } - - size += protoutil.NestedStructureSize(getRespBodyContainerField, r.cnr) - size += protoutil.NestedStructureSize(getRespBodySignatureField, r.sig) - size += protoutil.NestedStructureSize(getRespBodyTokenField, r.token) - - return size -} - -func (r *GetResponseBody) Unmarshal(data []byte) error { - return message.Unmarshal(r, data, new(container.GetResponse_Body)) -} - -func (r *ListRequestBody) StableMarshal(buf []byte) []byte { - if r == nil { - return []byte{} - } - - if buf == nil { - buf = make([]byte, r.StableSize()) - } - - protoutil.NestedStructureMarshal(listReqBodyOwnerField, buf, r.ownerID) - - return buf -} - -func (r *ListRequestBody) StableSize() (size int) { - if r == nil { - return 0 - } - - size += protoutil.NestedStructureSize(listReqBodyOwnerField, r.ownerID) - - return size -} - -func (r *ListRequestBody) Unmarshal(data []byte) error { - return message.Unmarshal(r, data, new(container.ListRequest_Body)) -} - -func (r *ListResponseBody) StableMarshal(buf []byte) []byte { - if r == nil { - return []byte{} - } - - if buf == nil { - buf = make([]byte, r.StableSize()) - } - - var offset int - - for i := range r.cidList { - offset += protoutil.NestedStructureMarshal(listRespBodyIDsField, buf[offset:], &r.cidList[i]) - } - - return buf -} - -func (r *ListResponseBody) StableSize() (size int) { - if r == nil { - return 0 - } - - for i := range r.cidList { - size += protoutil.NestedStructureSize(listRespBodyIDsField, &r.cidList[i]) - } - - return size -} - -func (r *ListResponseBody) Unmarshal(data []byte) error { - return message.Unmarshal(r, data, new(container.ListResponse_Body)) -} - -func (r *SetExtendedACLRequestBody) StableMarshal(buf []byte) []byte { - if r == nil { - return []byte{} - } - - if buf == nil { - buf = make([]byte, r.StableSize()) - } - - var offset int - - offset += protoutil.NestedStructureMarshal(setEACLReqBodyTableField, buf[offset:], r.eacl) - protoutil.NestedStructureMarshal(setEACLReqBodySignatureField, buf[offset:], r.sig) - - return buf -} - -func (r *SetExtendedACLRequestBody) StableSize() (size int) { - if r == nil { - return 0 - } - - size += protoutil.NestedStructureSize(setEACLReqBodyTableField, r.eacl) - size += protoutil.NestedStructureSize(setEACLReqBodySignatureField, r.sig) - - return size -} - -func (r *SetExtendedACLRequestBody) Unmarshal(data []byte) error { - return message.Unmarshal(r, data, new(container.SetExtendedACLRequest_Body)) -} - -func (r *SetExtendedACLResponseBody) StableMarshal(_ []byte) []byte { - return nil -} - -func (r *SetExtendedACLResponseBody) StableSize() (size int) { - return 0 -} - -func (r *SetExtendedACLResponseBody) Unmarshal([]byte) error { - return nil -} - -func (r *GetExtendedACLRequestBody) StableMarshal(buf []byte) []byte { - if r == nil { - return []byte{} - } - - if buf == nil { - buf = make([]byte, r.StableSize()) - } - - protoutil.NestedStructureMarshal(getEACLReqBodyIDField, buf, r.cid) - - return buf -} - -func (r *GetExtendedACLRequestBody) StableSize() (size int) { - if r == nil { - return 0 - } - - size += protoutil.NestedStructureSize(getEACLReqBodyIDField, r.cid) - - return size -} - -func (r *GetExtendedACLRequestBody) Unmarshal(data []byte) error { - return message.Unmarshal(r, data, new(container.GetExtendedACLRequest_Body)) -} - -func (r *GetExtendedACLResponseBody) StableMarshal(buf []byte) []byte { - if r == nil { - return []byte{} - } - - if buf == nil { - buf = make([]byte, r.StableSize()) - } - - var offset int - - offset += protoutil.NestedStructureMarshal(getEACLRespBodyTableField, buf[offset:], r.eacl) - offset += protoutil.NestedStructureMarshal(getEACLRespBodySignatureField, buf[offset:], r.sig) - protoutil.NestedStructureMarshal(getEACLRespBodyTokenField, buf[offset:], r.token) - - return buf -} - -func (r *GetExtendedACLResponseBody) StableSize() (size int) { - if r == nil { - return 0 - } - - size += protoutil.NestedStructureSize(getEACLRespBodyTableField, r.eacl) - size += protoutil.NestedStructureSize(getEACLRespBodySignatureField, r.sig) - size += protoutil.NestedStructureSize(getEACLRespBodyTokenField, r.token) - - return size -} - -func (r *GetExtendedACLResponseBody) Unmarshal(data []byte) error { - return message.Unmarshal(r, data, new(container.GetExtendedACLResponse_Body)) -} - -func (a *UsedSpaceAnnouncement) StableMarshal(buf []byte) []byte { - if a == nil { - return []byte{} - } - - if buf == nil { - buf = make([]byte, a.StableSize()) - } - - var offset int - - offset += protoutil.UInt64Marshal(usedSpaceAnnounceEpochField, buf[offset:], a.epoch) - offset += protoutil.NestedStructureMarshal(usedSpaceAnnounceCIDField, buf[offset:], a.cid) - protoutil.UInt64Marshal(usedSpaceAnnounceUsedSpaceField, buf[offset:], a.usedSpace) - - return buf -} - -func (a *UsedSpaceAnnouncement) StableSize() (size int) { - if a == nil { - return 0 - } - - size += protoutil.UInt64Size(usedSpaceAnnounceEpochField, a.epoch) - size += protoutil.NestedStructureSize(usedSpaceAnnounceCIDField, a.cid) - size += protoutil.UInt64Size(usedSpaceAnnounceUsedSpaceField, a.usedSpace) - - return size -} - -func (a *UsedSpaceAnnouncement) Unmarshal(data []byte) error { - return message.Unmarshal(a, data, new(container.AnnounceUsedSpaceRequest_Body_Announcement)) -} - -func (r *AnnounceUsedSpaceRequestBody) StableMarshal(buf []byte) []byte { - if r == nil { - return []byte{} - } - - if buf == nil { - buf = make([]byte, r.StableSize()) - } - - var offset int - - for i := range r.announcements { - offset += protoutil.NestedStructureMarshal(usedSpaceReqBodyAnnouncementsField, buf[offset:], &r.announcements[i]) - } - - return buf -} - -func (r *AnnounceUsedSpaceRequestBody) StableSize() (size int) { - if r == nil { - return 0 - } - - for i := range r.announcements { - size += protoutil.NestedStructureSize(usedSpaceReqBodyAnnouncementsField, &r.announcements[i]) - } - - return size -} - -func (r *AnnounceUsedSpaceRequestBody) Unmarshal(data []byte) error { - return message.Unmarshal(r, data, new(container.AnnounceUsedSpaceRequest_Body)) -} - -func (r *AnnounceUsedSpaceResponseBody) StableMarshal(_ []byte) []byte { - return nil -} - -func (r *AnnounceUsedSpaceResponseBody) StableSize() (size int) { - return 0 -} - -func (r *AnnounceUsedSpaceResponseBody) Unmarshal([]byte) error { - return nil -} diff --git a/container/message_test.go b/container/message_test.go index 869ccb2..f2e101f 100644 --- a/container/message_test.go +++ b/container/message_test.go @@ -4,44 +4,44 @@ import ( "testing" containertest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/container/test" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message" messagetest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message/test" + "google.golang.org/protobuf/proto" ) func TestMessageConvert(t *testing.T) { messagetest.TestRPCMessage(t, - func(empty bool) message.Message { return containertest.GenerateAttribute(empty) }, - func(empty bool) message.Message { return containertest.GenerateContainer(empty) }, - func(empty bool) message.Message { return containertest.GeneratePutRequestBody(empty) }, - func(empty bool) message.Message { return containertest.GeneratePutRequest(empty) }, - func(empty bool) message.Message { return containertest.GeneratePutResponseBody(empty) }, - func(empty bool) message.Message { return containertest.GeneratePutResponse(empty) }, - func(empty bool) message.Message { return containertest.GenerateGetRequestBody(empty) }, - func(empty bool) message.Message { return containertest.GenerateGetRequest(empty) }, - func(empty bool) message.Message { return containertest.GenerateGetResponseBody(empty) }, - func(empty bool) message.Message { return containertest.GenerateGetResponse(empty) }, - func(empty bool) message.Message { return containertest.GenerateDeleteRequestBody(empty) }, - func(empty bool) message.Message { return containertest.GenerateDeleteRequest(empty) }, - func(empty bool) message.Message { return containertest.GenerateDeleteResponseBody(empty) }, - func(empty bool) message.Message { return containertest.GenerateDeleteResponse(empty) }, - func(empty bool) message.Message { return containertest.GenerateListRequestBody(empty) }, - func(empty bool) message.Message { return containertest.GenerateListRequest(empty) }, - func(empty bool) message.Message { return containertest.GenerateListResponseBody(empty) }, - func(empty bool) message.Message { return containertest.GenerateListResponse(empty) }, - func(empty bool) message.Message { return containertest.GenerateSetExtendedACLRequestBody(empty) }, - func(empty bool) message.Message { return containertest.GenerateSetExtendedACLRequest(empty) }, - func(empty bool) message.Message { return containertest.GenerateGetRequestBody(empty) }, - func(empty bool) message.Message { return containertest.GenerateGetRequest(empty) }, - func(empty bool) message.Message { return containertest.GenerateGetResponseBody(empty) }, - func(empty bool) message.Message { return containertest.GenerateGetResponse(empty) }, - func(empty bool) message.Message { return containertest.GenerateGetExtendedACLRequestBody(empty) }, - func(empty bool) message.Message { return containertest.GenerateGetExtendedACLRequest(empty) }, - func(empty bool) message.Message { return containertest.GenerateGetExtendedACLResponseBody(empty) }, - func(empty bool) message.Message { return containertest.GenerateGetExtendedACLResponse(empty) }, - func(empty bool) message.Message { return containertest.GenerateUsedSpaceAnnouncement(empty) }, - func(empty bool) message.Message { return containertest.GenerateAnnounceUsedSpaceRequestBody(empty) }, - func(empty bool) message.Message { return containertest.GenerateAnnounceUsedSpaceRequest(empty) }, - func(empty bool) message.Message { return containertest.GenerateAnnounceUsedSpaceResponseBody(empty) }, - func(empty bool) message.Message { return containertest.GenerateAnnounceUsedSpaceResponse(empty) }, + func(empty bool) proto.Message { return containertest.GenerateAttribute(empty) }, + func(empty bool) proto.Message { return containertest.GenerateContainer(empty) }, + func(empty bool) proto.Message { return containertest.GeneratePutRequestBody(empty) }, + func(empty bool) proto.Message { return containertest.GeneratePutRequest(empty) }, + func(empty bool) proto.Message { return containertest.GeneratePutResponseBody(empty) }, + func(empty bool) proto.Message { return containertest.GeneratePutResponse(empty) }, + func(empty bool) proto.Message { return containertest.GenerateGetRequestBody(empty) }, + func(empty bool) proto.Message { return containertest.GenerateGetRequest(empty) }, + func(empty bool) proto.Message { return containertest.GenerateGetResponseBody(empty) }, + func(empty bool) proto.Message { return containertest.GenerateGetResponse(empty) }, + func(empty bool) proto.Message { return containertest.GenerateDeleteRequestBody(empty) }, + func(empty bool) proto.Message { return containertest.GenerateDeleteRequest(empty) }, + func(empty bool) proto.Message { return containertest.GenerateDeleteResponseBody(empty) }, + func(empty bool) proto.Message { return containertest.GenerateDeleteResponse(empty) }, + func(empty bool) proto.Message { return containertest.GenerateListRequestBody(empty) }, + func(empty bool) proto.Message { return containertest.GenerateListRequest(empty) }, + func(empty bool) proto.Message { return containertest.GenerateListResponseBody(empty) }, + func(empty bool) proto.Message { return containertest.GenerateListResponse(empty) }, + func(empty bool) proto.Message { return containertest.GenerateSetExtendedACLRequestBody(empty) }, + func(empty bool) proto.Message { return containertest.GenerateSetExtendedACLRequest(empty) }, + func(empty bool) proto.Message { return containertest.GenerateGetRequestBody(empty) }, + func(empty bool) proto.Message { return containertest.GenerateGetRequest(empty) }, + func(empty bool) proto.Message { return containertest.GenerateGetResponseBody(empty) }, + func(empty bool) proto.Message { return containertest.GenerateGetResponse(empty) }, + func(empty bool) proto.Message { return containertest.GenerateGetExtendedACLRequestBody(empty) }, + func(empty bool) proto.Message { return containertest.GenerateGetExtendedACLRequest(empty) }, + func(empty bool) proto.Message { return containertest.GenerateGetExtendedACLResponseBody(empty) }, + func(empty bool) proto.Message { return containertest.GenerateGetExtendedACLResponse(empty) }, + func(empty bool) proto.Message { return containertest.GenerateUsedSpaceAnnouncement(empty) }, + func(empty bool) proto.Message { return containertest.GenerateAnnounceUsedSpaceRequestBody(empty) }, + func(empty bool) proto.Message { return containertest.GenerateAnnounceUsedSpaceRequest(empty) }, + func(empty bool) proto.Message { return containertest.GenerateAnnounceUsedSpaceResponseBody(empty) }, + func(empty bool) proto.Message { return containertest.GenerateAnnounceUsedSpaceResponse(empty) }, ) } diff --git a/container/test/generate.go b/container/test/generate.go index 2b2afdf..8f910b8 100644 --- a/container/test/generate.go +++ b/container/test/generate.go @@ -2,14 +2,14 @@ package containertest import ( acltest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/acl/test" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/container" + container "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/container/grpc" netmaptest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/netmap/test" refstest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs/test" sessiontest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/session/test" ) -func GenerateAttribute(empty bool) *container.Attribute { - m := new(container.Attribute) +func GenerateAttribute(empty bool) *container.Container_Attribute { + m := new(container.Container_Attribute) if !empty { m.SetKey("key") @@ -19,13 +19,13 @@ func GenerateAttribute(empty bool) *container.Attribute { return m } -func GenerateAttributes(empty bool) []container.Attribute { - var res []container.Attribute +func GenerateAttributes(empty bool) []*container.Container_Attribute { + var res []*container.Container_Attribute if !empty { res = append(res, - *GenerateAttribute(false), - *GenerateAttribute(false), + GenerateAttribute(false), + GenerateAttribute(false), ) } @@ -36,9 +36,9 @@ func GenerateContainer(empty bool) *container.Container { m := new(container.Container) if !empty { - m.SetBasicACL(12) + m.SetBasicAcl(12) m.SetNonce([]byte{1, 2, 3}) - m.SetOwnerID(refstest.GenerateOwnerID(false)) + m.SetOwnerId(refstest.GenerateOwnerID(false)) m.SetAttributes(GenerateAttributes(false)) m.SetPlacementPolicy(netmaptest.GeneratePlacementPolicy(false)) } @@ -48,14 +48,14 @@ func GenerateContainer(empty bool) *container.Container { return m } -func GeneratePutRequestBody(empty bool) *container.PutRequestBody { - m := new(container.PutRequestBody) +func GeneratePutRequestBody(empty bool) *container.PutRequest_Body { + m := new(container.PutRequest_Body) if !empty { m.SetContainer(GenerateContainer(false)) } - m.SetSignature(refstest.GenerateSignature(empty)) + m.SetSignature(refstest.GenerateSignatureRFC6979(empty)) return m } @@ -68,16 +68,16 @@ func GeneratePutRequest(empty bool) *container.PutRequest { } m.SetMetaHeader(sessiontest.GenerateRequestMetaHeader(empty)) - m.SetVerificationHeader(sessiontest.GenerateRequestVerificationHeader(empty)) + m.SetVerifyHeader(sessiontest.GenerateRequestVerificationHeader(empty)) return m } -func GeneratePutResponseBody(empty bool) *container.PutResponseBody { - m := new(container.PutResponseBody) +func GeneratePutResponseBody(empty bool) *container.PutResponse_Body { + m := new(container.PutResponse_Body) if !empty { - m.SetContainerID(refstest.GenerateContainerID(false)) + m.SetContainerId(refstest.GenerateContainerID(false)) } return m @@ -91,16 +91,16 @@ func GeneratePutResponse(empty bool) *container.PutResponse { } m.SetMetaHeader(sessiontest.GenerateResponseMetaHeader(empty)) - m.SetVerificationHeader(sessiontest.GenerateResponseVerificationHeader(empty)) + m.SetVerifyHeader(sessiontest.GenerateResponseVerificationHeader(empty)) return m } -func GenerateGetRequestBody(empty bool) *container.GetRequestBody { - m := new(container.GetRequestBody) +func GenerateGetRequestBody(empty bool) *container.GetRequest_Body { + m := new(container.GetRequest_Body) if !empty { - m.SetContainerID(refstest.GenerateContainerID(false)) + m.SetContainerId(refstest.GenerateContainerID(false)) } return m @@ -114,19 +114,19 @@ func GenerateGetRequest(empty bool) *container.GetRequest { } m.SetMetaHeader(sessiontest.GenerateRequestMetaHeader(empty)) - m.SetVerificationHeader(sessiontest.GenerateRequestVerificationHeader(empty)) + m.SetVerifyHeader(sessiontest.GenerateRequestVerificationHeader(empty)) return m } -func GenerateGetResponseBody(empty bool) *container.GetResponseBody { - m := new(container.GetResponseBody) +func GenerateGetResponseBody(empty bool) *container.GetResponse_Body { + m := new(container.GetResponse_Body) if !empty { m.SetContainer(GenerateContainer(false)) } - m.SetSignature(refstest.GenerateSignature(empty)) + m.SetSignature(refstest.GenerateSignatureRFC6979(empty)) m.SetSessionToken(sessiontest.GenerateSessionToken(empty)) return m @@ -140,19 +140,19 @@ func GenerateGetResponse(empty bool) *container.GetResponse { } m.SetMetaHeader(sessiontest.GenerateResponseMetaHeader(empty)) - m.SetVerificationHeader(sessiontest.GenerateResponseVerificationHeader(empty)) + m.SetVerifyHeader(sessiontest.GenerateResponseVerificationHeader(empty)) return m } -func GenerateDeleteRequestBody(empty bool) *container.DeleteRequestBody { - m := new(container.DeleteRequestBody) +func GenerateDeleteRequestBody(empty bool) *container.DeleteRequest_Body { + m := new(container.DeleteRequest_Body) if !empty { - m.SetContainerID(refstest.GenerateContainerID(false)) + m.SetContainerId(refstest.GenerateContainerID(false)) } - m.SetSignature(refstest.GenerateSignature(empty)) + m.SetSignature(refstest.GenerateSignatureRFC6979(empty)) return m } @@ -165,13 +165,13 @@ func GenerateDeleteRequest(empty bool) *container.DeleteRequest { } m.SetMetaHeader(sessiontest.GenerateRequestMetaHeader(empty)) - m.SetVerificationHeader(sessiontest.GenerateRequestVerificationHeader(empty)) + m.SetVerifyHeader(sessiontest.GenerateRequestVerificationHeader(empty)) return m } -func GenerateDeleteResponseBody(_ bool) *container.DeleteResponseBody { - m := new(container.DeleteResponseBody) +func GenerateDeleteResponseBody(_ bool) *container.DeleteResponse_Body { + m := new(container.DeleteResponse_Body) return m } @@ -184,16 +184,16 @@ func GenerateDeleteResponse(empty bool) *container.DeleteResponse { } m.SetMetaHeader(sessiontest.GenerateResponseMetaHeader(empty)) - m.SetVerificationHeader(sessiontest.GenerateResponseVerificationHeader(empty)) + m.SetVerifyHeader(sessiontest.GenerateResponseVerificationHeader(empty)) return m } -func GenerateListRequestBody(empty bool) *container.ListRequestBody { - m := new(container.ListRequestBody) +func GenerateListRequestBody(empty bool) *container.ListRequest_Body { + m := new(container.ListRequest_Body) if !empty { - m.SetOwnerID(refstest.GenerateOwnerID(false)) + m.SetOwnerId(refstest.GenerateOwnerID(false)) } return m @@ -207,16 +207,16 @@ func GenerateListRequest(empty bool) *container.ListRequest { } m.SetMetaHeader(sessiontest.GenerateRequestMetaHeader(empty)) - m.SetVerificationHeader(sessiontest.GenerateRequestVerificationHeader(empty)) + m.SetVerifyHeader(sessiontest.GenerateRequestVerificationHeader(empty)) return m } -func GenerateListResponseBody(empty bool) *container.ListResponseBody { - m := new(container.ListResponseBody) +func GenerateListResponseBody(empty bool) *container.ListResponse_Body { + m := new(container.ListResponse_Body) if !empty { - m.SetContainerIDs(refstest.GenerateContainerIDs(false)) + m.SetContainerIds(refstest.GenerateContainerIDs(false)) } return m @@ -230,19 +230,19 @@ func GenerateListResponse(empty bool) *container.ListResponse { } m.SetMetaHeader(sessiontest.GenerateResponseMetaHeader(empty)) - m.SetVerificationHeader(sessiontest.GenerateResponseVerificationHeader(empty)) + m.SetVerifyHeader(sessiontest.GenerateResponseVerificationHeader(empty)) return m } -func GenerateSetExtendedACLRequestBody(empty bool) *container.SetExtendedACLRequestBody { - m := new(container.SetExtendedACLRequestBody) +func GenerateSetExtendedACLRequestBody(empty bool) *container.SetExtendedACLRequest_Body { + m := new(container.SetExtendedACLRequest_Body) if !empty { - m.SetEACL(acltest.GenerateTable(false)) + m.SetEacl(acltest.GenerateTable(false)) } - m.SetSignature(refstest.GenerateSignature(empty)) + m.SetSignature(refstest.GenerateSignatureRFC6979(empty)) return m } @@ -255,13 +255,13 @@ func GenerateSetExtendedACLRequest(empty bool) *container.SetExtendedACLRequest } m.SetMetaHeader(sessiontest.GenerateRequestMetaHeader(empty)) - m.SetVerificationHeader(sessiontest.GenerateRequestVerificationHeader(empty)) + m.SetVerifyHeader(sessiontest.GenerateRequestVerificationHeader(empty)) return m } -func GenerateSetExtendedACLResponseBody(_ bool) *container.SetExtendedACLResponseBody { - m := new(container.SetExtendedACLResponseBody) +func GenerateSetExtendedACLResponseBody(_ bool) *container.SetExtendedACLResponse_Body { + m := new(container.SetExtendedACLResponse_Body) return m } @@ -274,16 +274,16 @@ func GenerateSetExtendedACLResponse(empty bool) *container.SetExtendedACLRespons } m.SetMetaHeader(sessiontest.GenerateResponseMetaHeader(empty)) - m.SetVerificationHeader(sessiontest.GenerateResponseVerificationHeader(empty)) + m.SetVerifyHeader(sessiontest.GenerateResponseVerificationHeader(empty)) return m } -func GenerateGetExtendedACLRequestBody(empty bool) *container.GetExtendedACLRequestBody { - m := new(container.GetExtendedACLRequestBody) +func GenerateGetExtendedACLRequestBody(empty bool) *container.GetExtendedACLRequest_Body { + m := new(container.GetExtendedACLRequest_Body) if !empty { - m.SetContainerID(refstest.GenerateContainerID(false)) + m.SetContainerId(refstest.GenerateContainerID(false)) } return m @@ -297,19 +297,19 @@ func GenerateGetExtendedACLRequest(empty bool) *container.GetExtendedACLRequest } m.SetMetaHeader(sessiontest.GenerateRequestMetaHeader(empty)) - m.SetVerificationHeader(sessiontest.GenerateRequestVerificationHeader(empty)) + m.SetVerifyHeader(sessiontest.GenerateRequestVerificationHeader(empty)) return m } -func GenerateGetExtendedACLResponseBody(empty bool) *container.GetExtendedACLResponseBody { - m := new(container.GetExtendedACLResponseBody) +func GenerateGetExtendedACLResponseBody(empty bool) *container.GetExtendedACLResponse_Body { + m := new(container.GetExtendedACLResponse_Body) if !empty { - m.SetEACL(acltest.GenerateTable(false)) + m.SetEacl(acltest.GenerateTable(false)) } - m.SetSignature(refstest.GenerateSignature(empty)) + m.SetSignature(refstest.GenerateSignatureRFC6979(empty)) m.SetSessionToken(sessiontest.GenerateSessionToken(empty)) return m @@ -323,16 +323,16 @@ func GenerateGetExtendedACLResponse(empty bool) *container.GetExtendedACLRespons } m.SetMetaHeader(sessiontest.GenerateResponseMetaHeader(empty)) - m.SetVerificationHeader(sessiontest.GenerateResponseVerificationHeader(empty)) + m.SetVerifyHeader(sessiontest.GenerateResponseVerificationHeader(empty)) return m } -func GenerateUsedSpaceAnnouncement(empty bool) *container.UsedSpaceAnnouncement { - m := new(container.UsedSpaceAnnouncement) +func GenerateUsedSpaceAnnouncement(empty bool) *container.AnnounceUsedSpaceRequest_Body_Announcement { + m := new(container.AnnounceUsedSpaceRequest_Body_Announcement) if !empty { - m.SetContainerID(refstest.GenerateContainerID(false)) + m.SetContainerId(refstest.GenerateContainerID(false)) m.SetEpoch(1) m.SetUsedSpace(2) } @@ -340,21 +340,21 @@ func GenerateUsedSpaceAnnouncement(empty bool) *container.UsedSpaceAnnouncement return m } -func GenerateUsedSpaceAnnouncements(empty bool) []container.UsedSpaceAnnouncement { - var res []container.UsedSpaceAnnouncement +func GenerateUsedSpaceAnnouncements(empty bool) []*container.AnnounceUsedSpaceRequest_Body_Announcement { + var res []*container.AnnounceUsedSpaceRequest_Body_Announcement if !empty { res = append(res, - *GenerateUsedSpaceAnnouncement(false), - *GenerateUsedSpaceAnnouncement(false), + GenerateUsedSpaceAnnouncement(false), + GenerateUsedSpaceAnnouncement(false), ) } return res } -func GenerateAnnounceUsedSpaceRequestBody(empty bool) *container.AnnounceUsedSpaceRequestBody { - m := new(container.AnnounceUsedSpaceRequestBody) +func GenerateAnnounceUsedSpaceRequestBody(empty bool) *container.AnnounceUsedSpaceRequest_Body { + m := new(container.AnnounceUsedSpaceRequest_Body) if !empty { m.SetAnnouncements(GenerateUsedSpaceAnnouncements(false)) @@ -371,13 +371,13 @@ func GenerateAnnounceUsedSpaceRequest(empty bool) *container.AnnounceUsedSpaceRe } m.SetMetaHeader(sessiontest.GenerateRequestMetaHeader(empty)) - m.SetVerificationHeader(sessiontest.GenerateRequestVerificationHeader(empty)) + m.SetVerifyHeader(sessiontest.GenerateRequestVerificationHeader(empty)) return m } -func GenerateAnnounceUsedSpaceResponseBody(_ bool) *container.AnnounceUsedSpaceResponseBody { - m := new(container.AnnounceUsedSpaceResponseBody) +func GenerateAnnounceUsedSpaceResponseBody(_ bool) *container.AnnounceUsedSpaceResponse_Body { + m := new(container.AnnounceUsedSpaceResponse_Body) return m } @@ -390,7 +390,7 @@ func GenerateAnnounceUsedSpaceResponse(empty bool) *container.AnnounceUsedSpaceR } m.SetMetaHeader(sessiontest.GenerateResponseMetaHeader(empty)) - m.SetVerificationHeader(sessiontest.GenerateResponseVerificationHeader(empty)) + m.SetVerifyHeader(sessiontest.GenerateResponseVerificationHeader(empty)) return m } diff --git a/container/types.go b/container/types.go deleted file mode 100644 index 948580d..0000000 --- a/container/types.go +++ /dev/null @@ -1,717 +0,0 @@ -package container - -import ( - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/acl" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/netmap" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/session" -) - -type Attribute struct { - key, val string -} - -type Container struct { - version *refs.Version - - ownerID *refs.OwnerID - - nonce []byte - - basicACL uint32 - - attr []Attribute - - policy *netmap.PlacementPolicy -} - -type PutRequestBody struct { - cnr *Container - - sig *refs.Signature -} -type PutRequest struct { - body *PutRequestBody - - session.RequestHeaders -} - -type PutResponseBody struct { - cid *refs.ContainerID -} - -type PutResponse struct { - body *PutResponseBody - - session.ResponseHeaders -} - -type GetRequestBody struct { - cid *refs.ContainerID -} - -type GetRequest struct { - body *GetRequestBody - - session.RequestHeaders -} - -type GetResponseBody struct { - cnr *Container - - token *session.Token - - sig *refs.Signature -} - -type GetResponse struct { - body *GetResponseBody - - session.ResponseHeaders -} - -type DeleteRequestBody struct { - cid *refs.ContainerID - - sig *refs.Signature -} - -type DeleteRequest struct { - body *DeleteRequestBody - - session.RequestHeaders -} - -type DeleteResponseBody struct{} - -type DeleteResponse struct { - body *DeleteResponseBody - - session.ResponseHeaders -} - -type ListRequestBody struct { - ownerID *refs.OwnerID -} - -type ListRequest struct { - body *ListRequestBody - - session.RequestHeaders -} - -type ListResponseBody struct { - cidList []refs.ContainerID -} - -type ListResponse struct { - body *ListResponseBody - - session.ResponseHeaders -} - -type SetExtendedACLRequestBody struct { - eacl *acl.Table - - sig *refs.Signature -} - -type SetExtendedACLRequest struct { - body *SetExtendedACLRequestBody - - session.RequestHeaders -} - -type SetExtendedACLResponseBody struct{} - -type SetExtendedACLResponse struct { - body *SetExtendedACLResponseBody - - session.ResponseHeaders -} - -type GetExtendedACLRequestBody struct { - cid *refs.ContainerID -} - -type GetExtendedACLRequest struct { - body *GetExtendedACLRequestBody - - session.RequestHeaders -} - -type GetExtendedACLResponseBody struct { - eacl *acl.Table - - sig *refs.Signature - - token *session.Token -} - -type GetExtendedACLResponse struct { - body *GetExtendedACLResponseBody - - session.ResponseHeaders -} - -type UsedSpaceAnnouncement struct { - epoch uint64 - - cid *refs.ContainerID - - usedSpace uint64 -} - -type AnnounceUsedSpaceRequestBody struct { - announcements []UsedSpaceAnnouncement -} - -type AnnounceUsedSpaceRequest struct { - body *AnnounceUsedSpaceRequestBody - - session.RequestHeaders -} - -type AnnounceUsedSpaceResponseBody struct{} - -type AnnounceUsedSpaceResponse struct { - body *AnnounceUsedSpaceResponseBody - - session.ResponseHeaders -} - -func (a *Attribute) GetKey() string { - if a != nil { - return a.key - } - - return "" -} - -func (a *Attribute) SetKey(v string) { - a.key = v -} - -func (a *Attribute) GetValue() string { - if a != nil { - return a.val - } - - return "" -} - -func (a *Attribute) SetValue(v string) { - a.val = v -} - -func (c *Container) GetVersion() *refs.Version { - if c != nil { - return c.version - } - - return nil -} - -func (c *Container) SetVersion(v *refs.Version) { - c.version = v -} - -func (c *Container) GetOwnerID() *refs.OwnerID { - if c != nil { - return c.ownerID - } - - return nil -} - -func (c *Container) SetOwnerID(v *refs.OwnerID) { - c.ownerID = v -} - -func (c *Container) GetNonce() []byte { - if c != nil { - return c.nonce - } - - return nil -} - -func (c *Container) SetNonce(v []byte) { - c.nonce = v -} - -func (c *Container) GetBasicACL() uint32 { - if c != nil { - return c.basicACL - } - - return 0 -} - -func (c *Container) SetBasicACL(v uint32) { - c.basicACL = v -} - -func (c *Container) GetAttributes() []Attribute { - if c != nil { - return c.attr - } - - return nil -} - -func (c *Container) SetAttributes(v []Attribute) { - c.attr = v -} - -func (c *Container) GetPlacementPolicy() *netmap.PlacementPolicy { - if c != nil { - return c.policy - } - - return nil -} - -func (c *Container) SetPlacementPolicy(v *netmap.PlacementPolicy) { - c.policy = v -} - -func (r *PutRequestBody) GetContainer() *Container { - if r != nil { - return r.cnr - } - - return nil -} - -func (r *PutRequestBody) SetContainer(v *Container) { - r.cnr = v -} - -func (r *PutRequestBody) GetSignature() *refs.Signature { - if r != nil { - return r.sig - } - - return nil -} - -func (r *PutRequestBody) SetSignature(v *refs.Signature) { - // TODO: (neofs-api-go#381) avoid this hack (e.g. create refs.SignatureRFC6979 type) - v.SetScheme(0) - r.sig = v -} - -func (r *PutRequest) GetBody() *PutRequestBody { - if r != nil { - return r.body - } - - return nil -} - -func (r *PutRequest) SetBody(v *PutRequestBody) { - r.body = v -} - -func (r *PutResponseBody) GetContainerID() *refs.ContainerID { - if r != nil { - return r.cid - } - - return nil -} - -func (r *PutResponseBody) SetContainerID(v *refs.ContainerID) { - r.cid = v -} - -func (r *PutResponse) GetBody() *PutResponseBody { - if r != nil { - return r.body - } - - return nil -} - -func (r *PutResponse) SetBody(v *PutResponseBody) { - r.body = v -} - -func (r *GetRequestBody) GetContainerID() *refs.ContainerID { - if r != nil { - return r.cid - } - - return nil -} - -func (r *GetRequestBody) SetContainerID(v *refs.ContainerID) { - r.cid = v -} - -func (r *GetRequest) GetBody() *GetRequestBody { - if r != nil { - return r.body - } - - return nil -} - -func (r *GetRequest) SetBody(v *GetRequestBody) { - r.body = v -} - -func (r *GetResponseBody) GetContainer() *Container { - if r != nil { - return r.cnr - } - - return nil -} - -func (r *GetResponseBody) SetContainer(v *Container) { - r.cnr = v -} - -// GetSessionToken returns token of the session within which requested -// container was created. -func (r *GetResponseBody) GetSessionToken() *session.Token { - if r != nil { - return r.token - } - - return nil -} - -// SetSessionToken sets token of the session within which requested -// container was created. -func (r *GetResponseBody) SetSessionToken(v *session.Token) { - r.token = v -} - -// GetSignature returns signature of the requested container. -func (r *GetResponseBody) GetSignature() *refs.Signature { - if r != nil { - return r.sig - } - - return nil -} - -// SetSignature sets signature of the requested container. -func (r *GetResponseBody) SetSignature(v *refs.Signature) { - // TODO: (neofs-api-go#381) avoid this hack (e.g. create refs.SignatureRFC6979 type) - v.SetScheme(0) - r.sig = v -} - -func (r *GetResponse) GetBody() *GetResponseBody { - if r != nil { - return r.body - } - - return nil -} - -func (r *GetResponse) SetBody(v *GetResponseBody) { - r.body = v -} - -func (r *DeleteRequestBody) GetContainerID() *refs.ContainerID { - if r != nil { - return r.cid - } - - return nil -} - -func (r *DeleteRequestBody) SetContainerID(v *refs.ContainerID) { - r.cid = v -} - -func (r *DeleteRequestBody) GetSignature() *refs.Signature { - if r != nil { - return r.sig - } - - return nil -} - -func (r *DeleteRequestBody) SetSignature(v *refs.Signature) { - // TODO: (neofs-api-go#381) avoid this hack (e.g. create refs.SignatureRFC6979 type) - v.SetScheme(0) - r.sig = v -} - -func (r *DeleteRequest) GetBody() *DeleteRequestBody { - if r != nil { - return r.body - } - - return nil -} - -func (r *DeleteRequest) SetBody(v *DeleteRequestBody) { - r.body = v -} - -func (r *DeleteResponse) GetBody() *DeleteResponseBody { - if r != nil { - return r.body - } - - return nil -} - -func (r *DeleteResponse) SetBody(v *DeleteResponseBody) { - r.body = v -} - -func (r *ListRequestBody) GetOwnerID() *refs.OwnerID { - if r != nil { - return r.ownerID - } - - return nil -} - -func (r *ListRequestBody) SetOwnerID(v *refs.OwnerID) { - r.ownerID = v -} - -func (r *ListRequest) GetBody() *ListRequestBody { - if r != nil { - return r.body - } - - return nil -} - -func (r *ListRequest) SetBody(v *ListRequestBody) { - r.body = v -} - -func (r *ListResponseBody) GetContainerIDs() []refs.ContainerID { - if r != nil { - return r.cidList - } - - return nil -} - -func (r *ListResponseBody) SetContainerIDs(v []refs.ContainerID) { - r.cidList = v -} - -func (r *ListResponse) GetBody() *ListResponseBody { - if r != nil { - return r.body - } - - return nil -} - -func (r *ListResponse) SetBody(v *ListResponseBody) { - r.body = v -} - -func (r *SetExtendedACLRequestBody) GetEACL() *acl.Table { - if r != nil { - return r.eacl - } - - return nil -} - -func (r *SetExtendedACLRequestBody) SetEACL(v *acl.Table) { - r.eacl = v -} - -func (r *SetExtendedACLRequestBody) GetSignature() *refs.Signature { - if r != nil { - return r.sig - } - - return nil -} - -func (r *SetExtendedACLRequestBody) SetSignature(v *refs.Signature) { - // TODO: (neofs-api-go#381) avoid this hack (e.g. create refs.SignatureRFC6979 type) - v.SetScheme(0) - r.sig = v -} - -func (r *SetExtendedACLRequest) GetBody() *SetExtendedACLRequestBody { - if r != nil { - return r.body - } - - return nil -} - -func (r *SetExtendedACLRequest) SetBody(v *SetExtendedACLRequestBody) { - r.body = v -} - -func (r *SetExtendedACLResponse) GetBody() *SetExtendedACLResponseBody { - if r != nil { - return r.body - } - - return nil -} - -func (r *SetExtendedACLResponse) SetBody(v *SetExtendedACLResponseBody) { - r.body = v -} - -func (r *GetExtendedACLRequestBody) GetContainerID() *refs.ContainerID { - if r != nil { - return r.cid - } - - return nil -} - -func (r *GetExtendedACLRequestBody) SetContainerID(v *refs.ContainerID) { - r.cid = v -} - -func (r *GetExtendedACLRequest) GetBody() *GetExtendedACLRequestBody { - if r != nil { - return r.body - } - - return nil -} - -func (r *GetExtendedACLRequest) SetBody(v *GetExtendedACLRequestBody) { - r.body = v -} - -func (r *GetExtendedACLResponseBody) GetEACL() *acl.Table { - if r != nil { - return r.eacl - } - - return nil -} - -func (r *GetExtendedACLResponseBody) SetEACL(v *acl.Table) { - r.eacl = v -} - -func (r *GetExtendedACLResponseBody) GetSignature() *refs.Signature { - if r != nil { - return r.sig - } - - return nil -} - -func (r *GetExtendedACLResponseBody) SetSignature(v *refs.Signature) { - // TODO: (neofs-api-go#381) avoid this hack (e.g. create refs.SignatureRFC6979 type) - v.SetScheme(0) - r.sig = v -} - -// GetSessionToken returns token of the session within which requested -// eACL table was set. -func (r *GetExtendedACLResponseBody) GetSessionToken() *session.Token { - if r != nil { - return r.token - } - - return nil -} - -// SetSessionToken sets token of the session within which requested -// eACL table was set. -func (r *GetExtendedACLResponseBody) SetSessionToken(v *session.Token) { - r.token = v -} - -func (r *GetExtendedACLResponse) GetBody() *GetExtendedACLResponseBody { - if r != nil { - return r.body - } - - return nil -} - -func (r *GetExtendedACLResponse) SetBody(v *GetExtendedACLResponseBody) { - r.body = v -} - -func (a *UsedSpaceAnnouncement) GetEpoch() uint64 { - if a != nil { - return a.epoch - } - - return 0 -} - -func (a *UsedSpaceAnnouncement) SetEpoch(v uint64) { - a.epoch = v -} - -func (a *UsedSpaceAnnouncement) GetUsedSpace() uint64 { - if a != nil { - return a.usedSpace - } - - return 0 -} - -func (a *UsedSpaceAnnouncement) SetUsedSpace(v uint64) { - a.usedSpace = v -} - -func (a *UsedSpaceAnnouncement) GetContainerID() *refs.ContainerID { - if a != nil { - return a.cid - } - - return nil -} - -func (a *UsedSpaceAnnouncement) SetContainerID(v *refs.ContainerID) { - a.cid = v -} - -func (r *AnnounceUsedSpaceRequestBody) GetAnnouncements() []UsedSpaceAnnouncement { - if r != nil { - return r.announcements - } - - return nil -} - -func (r *AnnounceUsedSpaceRequestBody) SetAnnouncements(v []UsedSpaceAnnouncement) { - r.announcements = v -} - -func (r *AnnounceUsedSpaceRequest) GetBody() *AnnounceUsedSpaceRequestBody { - if r != nil { - return r.body - } - - return nil -} - -func (r *AnnounceUsedSpaceRequest) SetBody(v *AnnounceUsedSpaceRequestBody) { - r.body = v -} - -func (r *AnnounceUsedSpaceResponse) GetBody() *AnnounceUsedSpaceResponseBody { - if r != nil { - return r.body - } - - return nil -} - -func (r *AnnounceUsedSpaceResponse) SetBody(v *AnnounceUsedSpaceResponseBody) { - r.body = v -} diff --git a/lock/grpc/lock_test.go b/lock/grpc/lock_test.go new file mode 100644 index 0000000..26306b2 --- /dev/null +++ b/lock/grpc/lock_test.go @@ -0,0 +1,28 @@ +package lock_test + +import ( + "testing" + + lock "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/lock/grpc" + locktest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/lock/test" + object "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/object/grpc" + "github.com/stretchr/testify/require" + "google.golang.org/protobuf/proto" +) + +func TestLockRW(t *testing.T) { + l := new(lock.Lock) + obj := new(object.Object) + + require.Error(t, lock.ReadLock(l, obj)) + + l = locktest.GenerateLock(false) + + lock.WriteLock(obj, l) + + l2 := new(lock.Lock) + + require.NoError(t, lock.ReadLock(l2, obj)) + + require.True(t, proto.Equal(l, l2)) +} diff --git a/lock/grpc/types.go b/lock/grpc/types.go index 9d5719f..13b6c4b 100644 --- a/lock/grpc/types.go +++ b/lock/grpc/types.go @@ -1,8 +1,62 @@ package lock -import refs "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs/grpc" +import ( + "errors" + "fmt" + + object "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/object/grpc" + refs "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs/grpc" + "google.golang.org/protobuf/proto" +) // SetMembers sets `members` field. func (x *Lock) SetMembers(ids []*refs.ObjectID) { x.Members = ids } + +func (x *Lock) Unmarshal(data []byte) error { + return proto.Unmarshal(data, x) +} + +// WriteLock writes Lock to the Object as a payload content. +// The object must not be nil. +func WriteLock(obj *object.Object, lock *Lock) { + hdr := obj.GetHeader() + if hdr == nil { + hdr = new(object.Header) + obj.SetHeader(hdr) + } + + hdr.SetObjectType(object.ObjectType_LOCK) + + payload := lock.StableMarshal(nil) + obj.SetPayload(payload) +} + +// ReadLock reads Lock from the Object payload content. +func ReadLock(lock *Lock, obj *object.Object) error { + payload := obj.GetPayload() + if len(payload) == 0 { + return errors.New("empty payload") + } + + err := lock.Unmarshal(payload) + if err != nil { + return fmt.Errorf("decode lock content from payload: %w", err) + } + + return nil +} + +func (l *Lock) NumberOfMembers() int { + return len(l.GetMembers()) +} + +// IterateMembers passes members of the lock list to f. +func (x *Lock) IterateMembers(f func(*refs.ObjectID)) { + if x != nil { + for i := range x.Members { + f(x.Members[i]) + } + } +} diff --git a/lock/grpc/types.pb.go b/lock/grpc/types.pb.go index 958476c..ed902b2 100644 Binary files a/lock/grpc/types.pb.go and b/lock/grpc/types.pb.go differ diff --git a/lock/grpc/types_frostfs.pb.go b/lock/grpc/types_frostfs.pb.go new file mode 100644 index 0000000..267de94 Binary files /dev/null and b/lock/grpc/types_frostfs.pb.go differ diff --git a/lock/test/generate.go b/lock/test/generate.go new file mode 100644 index 0000000..297976a --- /dev/null +++ b/lock/test/generate.go @@ -0,0 +1,20 @@ +package locktest + +import ( + lock "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/lock/grpc" + refs "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs/grpc" + refstest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs/test" +) + +func GenerateLock(empty bool) *lock.Lock { + m := new(lock.Lock) + + if !empty { + m.SetMembers([]*refs.ObjectID{ + refstest.GenerateObjectID(false), + refstest.GenerateObjectID(false), + }) + } + + return m +} diff --git a/netmap/convert.go b/netmap/convert.go deleted file mode 100644 index 6bb1525..0000000 --- a/netmap/convert.go +++ /dev/null @@ -1,919 +0,0 @@ -package netmap - -import ( - netmap "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/netmap/grpc" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs" - refsGRPC "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs/grpc" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/grpc" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message" -) - -func (f *Filter) ToGRPCMessage() grpc.Message { - var m *netmap.Filter - - if f != nil { - m = new(netmap.Filter) - - m.SetKey(f.key) - m.SetValue(f.value) - m.SetName(f.name) - m.SetOp(OperationToGRPCMessage(f.op)) - m.SetFilters(FiltersToGRPC(f.filters)) - } - - return m -} - -func (f *Filter) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*netmap.Filter) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var err error - - f.filters, err = FiltersFromGRPC(v.GetFilters()) - if err != nil { - return err - } - - f.key = v.GetKey() - f.value = v.GetValue() - f.name = v.GetName() - f.op = OperationFromGRPCMessage(v.GetOp()) - - return nil -} - -func FiltersToGRPC(fs []Filter) (res []*netmap.Filter) { - if fs != nil { - res = make([]*netmap.Filter, 0, len(fs)) - - for i := range fs { - res = append(res, fs[i].ToGRPCMessage().(*netmap.Filter)) - } - } - - return -} - -func FiltersFromGRPC(fs []*netmap.Filter) (res []Filter, err error) { - if fs != nil { - res = make([]Filter, len(fs)) - - for i := range fs { - if fs[i] != nil { - err = res[i].FromGRPCMessage(fs[i]) - if err != nil { - return - } - } - } - } - - return -} - -func (s *Selector) ToGRPCMessage() grpc.Message { - var m *netmap.Selector - - if s != nil { - m = new(netmap.Selector) - - m.SetName(s.name) - m.SetAttribute(s.attribute) - m.SetFilter(s.filter) - m.SetCount(s.count) - m.SetClause(ClauseToGRPCMessage(s.clause)) - } - - return m -} - -func (s *Selector) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*netmap.Selector) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - s.name = v.GetName() - s.attribute = v.GetAttribute() - s.filter = v.GetFilter() - s.count = v.GetCount() - s.clause = ClauseFromGRPCMessage(v.GetClause()) - - return nil -} - -func SelectorsToGRPC(ss []Selector) (res []*netmap.Selector) { - if ss != nil { - res = make([]*netmap.Selector, 0, len(ss)) - - for i := range ss { - res = append(res, ss[i].ToGRPCMessage().(*netmap.Selector)) - } - } - - return -} - -func SelectorsFromGRPC(ss []*netmap.Selector) (res []Selector, err error) { - if ss != nil { - res = make([]Selector, len(ss)) - - for i := range ss { - if ss[i] != nil { - err = res[i].FromGRPCMessage(ss[i]) - if err != nil { - return - } - } - } - } - - return -} - -func (r *Replica) ToGRPCMessage() grpc.Message { - var m *netmap.Replica - - if r != nil { - m = new(netmap.Replica) - - m.SetSelector(r.selector) - m.SetCount(r.count) - } - - return m -} - -func (r *Replica) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*netmap.Replica) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - r.selector = v.GetSelector() - r.count = v.GetCount() - - return nil -} - -func ReplicasToGRPC(rs []Replica) (res []*netmap.Replica) { - if rs != nil { - res = make([]*netmap.Replica, 0, len(rs)) - - for i := range rs { - res = append(res, rs[i].ToGRPCMessage().(*netmap.Replica)) - } - } - - return -} - -func ReplicasFromGRPC(rs []*netmap.Replica) (res []Replica, err error) { - if rs != nil { - res = make([]Replica, len(rs)) - - for i := range rs { - if rs[i] != nil { - err = res[i].FromGRPCMessage(rs[i]) - if err != nil { - return - } - } - } - } - - return -} - -func (p *PlacementPolicy) ToGRPCMessage() grpc.Message { - var m *netmap.PlacementPolicy - - if p != nil { - m = new(netmap.PlacementPolicy) - - m.SetFilters(FiltersToGRPC(p.filters)) - m.SetSelectors(SelectorsToGRPC(p.selectors)) - m.SetReplicas(ReplicasToGRPC(p.replicas)) - m.SetContainerBackupFactor(p.backupFactor) - } - - return m -} - -func (p *PlacementPolicy) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*netmap.PlacementPolicy) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var err error - - p.filters, err = FiltersFromGRPC(v.GetFilters()) - if err != nil { - return err - } - - p.selectors, err = SelectorsFromGRPC(v.GetSelectors()) - if err != nil { - return err - } - - p.replicas, err = ReplicasFromGRPC(v.GetReplicas()) - if err != nil { - return err - } - - p.backupFactor = v.GetContainerBackupFactor() - - return nil -} - -func ClauseToGRPCMessage(n Clause) netmap.Clause { - return netmap.Clause(n) -} - -func ClauseFromGRPCMessage(n netmap.Clause) Clause { - return Clause(n) -} - -func OperationToGRPCMessage(n Operation) netmap.Operation { - return netmap.Operation(n) -} - -func OperationFromGRPCMessage(n netmap.Operation) Operation { - return Operation(n) -} - -func NodeStateToGRPCMessage(n NodeState) netmap.NodeInfo_State { - return netmap.NodeInfo_State(n) -} - -func NodeStateFromRPCMessage(n netmap.NodeInfo_State) NodeState { - return NodeState(n) -} - -func (a *Attribute) ToGRPCMessage() grpc.Message { - var m *netmap.NodeInfo_Attribute - - if a != nil { - m = new(netmap.NodeInfo_Attribute) - - m.SetKey(a.key) - m.SetValue(a.value) - m.SetParents(a.parents) - } - - return m -} - -func (a *Attribute) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*netmap.NodeInfo_Attribute) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - a.key = v.GetKey() - a.value = v.GetValue() - a.parents = v.GetParents() - - return nil -} - -func AttributesToGRPC(as []Attribute) (res []*netmap.NodeInfo_Attribute) { - if as != nil { - res = make([]*netmap.NodeInfo_Attribute, 0, len(as)) - - for i := range as { - res = append(res, as[i].ToGRPCMessage().(*netmap.NodeInfo_Attribute)) - } - } - - return -} - -func AttributesFromGRPC(as []*netmap.NodeInfo_Attribute) (res []Attribute, err error) { - if as != nil { - res = make([]Attribute, len(as)) - - for i := range as { - if as[i] != nil { - err = res[i].FromGRPCMessage(as[i]) - if err != nil { - return - } - } - } - } - - return -} - -func (ni *NodeInfo) ToGRPCMessage() grpc.Message { - var m *netmap.NodeInfo - - if ni != nil { - m = new(netmap.NodeInfo) - - m.SetPublicKey(ni.publicKey) - m.SetAddresses(ni.addresses) - m.SetState(NodeStateToGRPCMessage(ni.state)) - m.SetAttributes(AttributesToGRPC(ni.attributes)) - } - - return m -} - -func (ni *NodeInfo) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*netmap.NodeInfo) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var err error - - ni.attributes, err = AttributesFromGRPC(v.GetAttributes()) - if err != nil { - return err - } - - ni.publicKey = v.GetPublicKey() - ni.addresses = v.GetAddresses() - ni.state = NodeStateFromRPCMessage(v.GetState()) - - return nil -} - -func (l *LocalNodeInfoRequestBody) ToGRPCMessage() grpc.Message { - var m *netmap.LocalNodeInfoRequest_Body - - if l != nil { - m = new(netmap.LocalNodeInfoRequest_Body) - } - - return m -} - -func (l *LocalNodeInfoRequestBody) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*netmap.LocalNodeInfoRequest_Body) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - return nil -} - -func (l *LocalNodeInfoRequest) ToGRPCMessage() grpc.Message { - var m *netmap.LocalNodeInfoRequest - - if l != nil { - m = new(netmap.LocalNodeInfoRequest) - - m.SetBody(l.body.ToGRPCMessage().(*netmap.LocalNodeInfoRequest_Body)) - l.RequestHeaders.ToMessage(m) - } - - return m -} - -func (l *LocalNodeInfoRequest) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*netmap.LocalNodeInfoRequest) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var err error - - body := v.GetBody() - if body == nil { - l.body = nil - } else { - if l.body == nil { - l.body = new(LocalNodeInfoRequestBody) - } - - err = l.body.FromGRPCMessage(body) - if err != nil { - return err - } - } - - return l.RequestHeaders.FromMessage(v) -} - -func (l *LocalNodeInfoResponseBody) ToGRPCMessage() grpc.Message { - var m *netmap.LocalNodeInfoResponse_Body - - if l != nil { - m = new(netmap.LocalNodeInfoResponse_Body) - - m.SetVersion(l.version.ToGRPCMessage().(*refsGRPC.Version)) - m.SetNodeInfo(l.nodeInfo.ToGRPCMessage().(*netmap.NodeInfo)) - } - - return m -} - -func (l *LocalNodeInfoResponseBody) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*netmap.LocalNodeInfoResponse_Body) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var err error - - version := v.GetVersion() - if version == nil { - l.version = nil - } else { - if l.version == nil { - l.version = new(refs.Version) - } - - err = l.version.FromGRPCMessage(version) - if err != nil { - return err - } - } - - nodeInfo := v.GetNodeInfo() - if nodeInfo == nil { - l.nodeInfo = nil - } else { - if l.nodeInfo == nil { - l.nodeInfo = new(NodeInfo) - } - - err = l.nodeInfo.FromGRPCMessage(nodeInfo) - } - - return err -} - -func (l *LocalNodeInfoResponse) ToGRPCMessage() grpc.Message { - var m *netmap.LocalNodeInfoResponse - - if l != nil { - m = new(netmap.LocalNodeInfoResponse) - - m.SetBody(l.body.ToGRPCMessage().(*netmap.LocalNodeInfoResponse_Body)) - l.ResponseHeaders.ToMessage(m) - } - - return m -} - -func (l *LocalNodeInfoResponse) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*netmap.LocalNodeInfoResponse) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var err error - - body := v.GetBody() - if body == nil { - l.body = nil - } else { - if l.body == nil { - l.body = new(LocalNodeInfoResponseBody) - } - - err = l.body.FromGRPCMessage(body) - if err != nil { - return err - } - } - - return l.ResponseHeaders.FromMessage(v) -} - -func (x *NetworkParameter) ToGRPCMessage() grpc.Message { - var m *netmap.NetworkConfig_Parameter - - if x != nil { - m = new(netmap.NetworkConfig_Parameter) - - m.SetKey(x.k) - m.SetValue(x.v) - } - - return m -} - -func (x *NetworkParameter) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*netmap.NetworkConfig_Parameter) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - x.k = v.GetKey() - x.v = v.GetValue() - - return nil -} - -func (x *NetworkConfig) ToGRPCMessage() grpc.Message { - var m *netmap.NetworkConfig - - if x != nil { - m = new(netmap.NetworkConfig) - - var ps []*netmap.NetworkConfig_Parameter - - if ln := len(x.ps); ln > 0 { - ps = make([]*netmap.NetworkConfig_Parameter, 0, ln) - - for i := 0; i < ln; i++ { - ps = append(ps, x.ps[i].ToGRPCMessage().(*netmap.NetworkConfig_Parameter)) - } - } - - m.SetParameters(ps) - } - - return m -} - -func (x *NetworkConfig) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*netmap.NetworkConfig) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var ( - ps []NetworkParameter - psV2 = v.GetParameters() - ) - - if psV2 != nil { - ln := len(psV2) - - ps = make([]NetworkParameter, ln) - - for i := 0; i < ln; i++ { - if psV2[i] != nil { - if err := ps[i].FromGRPCMessage(psV2[i]); err != nil { - return err - } - } - } - } - - x.ps = ps - - return nil -} - -func (i *NetworkInfo) ToGRPCMessage() grpc.Message { - var m *netmap.NetworkInfo - - if i != nil { - m = new(netmap.NetworkInfo) - - m.SetMagicNumber(i.magicNum) - m.SetCurrentEpoch(i.curEpoch) - m.SetMsPerBlock(i.msPerBlock) - m.SetNetworkConfig(i.netCfg.ToGRPCMessage().(*netmap.NetworkConfig)) - } - - return m -} - -func (i *NetworkInfo) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*netmap.NetworkInfo) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var err error - - netCfg := v.GetNetworkConfig() - if netCfg == nil { - i.netCfg = nil - } else { - if i.netCfg == nil { - i.netCfg = new(NetworkConfig) - } - - err = i.netCfg.FromGRPCMessage(netCfg) - if err != nil { - return err - } - } - - i.magicNum = v.GetMagicNumber() - i.curEpoch = v.GetCurrentEpoch() - i.msPerBlock = v.GetMsPerBlock() - - return nil -} - -func (l *NetworkInfoRequestBody) ToGRPCMessage() grpc.Message { - var m *netmap.NetworkInfoRequest_Body - - if l != nil { - m = new(netmap.NetworkInfoRequest_Body) - } - - return m -} - -func (l *NetworkInfoRequestBody) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*netmap.NetworkInfoRequest_Body) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - return nil -} - -func (l *NetworkInfoRequest) ToGRPCMessage() grpc.Message { - var m *netmap.NetworkInfoRequest - - if l != nil { - m = new(netmap.NetworkInfoRequest) - - m.SetBody(l.body.ToGRPCMessage().(*netmap.NetworkInfoRequest_Body)) - l.RequestHeaders.ToMessage(m) - } - - return m -} - -func (l *NetworkInfoRequest) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*netmap.NetworkInfoRequest) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var err error - - body := v.GetBody() - if body == nil { - l.body = nil - } else { - if l.body == nil { - l.body = new(NetworkInfoRequestBody) - } - - err = l.body.FromGRPCMessage(body) - if err != nil { - return err - } - } - - return l.RequestHeaders.FromMessage(v) -} - -func (i *NetworkInfoResponseBody) ToGRPCMessage() grpc.Message { - var m *netmap.NetworkInfoResponse_Body - - if i != nil { - m = new(netmap.NetworkInfoResponse_Body) - - m.SetNetworkInfo(i.netInfo.ToGRPCMessage().(*netmap.NetworkInfo)) - } - - return m -} - -func (i *NetworkInfoResponseBody) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*netmap.NetworkInfoResponse_Body) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var err error - - netInfo := v.GetNetworkInfo() - if netInfo == nil { - i.netInfo = nil - } else { - if i.netInfo == nil { - i.netInfo = new(NetworkInfo) - } - - err = i.netInfo.FromGRPCMessage(netInfo) - } - - return err -} - -func (l *NetworkInfoResponse) ToGRPCMessage() grpc.Message { - var m *netmap.NetworkInfoResponse - - if l != nil { - m = new(netmap.NetworkInfoResponse) - - m.SetBody(l.body.ToGRPCMessage().(*netmap.NetworkInfoResponse_Body)) - l.ResponseHeaders.ToMessage(m) - } - - return m -} - -func (l *NetworkInfoResponse) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*netmap.NetworkInfoResponse) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var err error - - body := v.GetBody() - if body == nil { - l.body = nil - } else { - if l.body == nil { - l.body = new(NetworkInfoResponseBody) - } - - err = l.body.FromGRPCMessage(body) - if err != nil { - return err - } - } - - return l.ResponseHeaders.FromMessage(v) -} - -func (x *NetMap) ToGRPCMessage() grpc.Message { - var m *netmap.Netmap - - if x != nil { - m = new(netmap.Netmap) - - m.SetEpoch(x.epoch) - - if x.nodes != nil { - nodes := make([]*netmap.NodeInfo, len(x.nodes)) - - for i := range x.nodes { - nodes[i] = x.nodes[i].ToGRPCMessage().(*netmap.NodeInfo) - } - - m.SetNodes(nodes) - } - } - - return m -} - -func (x *NetMap) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*netmap.Netmap) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var err error - - nodes := v.GetNodes() - if nodes == nil { - x.nodes = nil - } else { - x.nodes = make([]NodeInfo, len(nodes)) - - for i := range nodes { - err = x.nodes[i].FromGRPCMessage(nodes[i]) - if err != nil { - return err - } - } - } - - x.epoch = v.GetEpoch() - - return nil -} - -func (x *SnapshotRequestBody) ToGRPCMessage() grpc.Message { - var m *netmap.NetmapSnapshotRequest_Body - - if x != nil { - m = new(netmap.NetmapSnapshotRequest_Body) - } - - return m -} - -func (x *SnapshotRequestBody) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*netmap.NetmapSnapshotRequest_Body) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - return nil -} - -func (x *SnapshotRequest) ToGRPCMessage() grpc.Message { - var m *netmap.NetmapSnapshotRequest - - if x != nil { - m = new(netmap.NetmapSnapshotRequest) - - m.SetBody(x.body.ToGRPCMessage().(*netmap.NetmapSnapshotRequest_Body)) - x.RequestHeaders.ToMessage(m) - } - - return m -} - -func (x *SnapshotRequest) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*netmap.NetmapSnapshotRequest) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var err error - - body := v.GetBody() - if body == nil { - x.body = nil - } else { - if x.body == nil { - x.body = new(SnapshotRequestBody) - } - - err = x.body.FromGRPCMessage(body) - if err != nil { - return err - } - } - - return x.RequestHeaders.FromMessage(v) -} - -func (x *SnapshotResponseBody) ToGRPCMessage() grpc.Message { - var m *netmap.NetmapSnapshotResponse_Body - - if x != nil { - m = new(netmap.NetmapSnapshotResponse_Body) - - m.SetNetmap(x.netMap.ToGRPCMessage().(*netmap.Netmap)) - } - - return m -} - -func (x *SnapshotResponseBody) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*netmap.NetmapSnapshotResponse_Body) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var err error - - netMap := v.GetNetmap() - if netMap == nil { - x.netMap = nil - } else { - if x.netMap == nil { - x.netMap = new(NetMap) - } - - err = x.netMap.FromGRPCMessage(netMap) - } - - return err -} - -func (x *SnapshotResponse) ToGRPCMessage() grpc.Message { - var m *netmap.NetmapSnapshotResponse - - if x != nil { - m = new(netmap.NetmapSnapshotResponse) - - m.SetBody(x.body.ToGRPCMessage().(*netmap.NetmapSnapshotResponse_Body)) - x.ResponseHeaders.ToMessage(m) - } - - return m -} - -func (x *SnapshotResponse) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*netmap.NetmapSnapshotResponse) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var err error - - body := v.GetBody() - if body == nil { - x.body = nil - } else { - if x.body == nil { - x.body = new(SnapshotResponseBody) - } - - err = x.body.FromGRPCMessage(body) - if err != nil { - return err - } - } - - return x.ResponseHeaders.FromMessage(v) -} diff --git a/netmap/grpc/service.pb.go b/netmap/grpc/service.pb.go index acfe43c..a932e0e 100644 Binary files a/netmap/grpc/service.pb.go and b/netmap/grpc/service.pb.go differ diff --git a/netmap/grpc/service_frostfs.pb.go b/netmap/grpc/service_frostfs.pb.go new file mode 100644 index 0000000..aaaab81 Binary files /dev/null and b/netmap/grpc/service_frostfs.pb.go differ diff --git a/netmap/grpc/service_grpc.pb.go b/netmap/grpc/service_grpc.pb.go index 3834c3d..233676d 100644 Binary files a/netmap/grpc/service_grpc.pb.go and b/netmap/grpc/service_grpc.pb.go differ diff --git a/netmap/grpc/types.go b/netmap/grpc/types.go index f312bbb..f7a0753 100644 --- a/netmap/grpc/types.go +++ b/netmap/grpc/types.go @@ -1,5 +1,10 @@ package netmap +// SetUnique of placement policy. +func (m *PlacementPolicy) SetUnique(unique bool) { + m.Unique = unique +} + // SetReplicas of placement policy. func (m *PlacementPolicy) SetReplicas(v []*Replica) { m.Replicas = v @@ -122,6 +127,29 @@ func (m *NodeInfo) SetState(v NodeInfo_State) { m.State = v } +// NumberOfAddresses returns number of network addresses of the node. +func (ni *NodeInfo) NumberOfAddresses() int { + if ni != nil { + return len(ni.Addresses) + } + + return 0 +} + +// IterateAddresses iterates over network addresses of the node. +// Breaks iteration on f's true return. +// +// Handler should not be nil. +func (ni *NodeInfo) IterateAddresses(f func(string) bool) { + if ni != nil { + for i := range ni.Addresses { + if f(ni.Addresses[i]) { + break + } + } + } +} + // SetCurrentEpoch sets number of the current epoch. func (x *NetworkInfo) SetCurrentEpoch(v uint64) { x.CurrentEpoch = v @@ -196,6 +224,29 @@ func (x *NetworkConfig) SetParameters(v []*NetworkConfig_Parameter) { x.Parameters = v } +// NumberOfParameters returns number of network parameters. +func (x *NetworkConfig) NumberOfParameters() int { + if x != nil { + return len(x.GetParameters()) + } + + return 0 +} + +// IterateParameters iterates over network parameters. +// Breaks iteration on f's true return. +// +// Handler must not be nil. +func (x *NetworkConfig) IterateParameters(f func(*NetworkConfig_Parameter) bool) { + if x != nil { + for i := range x.Parameters { + if f(x.Parameters[i]) { + break + } + } + } +} + // SetEpoch sets revision number of the Netmap. func (x *Netmap) SetEpoch(v uint64) { x.Epoch = v diff --git a/netmap/grpc/types_frostfs.pb.go b/netmap/grpc/types_frostfs.pb.go new file mode 100644 index 0000000..4e9366d Binary files /dev/null and b/netmap/grpc/types_frostfs.pb.go differ diff --git a/netmap/json.go b/netmap/json.go deleted file mode 100644 index 6eacb96..0000000 --- a/netmap/json.go +++ /dev/null @@ -1,62 +0,0 @@ -package netmap - -import ( - netmap "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/netmap/grpc" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message" -) - -func (p *PlacementPolicy) MarshalJSON() ([]byte, error) { - return message.MarshalJSON(p) -} - -func (p *PlacementPolicy) UnmarshalJSON(data []byte) error { - return message.UnmarshalJSON(p, data, new(netmap.PlacementPolicy)) -} - -func (f *Filter) MarshalJSON() ([]byte, error) { - return message.MarshalJSON(f) -} - -func (f *Filter) UnmarshalJSON(data []byte) error { - return message.UnmarshalJSON(f, data, new(netmap.Filter)) -} - -func (s *Selector) MarshalJSON() ([]byte, error) { - return message.MarshalJSON(s) -} - -func (s *Selector) UnmarshalJSON(data []byte) error { - return message.UnmarshalJSON(s, data, new(netmap.Selector)) -} - -func (r *Replica) MarshalJSON() ([]byte, error) { - return message.MarshalJSON(r) -} - -func (r *Replica) UnmarshalJSON(data []byte) error { - return message.UnmarshalJSON(r, data, new(netmap.Replica)) -} - -func (a *Attribute) MarshalJSON() ([]byte, error) { - return message.MarshalJSON(a) -} - -func (a *Attribute) UnmarshalJSON(data []byte) error { - return message.UnmarshalJSON(a, data, new(netmap.NodeInfo_Attribute)) -} - -func (ni *NodeInfo) MarshalJSON() ([]byte, error) { - return message.MarshalJSON(ni) -} - -func (ni *NodeInfo) UnmarshalJSON(data []byte) error { - return message.UnmarshalJSON(ni, data, new(netmap.NodeInfo)) -} - -func (i *NetworkInfo) MarshalJSON() ([]byte, error) { - return message.MarshalJSON(i) -} - -func (i *NetworkInfo) UnmarshalJSON(data []byte) error { - return message.UnmarshalJSON(i, data, new(netmap.NetworkInfo)) -} diff --git a/netmap/marshal.go b/netmap/marshal.go deleted file mode 100644 index bf559ce..0000000 --- a/netmap/marshal.go +++ /dev/null @@ -1,554 +0,0 @@ -package netmap - -import ( - netmap "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/netmap/grpc" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message" - protoutil "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/util/proto" -) - -const ( - nameFilterField = 1 - keyFilterField = 2 - opFilterField = 3 - valueFilterField = 4 - filtersFilterField = 5 - - nameSelectorField = 1 - countSelectorField = 2 - clauseSelectorField = 3 - attributeSelectorField = 4 - filterSelectorField = 5 - - countReplicaField = 1 - selectorReplicaField = 2 - - replicasPolicyField = 1 - backupPolicyField = 2 - selectorsPolicyField = 3 - filtersPolicyField = 4 - uniquePolicyField = 5 - - keyAttributeField = 1 - valueAttributeField = 2 - parentsAttributeField = 3 - - keyNodeInfoField = 1 - addressNodeInfoField = 2 - attributesNodeInfoField = 3 - stateNodeInfoField = 4 - - versionInfoResponseBodyField = 1 - nodeInfoResponseBodyField = 2 -) - -func (f *Filter) StableMarshal(buf []byte) []byte { - if f == nil { - return []byte{} - } - - if buf == nil { - buf = make([]byte, f.StableSize()) - } - - var offset int - - offset += protoutil.StringMarshal(nameFilterField, buf[offset:], f.name) - offset += protoutil.StringMarshal(keyFilterField, buf[offset:], f.key) - offset += protoutil.EnumMarshal(opFilterField, buf[offset:], int32(f.op)) - offset += protoutil.StringMarshal(valueFilterField, buf[offset:], f.value) - - for i := range f.filters { - offset += protoutil.NestedStructureMarshal(filtersFilterField, buf[offset:], &f.filters[i]) - } - - return buf -} - -func (f *Filter) StableSize() (size int) { - size += protoutil.StringSize(nameFilterField, f.name) - size += protoutil.StringSize(keyFilterField, f.key) - size += protoutil.EnumSize(opFilterField, int32(f.op)) - size += protoutil.StringSize(valueFilterField, f.value) - for i := range f.filters { - size += protoutil.NestedStructureSize(filtersFilterField, &f.filters[i]) - } - - return size -} - -func (f *Filter) Unmarshal(data []byte) error { - return message.Unmarshal(f, data, new(netmap.Filter)) -} - -func (s *Selector) StableMarshal(buf []byte) []byte { - if s == nil { - return []byte{} - } - - if buf == nil { - buf = make([]byte, s.StableSize()) - } - - var offset int - - offset += protoutil.StringMarshal(nameSelectorField, buf[offset:], s.name) - offset += protoutil.UInt32Marshal(countSelectorField, buf[offset:], s.count) - offset += protoutil.EnumMarshal(clauseSelectorField, buf[offset:], int32(s.clause)) - offset += protoutil.StringMarshal(attributeSelectorField, buf[offset:], s.attribute) - protoutil.StringMarshal(filterSelectorField, buf[offset:], s.filter) - - return buf -} - -func (s *Selector) StableSize() (size int) { - size += protoutil.StringSize(nameSelectorField, s.name) - size += protoutil.UInt32Size(countSelectorField, s.count) - size += protoutil.EnumSize(countSelectorField, int32(s.clause)) - size += protoutil.StringSize(attributeSelectorField, s.attribute) - size += protoutil.StringSize(filterSelectorField, s.filter) - - return size -} - -func (s *Selector) Unmarshal(data []byte) error { - return message.Unmarshal(s, data, new(netmap.Selector)) -} - -func (r *Replica) StableMarshal(buf []byte) []byte { - if r == nil { - return []byte{} - } - - if buf == nil { - buf = make([]byte, r.StableSize()) - } - - var offset int - - offset += protoutil.UInt32Marshal(countReplicaField, buf[offset:], r.count) - protoutil.StringMarshal(selectorReplicaField, buf[offset:], r.selector) - - return buf -} - -func (r *Replica) StableSize() (size int) { - size += protoutil.UInt32Size(countReplicaField, r.count) - size += protoutil.StringSize(selectorReplicaField, r.selector) - - return size -} - -func (r *Replica) Unmarshal(data []byte) error { - return message.Unmarshal(r, data, new(netmap.Replica)) -} - -func (p *PlacementPolicy) StableMarshal(buf []byte) []byte { - if p == nil { - return []byte{} - } - - if buf == nil { - buf = make([]byte, p.StableSize()) - } - - var offset int - - for i := range p.replicas { - offset += protoutil.NestedStructureMarshal(replicasPolicyField, buf[offset:], &p.replicas[i]) - } - - offset += protoutil.UInt32Marshal(backupPolicyField, buf[offset:], p.backupFactor) - - for i := range p.selectors { - offset += protoutil.NestedStructureMarshal(selectorsPolicyField, buf[offset:], &p.selectors[i]) - } - - for i := range p.filters { - offset += protoutil.NestedStructureMarshal(filtersPolicyField, buf[offset:], &p.filters[i]) - } - - protoutil.BoolMarshal(uniquePolicyField, buf[offset:], p.unique) - - return buf -} - -func (p *PlacementPolicy) StableSize() (size int) { - for i := range p.replicas { - size += protoutil.NestedStructureSize(replicasPolicyField, &p.replicas[i]) - } - - size += protoutil.UInt32Size(backupPolicyField, p.backupFactor) - - for i := range p.selectors { - size += protoutil.NestedStructureSize(selectorsPolicyField, &p.selectors[i]) - } - - for i := range p.filters { - size += protoutil.NestedStructureSize(filtersPolicyField, &p.filters[i]) - } - - size += protoutil.BoolSize(uniquePolicyField, p.unique) - - return size -} - -func (p *PlacementPolicy) Unmarshal(data []byte) error { - return message.Unmarshal(p, data, new(netmap.PlacementPolicy)) -} - -func (a *Attribute) StableMarshal(buf []byte) []byte { - if a == nil { - return []byte{} - } - - if buf == nil { - buf = make([]byte, a.StableSize()) - } - - var offset int - - offset += protoutil.StringMarshal(keyAttributeField, buf[offset:], a.key) - offset += protoutil.StringMarshal(valueAttributeField, buf[offset:], a.value) - - for i := range a.parents { - offset += protoutil.StringMarshal(parentsAttributeField, buf[offset:], a.parents[i]) - } - - return buf -} - -func (a *Attribute) StableSize() (size int) { - if a == nil { - return 0 - } - - size += protoutil.StringSize(keyAttributeField, a.key) - size += protoutil.StringSize(valueAttributeField, a.value) - - for i := range a.parents { - size += protoutil.StringSize(parentsAttributeField, a.parents[i]) - } - - return size -} - -func (a *Attribute) Unmarshal(data []byte) error { - return message.Unmarshal(a, data, new(netmap.NodeInfo_Attribute)) -} - -func (ni *NodeInfo) StableMarshal(buf []byte) []byte { - if ni == nil { - return []byte{} - } - - if buf == nil { - buf = make([]byte, ni.StableSize()) - } - - var offset int - - offset += protoutil.BytesMarshal(keyNodeInfoField, buf[offset:], ni.publicKey) - offset += protoutil.RepeatedStringMarshal(addressNodeInfoField, buf[offset:], ni.addresses) - - for i := range ni.attributes { - offset += protoutil.NestedStructureMarshal(attributesNodeInfoField, buf[offset:], &ni.attributes[i]) - } - - protoutil.EnumMarshal(stateNodeInfoField, buf[offset:], int32(ni.state)) - - return buf -} - -func (ni *NodeInfo) StableSize() (size int) { - if ni == nil { - return 0 - } - - size += protoutil.BytesSize(keyNodeInfoField, ni.publicKey) - size += protoutil.RepeatedStringSize(addressNodeInfoField, ni.addresses) - - for i := range ni.attributes { - size += protoutil.NestedStructureSize(attributesNodeInfoField, &ni.attributes[i]) - } - - size += protoutil.EnumSize(stateNodeInfoField, int32(ni.state)) - - return size -} - -func (ni *NodeInfo) Unmarshal(data []byte) error { - return message.Unmarshal(ni, data, new(netmap.NodeInfo)) -} - -func (l *LocalNodeInfoRequestBody) StableMarshal(_ []byte) []byte { - return nil -} - -func (l *LocalNodeInfoRequestBody) StableSize() (size int) { - return 0 -} - -func (l *LocalNodeInfoRequestBody) Unmarshal([]byte) error { - return nil -} - -func (l *LocalNodeInfoResponseBody) StableMarshal(buf []byte) []byte { - if l == nil { - return []byte{} - } - - if buf == nil { - buf = make([]byte, l.StableSize()) - } - - var offset int - - offset += protoutil.NestedStructureMarshal(versionInfoResponseBodyField, buf[offset:], l.version) - protoutil.NestedStructureMarshal(nodeInfoResponseBodyField, buf[offset:], l.nodeInfo) - - return buf -} - -func (l *LocalNodeInfoResponseBody) StableSize() (size int) { - if l == nil { - return 0 - } - - size += protoutil.NestedStructureSize(versionInfoResponseBodyField, l.version) - size += protoutil.NestedStructureSize(nodeInfoResponseBodyField, l.nodeInfo) - - return size -} - -func (l *LocalNodeInfoResponseBody) Unmarshal(data []byte) error { - return message.Unmarshal(l, data, new(netmap.LocalNodeInfoResponse_Body)) -} - -const ( - _ = iota - netPrmKeyFNum - netPrmValFNum -) - -func (x *NetworkParameter) StableMarshal(buf []byte) []byte { - if x == nil { - return []byte{} - } - - if buf == nil { - buf = make([]byte, x.StableSize()) - } - - var offset int - - offset += protoutil.BytesMarshal(netPrmKeyFNum, buf[offset:], x.k) - protoutil.BytesMarshal(netPrmValFNum, buf[offset:], x.v) - - return buf -} - -func (x *NetworkParameter) StableSize() (size int) { - if x == nil { - return 0 - } - - size += protoutil.BytesSize(netPrmKeyFNum, x.k) - size += protoutil.BytesSize(netPrmValFNum, x.v) - - return size -} - -const ( - _ = iota - netCfgPrmsFNum -) - -func (x *NetworkConfig) StableMarshal(buf []byte) []byte { - if x == nil { - return []byte{} - } - - if buf == nil { - buf = make([]byte, x.StableSize()) - } - - var offset int - - for i := range x.ps { - offset += protoutil.NestedStructureMarshal(netCfgPrmsFNum, buf[offset:], &x.ps[i]) - } - - return buf -} - -func (x *NetworkConfig) StableSize() (size int) { - if x == nil { - return 0 - } - - for i := range x.ps { - size += protoutil.NestedStructureSize(netCfgPrmsFNum, &x.ps[i]) - } - - return size -} - -const ( - _ = iota - netInfoCurEpochFNum - netInfoMagicNumFNum - netInfoMSPerBlockFNum - netInfoCfgFNum -) - -func (i *NetworkInfo) StableMarshal(buf []byte) []byte { - if i == nil { - return []byte{} - } - - if buf == nil { - buf = make([]byte, i.StableSize()) - } - - var offset int - - offset += protoutil.UInt64Marshal(netInfoCurEpochFNum, buf[offset:], i.curEpoch) - offset += protoutil.UInt64Marshal(netInfoMagicNumFNum, buf[offset:], i.magicNum) - offset += protoutil.Int64Marshal(netInfoMSPerBlockFNum, buf[offset:], i.msPerBlock) - protoutil.NestedStructureMarshal(netInfoCfgFNum, buf[offset:], i.netCfg) - - return buf -} - -func (i *NetworkInfo) StableSize() (size int) { - if i == nil { - return 0 - } - - size += protoutil.UInt64Size(netInfoCurEpochFNum, i.curEpoch) - size += protoutil.UInt64Size(netInfoMagicNumFNum, i.magicNum) - size += protoutil.Int64Size(netInfoMSPerBlockFNum, i.msPerBlock) - size += protoutil.NestedStructureSize(netInfoCfgFNum, i.netCfg) - - return size -} - -func (i *NetworkInfo) Unmarshal(data []byte) error { - return message.Unmarshal(i, data, new(netmap.NetworkInfo)) -} - -func (l *NetworkInfoRequestBody) StableMarshal(_ []byte) []byte { - return nil -} - -func (l *NetworkInfoRequestBody) StableSize() (size int) { - return 0 -} - -func (l *NetworkInfoRequestBody) Unmarshal(data []byte) error { - return message.Unmarshal(l, data, new(netmap.NetworkInfoRequest_Body)) -} - -const ( - _ = iota - netInfoRespBodyNetInfoFNum -) - -func (i *NetworkInfoResponseBody) StableMarshal(buf []byte) []byte { - if i == nil { - return []byte{} - } - - if buf == nil { - buf = make([]byte, i.StableSize()) - } - - protoutil.NestedStructureMarshal(netInfoRespBodyNetInfoFNum, buf, i.netInfo) - - return buf -} - -func (i *NetworkInfoResponseBody) StableSize() (size int) { - if i == nil { - return 0 - } - - size += protoutil.NestedStructureSize(netInfoRespBodyNetInfoFNum, i.netInfo) - - return size -} - -func (i *NetworkInfoResponseBody) Unmarshal(data []byte) error { - return message.Unmarshal(i, data, new(netmap.NetworkInfoResponse_Body)) -} - -const ( - _ = iota - fNumNetMapEpoch - fNumNetMapNodes -) - -func (x *NetMap) StableMarshal(buf []byte) []byte { - if x == nil { - return []byte{} - } - - if buf == nil { - buf = make([]byte, x.StableSize()) - } - - offset := protoutil.UInt64Marshal(fNumNetMapEpoch, buf, x.epoch) - - for i := range x.nodes { - offset += protoutil.NestedStructureMarshal(fNumNetMapNodes, buf[offset:], &x.nodes[i]) - } - - return buf -} - -func (x *NetMap) StableSize() (size int) { - if x != nil { - size = protoutil.UInt64Size(fNumNetMapEpoch, x.epoch) - - for i := range x.nodes { - size += protoutil.NestedStructureSize(fNumNetMapNodes, &x.nodes[i]) - } - } - - return -} - -func (x *SnapshotRequestBody) StableMarshal([]byte) []byte { - return nil -} - -func (x *SnapshotRequestBody) StableSize() int { - return 0 -} - -const ( - _ = iota - fNumSnapshotResponseBodyNetMap -) - -func (x *SnapshotResponseBody) StableMarshal(buf []byte) []byte { - if x == nil { - return []byte{} - } - - if buf == nil { - buf = make([]byte, x.StableSize()) - } - - protoutil.NestedStructureMarshal(fNumSnapshotResponseBodyNetMap, buf, x.netMap) - - return buf -} - -func (x *SnapshotResponseBody) StableSize() (size int) { - if x != nil { - size = protoutil.NestedStructureSize(fNumSnapshotResponseBodyNetMap, x.netMap) - } - - return -} diff --git a/netmap/message_test.go b/netmap/message_test.go index fe78ffe..8090bb1 100644 --- a/netmap/message_test.go +++ b/netmap/message_test.go @@ -4,29 +4,29 @@ import ( "testing" netmaptest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/netmap/test" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message" messagetest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message/test" + "google.golang.org/protobuf/proto" ) func TestMessageConvert(t *testing.T) { messagetest.TestRPCMessage(t, - func(empty bool) message.Message { return netmaptest.GenerateFilter(empty) }, - func(empty bool) message.Message { return netmaptest.GenerateSelector(empty) }, - func(empty bool) message.Message { return netmaptest.GenerateReplica(empty) }, - func(empty bool) message.Message { return netmaptest.GeneratePlacementPolicy(empty) }, - func(empty bool) message.Message { return netmaptest.GenerateAttribute(empty) }, - func(empty bool) message.Message { return netmaptest.GenerateNodeInfo(empty) }, - func(empty bool) message.Message { return netmaptest.GenerateLocalNodeInfoRequest(empty) }, - func(empty bool) message.Message { return netmaptest.GenerateLocalNodeInfoResponseBody(empty) }, - func(empty bool) message.Message { return netmaptest.GenerateNetworkParameter(empty) }, - func(empty bool) message.Message { return netmaptest.GenerateNetworkConfig(empty) }, - func(empty bool) message.Message { return netmaptest.GenerateNetworkInfo(empty) }, - func(empty bool) message.Message { return netmaptest.GenerateNetworkInfoRequest(empty) }, - func(empty bool) message.Message { return netmaptest.GenerateNetworkInfoResponseBody(empty) }, - func(empty bool) message.Message { return netmaptest.GenerateNetMap(empty) }, - func(empty bool) message.Message { return netmaptest.GenerateSnapshotRequestBody(empty) }, - func(empty bool) message.Message { return netmaptest.GenerateSnapshotRequest(empty) }, - func(empty bool) message.Message { return netmaptest.GenerateSnapshotResponseBody(empty) }, - func(empty bool) message.Message { return netmaptest.GenerateSnapshotResponse(empty) }, + func(empty bool) proto.Message { return netmaptest.GenerateFilter(empty) }, + func(empty bool) proto.Message { return netmaptest.GenerateSelector(empty) }, + func(empty bool) proto.Message { return netmaptest.GenerateReplica(empty) }, + func(empty bool) proto.Message { return netmaptest.GeneratePlacementPolicy(empty) }, + func(empty bool) proto.Message { return netmaptest.GenerateAttribute(empty) }, + func(empty bool) proto.Message { return netmaptest.GenerateNodeInfo(empty) }, + func(empty bool) proto.Message { return netmaptest.GenerateLocalNodeInfoRequest(empty) }, + func(empty bool) proto.Message { return netmaptest.GenerateLocalNodeInfoResponseBody(empty) }, + func(empty bool) proto.Message { return netmaptest.GenerateNetworkParameter(empty) }, + func(empty bool) proto.Message { return netmaptest.GenerateNetworkConfig(empty) }, + func(empty bool) proto.Message { return netmaptest.GenerateNetworkInfo(empty) }, + func(empty bool) proto.Message { return netmaptest.GenerateNetworkInfoRequest(empty) }, + func(empty bool) proto.Message { return netmaptest.GenerateNetworkInfoResponseBody(empty) }, + func(empty bool) proto.Message { return netmaptest.GenerateNetMap(empty) }, + func(empty bool) proto.Message { return netmaptest.GenerateSnapshotRequestBody(empty) }, + func(empty bool) proto.Message { return netmaptest.GenerateSnapshotRequest(empty) }, + func(empty bool) proto.Message { return netmaptest.GenerateSnapshotResponseBody(empty) }, + func(empty bool) proto.Message { return netmaptest.GenerateSnapshotResponse(empty) }, ) } diff --git a/netmap/string.go b/netmap/string.go deleted file mode 100644 index 1f00a55..0000000 --- a/netmap/string.go +++ /dev/null @@ -1,68 +0,0 @@ -package netmap - -import ( - netmap "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/netmap/grpc" -) - -// String returns string representation of Clause. -func (x Clause) String() string { - return ClauseToGRPCMessage(x).String() -} - -// FromString parses Clause from a string representation. -// It is a reverse action to String(). -// -// Returns true if s was parsed successfully. -func (x *Clause) FromString(s string) bool { - var g netmap.Clause - - ok := g.FromString(s) - - if ok { - *x = ClauseFromGRPCMessage(g) - } - - return ok -} - -// String returns string representation of Operation. -func (x Operation) String() string { - return OperationToGRPCMessage(x).String() -} - -// FromString parses Operation from a string representation. -// It is a reverse action to String(). -// -// Returns true if s was parsed successfully. -func (x *Operation) FromString(s string) bool { - var g netmap.Operation - - ok := g.FromString(s) - - if ok { - *x = OperationFromGRPCMessage(g) - } - - return ok -} - -// String returns string representation of NodeState. -func (x NodeState) String() string { - return NodeStateToGRPCMessage(x).String() -} - -// FromString parses NodeState from a string representation. -// It is a reverse action to String(). -// -// Returns true if s was parsed successfully. -func (x *NodeState) FromString(s string) bool { - var g netmap.NodeInfo_State - - ok := g.FromString(s) - - if ok { - *x = NodeStateFromRPCMessage(g) - } - - return ok -} diff --git a/netmap/test/generate.go b/netmap/test/generate.go index 400d24c..0ee9902 100644 --- a/netmap/test/generate.go +++ b/netmap/test/generate.go @@ -1,7 +1,7 @@ package netmaptest import ( - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/netmap" + netmap "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/netmap/grpc" refstest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs/test" sessiontest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/session/test" ) @@ -20,9 +20,9 @@ func generateFilter(empty, withSub bool) *netmap.Filter { m.SetOp(1) if withSub { - m.SetFilters([]netmap.Filter{ - *generateFilter(empty, false), - *generateFilter(empty, false), + m.SetFilters([]*netmap.Filter{ + generateFilter(empty, false), + generateFilter(empty, false), }) } } @@ -30,13 +30,13 @@ func generateFilter(empty, withSub bool) *netmap.Filter { return m } -func GenerateFilters(empty bool) []netmap.Filter { - var res []netmap.Filter +func GenerateFilters(empty bool) []*netmap.Filter { + var res []*netmap.Filter if !empty { res = append(res, - *GenerateFilter(false), - *GenerateFilter(false), + GenerateFilter(false), + GenerateFilter(false), ) } @@ -57,13 +57,13 @@ func GenerateSelector(empty bool) *netmap.Selector { return m } -func GenerateSelectors(empty bool) []netmap.Selector { - var res []netmap.Selector +func GenerateSelectors(empty bool) []*netmap.Selector { + var res []*netmap.Selector if !empty { res = append(res, - *GenerateSelector(false), - *GenerateSelector(false), + GenerateSelector(false), + GenerateSelector(false), ) } @@ -81,13 +81,13 @@ func GenerateReplica(empty bool) *netmap.Replica { return m } -func GenerateReplicas(empty bool) []netmap.Replica { - var res []netmap.Replica +func GenerateReplicas(empty bool) []*netmap.Replica { + var res []*netmap.Replica if !empty { res = append(res, - *GenerateReplica(false), - *GenerateReplica(false), + GenerateReplica(false), + GenerateReplica(false), ) } @@ -107,8 +107,8 @@ func GeneratePlacementPolicy(empty bool) *netmap.PlacementPolicy { return m } -func GenerateAttribute(empty bool) *netmap.Attribute { - m := new(netmap.Attribute) +func GenerateAttribute(empty bool) *netmap.NodeInfo_Attribute { + m := new(netmap.NodeInfo_Attribute) if !empty { m.SetKey("attribute key") @@ -118,13 +118,13 @@ func GenerateAttribute(empty bool) *netmap.Attribute { return m } -func GenerateAttributes(empty bool) []netmap.Attribute { - var res []netmap.Attribute +func GenerateAttributes(empty bool) []*netmap.NodeInfo_Attribute { + var res []*netmap.NodeInfo_Attribute if !empty { res = append(res, - *GenerateAttribute(false), - *GenerateAttribute(false), + GenerateAttribute(false), + GenerateAttribute(false), ) } @@ -135,7 +135,7 @@ func GenerateNodeInfo(empty bool) *netmap.NodeInfo { m := new(netmap.NodeInfo) if !empty { - m.SetAddresses("node address", "node address 2") + m.SetAddresses([]string{"node address", "node address 2"}) m.SetPublicKey([]byte{1, 2, 3}) m.SetState(33) m.SetAttributes(GenerateAttributes(empty)) @@ -144,8 +144,8 @@ func GenerateNodeInfo(empty bool) *netmap.NodeInfo { return m } -func GenerateLocalNodeInfoRequestBody(_ bool) *netmap.LocalNodeInfoRequestBody { - m := new(netmap.LocalNodeInfoRequestBody) +func GenerateLocalNodeInfoRequestBody(_ bool) *netmap.LocalNodeInfoRequest_Body { + m := new(netmap.LocalNodeInfoRequest_Body) return m } @@ -158,13 +158,13 @@ func GenerateLocalNodeInfoRequest(empty bool) *netmap.LocalNodeInfoRequest { } m.SetMetaHeader(sessiontest.GenerateRequestMetaHeader(empty)) - m.SetVerificationHeader(sessiontest.GenerateRequestVerificationHeader(empty)) + m.SetVerifyHeader(sessiontest.GenerateRequestVerificationHeader(empty)) return m } -func GenerateLocalNodeInfoResponseBody(empty bool) *netmap.LocalNodeInfoResponseBody { - m := new(netmap.LocalNodeInfoResponseBody) +func GenerateLocalNodeInfoResponseBody(empty bool) *netmap.LocalNodeInfoResponse_Body { + m := new(netmap.LocalNodeInfoResponse_Body) if !empty { m.SetNodeInfo(GenerateNodeInfo(false)) @@ -183,13 +183,13 @@ func GenerateLocalNodeInfoResponse(empty bool) *netmap.LocalNodeInfoResponse { } m.SetMetaHeader(sessiontest.GenerateResponseMetaHeader(empty)) - m.SetVerificationHeader(sessiontest.GenerateResponseVerificationHeader(empty)) + m.SetVerifyHeader(sessiontest.GenerateResponseVerificationHeader(empty)) return m } -func GenerateNetworkParameter(empty bool) *netmap.NetworkParameter { - m := new(netmap.NetworkParameter) +func GenerateNetworkParameter(empty bool) *netmap.NetworkConfig_Parameter { + m := new(netmap.NetworkConfig_Parameter) if !empty { m.SetKey([]byte("key")) @@ -203,10 +203,10 @@ func GenerateNetworkConfig(empty bool) *netmap.NetworkConfig { m := new(netmap.NetworkConfig) if !empty { - m.SetParameters( - *GenerateNetworkParameter(empty), - *GenerateNetworkParameter(empty), - ) + m.SetParameters([]*netmap.NetworkConfig_Parameter{ + GenerateNetworkParameter(empty), + GenerateNetworkParameter(empty), + }) } return m @@ -225,8 +225,8 @@ func GenerateNetworkInfo(empty bool) *netmap.NetworkInfo { return m } -func GenerateNetworkInfoRequestBody(_ bool) *netmap.NetworkInfoRequestBody { - m := new(netmap.NetworkInfoRequestBody) +func GenerateNetworkInfoRequestBody(_ bool) *netmap.NetworkInfoRequest_Body { + m := new(netmap.NetworkInfoRequest_Body) return m } @@ -239,13 +239,13 @@ func GenerateNetworkInfoRequest(empty bool) *netmap.NetworkInfoRequest { } m.SetMetaHeader(sessiontest.GenerateRequestMetaHeader(empty)) - m.SetVerificationHeader(sessiontest.GenerateRequestVerificationHeader(empty)) + m.SetVerifyHeader(sessiontest.GenerateRequestVerificationHeader(empty)) return m } -func GenerateNetworkInfoResponseBody(empty bool) *netmap.NetworkInfoResponseBody { - m := new(netmap.NetworkInfoResponseBody) +func GenerateNetworkInfoResponseBody(empty bool) *netmap.NetworkInfoResponse_Body { + m := new(netmap.NetworkInfoResponse_Body) if !empty { m.SetNetworkInfo(GenerateNetworkInfo(false)) @@ -262,61 +262,61 @@ func GenerateNetworkInfoResponse(empty bool) *netmap.NetworkInfoResponse { } m.SetMetaHeader(sessiontest.GenerateResponseMetaHeader(empty)) - m.SetVerificationHeader(sessiontest.GenerateResponseVerificationHeader(empty)) + m.SetVerifyHeader(sessiontest.GenerateResponseVerificationHeader(empty)) return m } -func GenerateNetMap(empty bool) *netmap.NetMap { - m := new(netmap.NetMap) +func GenerateNetMap(empty bool) *netmap.Netmap { + m := new(netmap.Netmap) if !empty { m.SetEpoch(987) - m.SetNodes([]netmap.NodeInfo{ - *GenerateNodeInfo(false), - *GenerateNodeInfo(false), + m.SetNodes([]*netmap.NodeInfo{ + GenerateNodeInfo(false), + GenerateNodeInfo(false), }) } return m } -func GenerateSnapshotRequestBody(_ bool) *netmap.SnapshotRequestBody { - return new(netmap.SnapshotRequestBody) +func GenerateSnapshotRequestBody(_ bool) *netmap.NetmapSnapshotRequest_Body { + return new(netmap.NetmapSnapshotRequest_Body) } -func GenerateSnapshotRequest(empty bool) *netmap.SnapshotRequest { - m := new(netmap.SnapshotRequest) +func GenerateSnapshotRequest(empty bool) *netmap.NetmapSnapshotRequest { + m := new(netmap.NetmapSnapshotRequest) if !empty { m.SetBody(GenerateSnapshotRequestBody(false)) } m.SetMetaHeader(sessiontest.GenerateRequestMetaHeader(empty)) - m.SetVerificationHeader(sessiontest.GenerateRequestVerificationHeader(empty)) + m.SetVerifyHeader(sessiontest.GenerateRequestVerificationHeader(empty)) return m } -func GenerateSnapshotResponseBody(empty bool) *netmap.SnapshotResponseBody { - m := new(netmap.SnapshotResponseBody) +func GenerateSnapshotResponseBody(empty bool) *netmap.NetmapSnapshotResponse_Body { + m := new(netmap.NetmapSnapshotResponse_Body) if !empty { - m.SetNetMap(GenerateNetMap(false)) + m.SetNetmap(GenerateNetMap(false)) } return m } -func GenerateSnapshotResponse(empty bool) *netmap.SnapshotResponse { - m := new(netmap.SnapshotResponse) +func GenerateSnapshotResponse(empty bool) *netmap.NetmapSnapshotResponse { + m := new(netmap.NetmapSnapshotResponse) if !empty { m.SetBody(GenerateSnapshotResponseBody(false)) } m.SetMetaHeader(sessiontest.GenerateResponseMetaHeader(empty)) - m.SetVerificationHeader(sessiontest.GenerateResponseVerificationHeader(empty)) + m.SetVerifyHeader(sessiontest.GenerateResponseVerificationHeader(empty)) return m } diff --git a/netmap/types.go b/netmap/types.go deleted file mode 100644 index bda9ec6..0000000 --- a/netmap/types.go +++ /dev/null @@ -1,751 +0,0 @@ -package netmap - -import ( - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/session" -) - -type LocalNodeInfoRequest struct { - body *LocalNodeInfoRequestBody - - session.RequestHeaders -} - -type LocalNodeInfoResponse struct { - body *LocalNodeInfoResponseBody - - session.ResponseHeaders -} - -// NetworkInfoRequest is a structure of NetworkInfo request. -type NetworkInfoRequest struct { - body *NetworkInfoRequestBody - - session.RequestHeaders -} - -// NetworkInfoResponse is a structure of NetworkInfo response. -type NetworkInfoResponse struct { - body *NetworkInfoResponseBody - - session.ResponseHeaders -} - -type Filter struct { - name string - key string - op Operation - value string - filters []Filter -} - -type Selector struct { - name string - count uint32 - clause Clause - attribute string - filter string -} - -type Replica struct { - count uint32 - selector string -} - -type Operation uint32 - -type PlacementPolicy struct { - replicas []Replica - backupFactor uint32 - selectors []Selector - filters []Filter - unique bool -} - -// Attribute of storage node. -type Attribute struct { - key string - value string - parents []string -} - -// NodeInfo of storage node. -type NodeInfo struct { - publicKey []byte - addresses []string - attributes []Attribute - state NodeState -} - -// NodeState of storage node. -type NodeState uint32 - -// Clause of placement selector. -type Clause uint32 - -type LocalNodeInfoRequestBody struct{} - -type LocalNodeInfoResponseBody struct { - version *refs.Version - nodeInfo *NodeInfo -} - -const ( - UnspecifiedState NodeState = iota - Online - Offline - Maintenance -) - -const ( - UnspecifiedOperation Operation = iota - EQ - NE - GT - GE - LT - LE - OR - AND - NOT -) - -const ( - UnspecifiedClause Clause = iota - Same - Distinct -) - -func (f *Filter) GetFilters() []Filter { - if f != nil { - return f.filters - } - - return nil -} - -func (f *Filter) SetFilters(filters []Filter) { - f.filters = filters -} - -func (f *Filter) GetValue() string { - if f != nil { - return f.value - } - - return "" -} - -func (f *Filter) SetValue(value string) { - f.value = value -} - -func (f *Filter) GetOp() Operation { - if f != nil { - return f.op - } - return UnspecifiedOperation -} - -func (f *Filter) SetOp(op Operation) { - f.op = op -} - -func (f *Filter) GetKey() string { - if f != nil { - return f.key - } - - return "" -} - -func (f *Filter) SetKey(key string) { - f.key = key -} - -func (f *Filter) GetName() string { - if f != nil { - return f.name - } - - return "" -} - -func (f *Filter) SetName(name string) { - f.name = name -} - -func (s *Selector) GetFilter() string { - if s != nil { - return s.filter - } - - return "" -} - -func (s *Selector) SetFilter(filter string) { - s.filter = filter -} - -func (s *Selector) GetAttribute() string { - if s != nil { - return s.attribute - } - - return "" -} - -func (s *Selector) SetAttribute(attribute string) { - s.attribute = attribute -} - -func (s *Selector) GetClause() Clause { - if s != nil { - return s.clause - } - - return UnspecifiedClause -} - -func (s *Selector) SetClause(clause Clause) { - s.clause = clause -} - -func (s *Selector) GetCount() uint32 { - if s != nil { - return s.count - } - - return 0 -} - -func (s *Selector) SetCount(count uint32) { - s.count = count -} - -func (s *Selector) GetName() string { - if s != nil { - return s.name - } - - return "" -} - -func (s *Selector) SetName(name string) { - s.name = name -} - -func (r *Replica) GetSelector() string { - if r != nil { - return r.selector - } - - return "" -} - -func (r *Replica) SetSelector(selector string) { - r.selector = selector -} - -func (r *Replica) GetCount() uint32 { - if r != nil { - return r.count - } - - return 0 -} - -func (r *Replica) SetCount(count uint32) { - r.count = count -} - -func (p *PlacementPolicy) GetUnique() bool { - if p != nil { - return p.unique - } - return false -} - -func (p *PlacementPolicy) SetUnique(unique bool) { - p.unique = unique -} - -func (p *PlacementPolicy) GetFilters() []Filter { - if p != nil { - return p.filters - } - - return nil -} - -func (p *PlacementPolicy) SetFilters(filters []Filter) { - p.filters = filters -} - -func (p *PlacementPolicy) GetSelectors() []Selector { - if p != nil { - return p.selectors - } - - return nil -} - -func (p *PlacementPolicy) SetSelectors(selectors []Selector) { - p.selectors = selectors -} - -func (p *PlacementPolicy) GetContainerBackupFactor() uint32 { - if p != nil { - return p.backupFactor - } - - return 0 -} - -func (p *PlacementPolicy) SetContainerBackupFactor(backupFactor uint32) { - p.backupFactor = backupFactor -} - -func (p *PlacementPolicy) GetReplicas() []Replica { - return p.replicas -} - -func (p *PlacementPolicy) SetReplicas(replicas []Replica) { - p.replicas = replicas -} - -func (a *Attribute) GetKey() string { - if a != nil { - return a.key - } - - return "" -} - -func (a *Attribute) SetKey(v string) { - a.key = v -} - -func (a *Attribute) GetValue() string { - if a != nil { - return a.value - } - - return "" -} - -func (a *Attribute) SetValue(v string) { - a.value = v -} - -func (a *Attribute) GetParents() []string { - if a != nil { - return a.parents - } - - return nil -} - -func (a *Attribute) SetParents(parent []string) { - a.parents = parent -} - -func (ni *NodeInfo) GetPublicKey() []byte { - if ni != nil { - return ni.publicKey - } - - return nil -} - -func (ni *NodeInfo) SetPublicKey(v []byte) { - ni.publicKey = v -} - -// GetAddress returns node's network address. -// -// Deprecated: use IterateAddresses. -func (ni *NodeInfo) GetAddress() (addr string) { - ni.IterateAddresses(func(s string) bool { - addr = s - return true - }) - - return -} - -// SetAddress sets node's network address. -// -// Deprecated: use SetAddresses. -func (ni *NodeInfo) SetAddress(v string) { - ni.SetAddresses(v) -} - -// SetAddresses sets list of network addresses of the node. -func (ni *NodeInfo) SetAddresses(v ...string) { - ni.addresses = v -} - -// NumberOfAddresses returns number of network addresses of the node. -func (ni *NodeInfo) NumberOfAddresses() int { - if ni != nil { - return len(ni.addresses) - } - - return 0 -} - -// IterateAddresses iterates over network addresses of the node. -// Breaks iteration on f's true return. -// -// Handler should not be nil. -func (ni *NodeInfo) IterateAddresses(f func(string) bool) { - if ni != nil { - for i := range ni.addresses { - if f(ni.addresses[i]) { - break - } - } - } -} - -func (ni *NodeInfo) GetAttributes() []Attribute { - if ni != nil { - return ni.attributes - } - - return nil -} - -func (ni *NodeInfo) SetAttributes(v []Attribute) { - ni.attributes = v -} - -func (ni *NodeInfo) GetState() NodeState { - if ni != nil { - return ni.state - } - - return UnspecifiedState -} - -func (ni *NodeInfo) SetState(state NodeState) { - ni.state = state -} - -func (l *LocalNodeInfoResponseBody) GetVersion() *refs.Version { - if l != nil { - return l.version - } - - return nil -} - -func (l *LocalNodeInfoResponseBody) SetVersion(version *refs.Version) { - l.version = version -} - -func (l *LocalNodeInfoResponseBody) GetNodeInfo() *NodeInfo { - if l != nil { - return l.nodeInfo - } - - return nil -} - -func (l *LocalNodeInfoResponseBody) SetNodeInfo(nodeInfo *NodeInfo) { - l.nodeInfo = nodeInfo -} - -func (l *LocalNodeInfoRequest) GetBody() *LocalNodeInfoRequestBody { - if l != nil { - return l.body - } - return nil -} - -func (l *LocalNodeInfoRequest) SetBody(body *LocalNodeInfoRequestBody) { - l.body = body -} - -func (l *LocalNodeInfoResponse) GetBody() *LocalNodeInfoResponseBody { - if l != nil { - return l.body - } - return nil -} - -func (l *LocalNodeInfoResponse) SetBody(body *LocalNodeInfoResponseBody) { - l.body = body -} - -// NetworkParameter represents NeoFS network parameter. -type NetworkParameter struct { - k, v []byte -} - -// GetKey returns parameter key. -func (x *NetworkParameter) GetKey() []byte { - if x != nil { - return x.k - } - - return nil -} - -// SetKey sets parameter key. -func (x *NetworkParameter) SetKey(k []byte) { - x.k = k -} - -// GetValue returns parameter value. -func (x *NetworkParameter) GetValue() []byte { - if x != nil { - return x.v - } - - return nil -} - -// SetValue sets parameter value. -func (x *NetworkParameter) SetValue(v []byte) { - x.v = v -} - -// NetworkConfig represents NeoFS network configuration. -type NetworkConfig struct { - ps []NetworkParameter -} - -// NumberOfParameters returns number of network parameters. -func (x *NetworkConfig) NumberOfParameters() int { - if x != nil { - return len(x.ps) - } - - return 0 -} - -// IterateParameters iterates over network parameters. -// Breaks iteration on f's true return. -// -// Handler must not be nil. -func (x *NetworkConfig) IterateParameters(f func(*NetworkParameter) bool) { - if x != nil { - for i := range x.ps { - if f(&x.ps[i]) { - break - } - } - } -} - -// SetParameters sets list of network parameters. -func (x *NetworkConfig) SetParameters(v ...NetworkParameter) { - x.ps = v -} - -// NetworkInfo groups information about -// NeoFS network. -type NetworkInfo struct { - curEpoch, magicNum uint64 - - msPerBlock int64 - - netCfg *NetworkConfig -} - -// GetCurrentEpoch returns number of the current epoch. -func (i *NetworkInfo) GetCurrentEpoch() uint64 { - if i != nil { - return i.curEpoch - } - - return 0 -} - -// SetCurrentEpoch sets number of the current epoch. -func (i *NetworkInfo) SetCurrentEpoch(epoch uint64) { - i.curEpoch = epoch -} - -// GetMagicNumber returns magic number of the sidechain. -func (i *NetworkInfo) GetMagicNumber() uint64 { - if i != nil { - return i.magicNum - } - - return 0 -} - -// SetMagicNumber sets magic number of the sidechain. -func (i *NetworkInfo) SetMagicNumber(magic uint64) { - i.magicNum = magic -} - -// GetMsPerBlock returns MillisecondsPerBlock network parameter. -func (i *NetworkInfo) GetMsPerBlock() int64 { - if i != nil { - return i.msPerBlock - } - - return 0 -} - -// SetMsPerBlock sets MillisecondsPerBlock network parameter. -func (i *NetworkInfo) SetMsPerBlock(v int64) { - i.msPerBlock = v -} - -// GetNetworkConfig returns NeoFS network configuration. -func (i *NetworkInfo) GetNetworkConfig() *NetworkConfig { - if i != nil { - return i.netCfg - } - - return nil -} - -// SetNetworkConfig sets NeoFS network configuration. -func (i *NetworkInfo) SetNetworkConfig(v *NetworkConfig) { - i.netCfg = v -} - -// NetworkInfoRequestBody is a structure of NetworkInfo request body. -type NetworkInfoRequestBody struct{} - -// NetworkInfoResponseBody is a structure of NetworkInfo response body. -type NetworkInfoResponseBody struct { - netInfo *NetworkInfo -} - -// GetNetworkInfo returns information about the NeoFS network. -func (i *NetworkInfoResponseBody) GetNetworkInfo() *NetworkInfo { - if i != nil { - return i.netInfo - } - - return nil -} - -// SetNetworkInfo sets information about the NeoFS network. -func (i *NetworkInfoResponseBody) SetNetworkInfo(netInfo *NetworkInfo) { - i.netInfo = netInfo -} - -func (l *NetworkInfoRequest) GetBody() *NetworkInfoRequestBody { - if l != nil { - return l.body - } - return nil -} - -func (l *NetworkInfoRequest) SetBody(body *NetworkInfoRequestBody) { - l.body = body -} - -func (l *NetworkInfoResponse) GetBody() *NetworkInfoResponseBody { - if l != nil { - return l.body - } - return nil -} - -func (l *NetworkInfoResponse) SetBody(body *NetworkInfoResponseBody) { - l.body = body -} - -// NetMap represents structure of NeoFS network map. -type NetMap struct { - epoch uint64 - - nodes []NodeInfo -} - -// Epoch returns revision number of the NetMap. -func (x *NetMap) Epoch() uint64 { - if x != nil { - return x.epoch - } - - return 0 -} - -// SetEpoch sets revision number of the NetMap. -func (x *NetMap) SetEpoch(v uint64) { - x.epoch = v -} - -// Nodes returns nodes presented in the NetMap. -func (x *NetMap) Nodes() []NodeInfo { - if x != nil { - return x.nodes - } - - return nil -} - -// SetNodes sets nodes presented in the NetMap. -func (x *NetMap) SetNodes(v []NodeInfo) { - x.nodes = v -} - -// SnapshotRequestBody represents structure of Snapshot request body. -type SnapshotRequestBody struct{} - -// SnapshotRequest represents structure of Snapshot request. -type SnapshotRequest struct { - body *SnapshotRequestBody - - session.RequestHeaders -} - -func (x *SnapshotRequest) GetBody() *SnapshotRequestBody { - if x != nil { - return x.body - } - - return nil -} - -func (x *SnapshotRequest) SetBody(body *SnapshotRequestBody) { - x.body = body -} - -// SnapshotResponseBody represents structure of Snapshot response body. -type SnapshotResponseBody struct { - netMap *NetMap -} - -// NetMap returns current NetMap. -func (x *SnapshotResponseBody) NetMap() *NetMap { - if x != nil { - return x.netMap - } - - return nil -} - -// SetNetMap sets current NetMap. -func (x *SnapshotResponseBody) SetNetMap(netMap *NetMap) { - x.netMap = netMap -} - -// SnapshotResponse represents structure of Snapshot response. -type SnapshotResponse struct { - body *SnapshotResponseBody - - session.ResponseHeaders -} - -func (x *SnapshotResponse) GetBody() *SnapshotResponseBody { - if x != nil { - return x.body - } - - return nil -} - -func (x *SnapshotResponse) SetBody(body *SnapshotResponseBody) { - x.body = body -} diff --git a/object/attributes.go b/object/attributes.go index 7f4fca0..507daf1 100644 --- a/object/attributes.go +++ b/object/attributes.go @@ -4,6 +4,8 @@ import ( "errors" "fmt" "strconv" + + object "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/object/grpc" ) // SysAttributePrefix is a prefix of key to system attribute. @@ -85,10 +87,10 @@ func (n *NotificationInfo) SetTopic(topic string) { // WriteNotificationInfo writes NotificationInfo to the Object via attributes. Object must not be nil. // // Existing notification attributes are expected to be key-unique, otherwise undefined behavior. -func WriteNotificationInfo(o *Object, ni NotificationInfo) { +func WriteNotificationInfo(o *object.Object, ni NotificationInfo) { h := o.GetHeader() if h == nil { - h = new(Header) + h = new(object.Header) o.SetHeader(h) } @@ -134,14 +136,16 @@ func WriteNotificationInfo(o *Object, ni NotificationInfo) { if !changedEpoch { index := len(attrs) - attrs = append(attrs, Attribute{}) + attr := new(object.Header_Attribute) + attrs = append(attrs, attr) attrs[index].SetKey(SysAttributeTickEpoch) attrs[index].SetValue(epoch) } if !changedTopic && topic != "" { index := len(attrs) - attrs = append(attrs, Attribute{}) + attr := new(object.Header_Attribute) + attrs = append(attrs, attr) attrs[index].SetKey(SysAttributeTickTopic) attrs[index].SetValue(topic) } @@ -157,7 +161,7 @@ var ErrNotificationNotSet = errors.New("notification for object is not set") // were found. // // Existing notification attributes are expected to be key-unique, otherwise undefined behavior. -func GetNotificationInfo(o *Object) (*NotificationInfo, error) { +func GetNotificationInfo(o *object.Object) (*NotificationInfo, error) { var ( foundEpoch bool ni = new(NotificationInfo) diff --git a/object/attributes_test.go b/object/attributes_test.go index 5bf411a..cb451fe 100644 --- a/object/attributes_test.go +++ b/object/attributes_test.go @@ -4,11 +4,12 @@ import ( "strconv" "testing" + object "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/object/grpc" "github.com/stretchr/testify/require" ) func TestSetNotification(t *testing.T) { - o := new(Object) + o := new(object.Object) var ni = NotificationInfo{ epoch: 10, @@ -40,14 +41,18 @@ func TestSetNotification(t *testing.T) { } func TestGetNotification(t *testing.T) { - o := new(Object) + o := new(object.Object) - attr := []Attribute{ - {SysAttributeTickEpoch, "10"}, - {SysAttributeTickTopic, "test"}, + attr := []*object.Header_Attribute{ + { + Key: SysAttributeTickEpoch, Value: "10", + }, + { + Key: SysAttributeTickTopic, Value: "test", + }, } - h := new(Header) + h := new(object.Header) h.SetAttributes(attr) o.SetHeader(h) @@ -62,7 +67,7 @@ func TestGetNotification(t *testing.T) { } func TestIntegration(t *testing.T) { - o := new(Object) + o := new(object.Object) var ( ni1 = NotificationInfo{ diff --git a/object/bench_test.go b/object/bench_test.go deleted file mode 100644 index 90fab73..0000000 --- a/object/bench_test.go +++ /dev/null @@ -1,45 +0,0 @@ -package object - -import ( - "math/rand" - "testing" - - "github.com/stretchr/testify/require" -) - -func randString(n int) string { - x := make([]byte, n) - for i := range x { - x[i] = byte('a' + rand.Intn('z'-'a')) - } - return string(x) -} - -func BenchmarkAttributesMarshal(b *testing.B) { - attrs := make([]Attribute, 50) - for i := range attrs { - attrs[i].key = SysAttributePrefix + randString(10) - attrs[i].val = randString(10) - } - raw := AttributesToGRPC(attrs) - require.Equal(b, len(raw), len(attrs)) - - b.Run("marshal", func(b *testing.B) { - b.ReportAllocs() - for i := 0; i < b.N; i++ { - res := AttributesToGRPC(attrs) - if len(res) != len(raw) { - b.FailNow() - } - } - }) - b.Run("unmarshal", func(b *testing.B) { - b.ReportAllocs() - for i := 0; i < b.N; i++ { - res, err := AttributesFromGRPC(raw) - if err != nil || len(res) != len(raw) { - b.FailNow() - } - } - }) -} diff --git a/object/convert.go b/object/convert.go deleted file mode 100644 index 07bf89c..0000000 --- a/object/convert.go +++ /dev/null @@ -1,2171 +0,0 @@ -package object - -import ( - "fmt" - - object "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/object/grpc" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs" - refsGRPC "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs/grpc" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/grpc" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/session" - sessionGRPC "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/session/grpc" -) - -func TypeToGRPCField(t Type) object.ObjectType { - return object.ObjectType(t) -} - -func TypeFromGRPCField(t object.ObjectType) Type { - return Type(t) -} - -func MatchTypeToGRPCField(t MatchType) object.MatchType { - return object.MatchType(t) -} - -func MatchTypeFromGRPCField(t object.MatchType) MatchType { - return MatchType(t) -} - -func (h *ShortHeader) ToGRPCMessage() grpc.Message { - var m *object.ShortHeader - - if h != nil { - m = new(object.ShortHeader) - - m.SetVersion(h.version.ToGRPCMessage().(*refsGRPC.Version)) - m.SetOwnerId(h.ownerID.ToGRPCMessage().(*refsGRPC.OwnerID)) - m.SetHomomorphicHash(h.homoHash.ToGRPCMessage().(*refsGRPC.Checksum)) - m.SetPayloadHash(h.payloadHash.ToGRPCMessage().(*refsGRPC.Checksum)) - m.SetObjectType(TypeToGRPCField(h.typ)) - m.SetCreationEpoch(h.creatEpoch) - m.SetPayloadLength(h.payloadLen) - } - - return m -} - -func (h *ShortHeader) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*object.ShortHeader) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var err error - - version := v.GetVersion() - if version == nil { - h.version = nil - } else { - if h.version == nil { - h.version = new(refs.Version) - } - - err = h.version.FromGRPCMessage(version) - if err != nil { - return err - } - } - - ownerID := v.GetOwnerId() - if ownerID == nil { - h.ownerID = nil - } else { - if h.ownerID == nil { - h.ownerID = new(refs.OwnerID) - } - - err = h.ownerID.FromGRPCMessage(ownerID) - if err != nil { - return err - } - } - - homoHash := v.GetHomomorphicHash() - if homoHash == nil { - h.homoHash = nil - } else { - if h.homoHash == nil { - h.homoHash = new(refs.Checksum) - } - - err = h.homoHash.FromGRPCMessage(homoHash) - if err != nil { - return err - } - } - - payloadHash := v.GetPayloadHash() - if payloadHash == nil { - h.payloadHash = nil - } else { - if h.payloadHash == nil { - h.payloadHash = new(refs.Checksum) - } - - err = h.payloadHash.FromGRPCMessage(payloadHash) - if err != nil { - return err - } - } - - h.typ = TypeFromGRPCField(v.GetObjectType()) - h.creatEpoch = v.GetCreationEpoch() - h.payloadLen = v.GetPayloadLength() - - return nil -} - -func (a *Attribute) ToGRPCMessage() grpc.Message { - var m *object.Header_Attribute - - if a != nil { - m = new(object.Header_Attribute) - - m.SetKey(a.key) - m.SetValue(a.val) - } - - return m -} - -func (a *Attribute) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*object.Header_Attribute) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - a.key = v.GetKey() - a.val = v.GetValue() - - return nil -} - -func AttributesToGRPC(xs []Attribute) (res []*object.Header_Attribute) { - if xs != nil { - res = make([]*object.Header_Attribute, 0, len(xs)) - - for i := range xs { - res = append(res, xs[i].ToGRPCMessage().(*object.Header_Attribute)) - } - } - - return -} - -func AttributesFromGRPC(xs []*object.Header_Attribute) (res []Attribute, err error) { - if xs != nil { - res = make([]Attribute, len(xs)) - - for i := range xs { - if xs[i] != nil { - err = res[i].FromGRPCMessage(xs[i]) - if err != nil { - return - } - } - } - } - - return -} - -func (h *SplitHeader) ToGRPCMessage() grpc.Message { - var m *object.Header_Split - - if h != nil { - m = new(object.Header_Split) - - m.SetParent(h.par.ToGRPCMessage().(*refsGRPC.ObjectID)) - m.SetPrevious(h.prev.ToGRPCMessage().(*refsGRPC.ObjectID)) - m.SetParentHeader(h.parHdr.ToGRPCMessage().(*object.Header)) - m.SetParentSignature(h.parSig.ToGRPCMessage().(*refsGRPC.Signature)) - m.SetChildren(refs.ObjectIDListToGRPCMessage(h.children)) - m.SetSplitId(h.splitID) - } - - return m -} - -func (h *SplitHeader) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*object.Header_Split) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var err error - - par := v.GetParent() - if par == nil { - h.par = nil - } else { - if h.par == nil { - h.par = new(refs.ObjectID) - } - - err = h.par.FromGRPCMessage(par) - if err != nil { - return err - } - } - - prev := v.GetPrevious() - if prev == nil { - h.prev = nil - } else { - if h.prev == nil { - h.prev = new(refs.ObjectID) - } - - err = h.prev.FromGRPCMessage(prev) - if err != nil { - return err - } - } - - parHdr := v.GetParentHeader() - if parHdr == nil { - h.parHdr = nil - } else { - if h.parHdr == nil { - h.parHdr = new(Header) - } - - err = h.parHdr.FromGRPCMessage(parHdr) - if err != nil { - return err - } - } - - parSig := v.GetParentSignature() - if parSig == nil { - h.parSig = nil - } else { - if h.parSig == nil { - h.parSig = new(refs.Signature) - } - - err = h.parSig.FromGRPCMessage(parSig) - if err != nil { - return err - } - } - - h.children, err = refs.ObjectIDListFromGRPCMessage(v.GetChildren()) - if err != nil { - return err - } - - h.splitID = v.GetSplitId() - - return nil -} - -func (h *Header) ToGRPCMessage() grpc.Message { - var m *object.Header - - if h != nil { - m = new(object.Header) - - m.SetVersion(h.version.ToGRPCMessage().(*refsGRPC.Version)) - m.SetPayloadHash(h.payloadHash.ToGRPCMessage().(*refsGRPC.Checksum)) - m.SetOwnerId(h.ownerID.ToGRPCMessage().(*refsGRPC.OwnerID)) - m.SetHomomorphicHash(h.homoHash.ToGRPCMessage().(*refsGRPC.Checksum)) - m.SetContainerId(h.cid.ToGRPCMessage().(*refsGRPC.ContainerID)) - m.SetSessionToken(h.sessionToken.ToGRPCMessage().(*sessionGRPC.SessionToken)) - m.SetSplit(h.split.ToGRPCMessage().(*object.Header_Split)) - m.SetAttributes(AttributesToGRPC(h.attr)) - m.SetPayloadLength(h.payloadLen) - m.SetCreationEpoch(h.creatEpoch) - m.SetObjectType(TypeToGRPCField(h.typ)) - } - - return m -} - -func (h *Header) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*object.Header) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var err error - - if err := h.fillVersion(v); err != nil { - return err - } - if err := h.fillPayloadHash(v); err != nil { - return err - } - if err := h.fillOwnerID(v); err != nil { - return err - } - if err := h.fillHomomorphicHash(v); err != nil { - return err - } - if err := h.fillContainerID(v); err != nil { - return err - } - if err := h.fillSessionToken(v); err != nil { - return err - } - if err := h.fillSplitHeader(v); err != nil { - return err - } - - h.attr, err = AttributesFromGRPC(v.GetAttributes()) - if err != nil { - return err - } - - h.payloadLen = v.GetPayloadLength() - h.creatEpoch = v.GetCreationEpoch() - h.typ = TypeFromGRPCField(v.GetObjectType()) - - return nil -} - -func (h *Header) fillVersion(v *object.Header) error { - version := v.GetVersion() - if version == nil { - h.version = nil - return nil - } - - if h.version == nil { - h.version = new(refs.Version) - } - return h.version.FromGRPCMessage(version) -} - -func (h *Header) fillPayloadHash(v *object.Header) error { - payloadHash := v.GetPayloadHash() - if payloadHash == nil { - h.payloadHash = nil - return nil - } - - if h.payloadHash == nil { - h.payloadHash = new(refs.Checksum) - } - return h.payloadHash.FromGRPCMessage(payloadHash) -} - -func (h *Header) fillOwnerID(v *object.Header) error { - ownerID := v.GetOwnerId() - if ownerID == nil { - h.ownerID = nil - return nil - } - - if h.ownerID == nil { - h.ownerID = new(refs.OwnerID) - } - return h.ownerID.FromGRPCMessage(ownerID) -} - -func (h *Header) fillHomomorphicHash(v *object.Header) error { - homoHash := v.GetHomomorphicHash() - if homoHash == nil { - h.homoHash = nil - return nil - } - - if h.homoHash == nil { - h.homoHash = new(refs.Checksum) - } - return h.homoHash.FromGRPCMessage(homoHash) -} - -func (h *Header) fillContainerID(v *object.Header) error { - cid := v.GetContainerId() - if cid == nil { - h.cid = nil - return nil - } - - if h.cid == nil { - h.cid = new(refs.ContainerID) - } - return h.cid.FromGRPCMessage(cid) -} - -func (h *Header) fillSessionToken(v *object.Header) error { - sessionToken := v.GetSessionToken() - if sessionToken == nil { - h.sessionToken = nil - return nil - } - - if h.sessionToken == nil { - h.sessionToken = new(session.Token) - } - return h.sessionToken.FromGRPCMessage(sessionToken) -} - -func (h *Header) fillSplitHeader(v *object.Header) error { - split := v.GetSplit() - if split == nil { - h.split = nil - return nil - } - - if h.split == nil { - h.split = new(SplitHeader) - } - return h.split.FromGRPCMessage(split) -} - -func (h *HeaderWithSignature) ToGRPCMessage() grpc.Message { - var m *object.HeaderWithSignature - - if h != nil { - m = new(object.HeaderWithSignature) - - m.SetSignature(h.signature.ToGRPCMessage().(*refsGRPC.Signature)) - m.SetHeader(h.header.ToGRPCMessage().(*object.Header)) - } - - return m -} - -func (h *HeaderWithSignature) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*object.HeaderWithSignature) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var err error - - signature := v.GetSignature() - if signature == nil { - h.signature = nil - } else { - if h.signature == nil { - h.signature = new(refs.Signature) - } - - err = h.signature.FromGRPCMessage(signature) - if err != nil { - return err - } - } - - header := v.GetHeader() - if header == nil { - h.header = nil - } else { - if h.header == nil { - h.header = new(Header) - } - - err = h.header.FromGRPCMessage(header) - } - - return err -} - -func (o *Object) ToGRPCMessage() grpc.Message { - var m *object.Object - - if o != nil { - m = new(object.Object) - - m.SetObjectId(o.objectID.ToGRPCMessage().(*refsGRPC.ObjectID)) - m.SetSignature(o.idSig.ToGRPCMessage().(*refsGRPC.Signature)) - m.SetHeader(o.header.ToGRPCMessage().(*object.Header)) - m.SetPayload(o.payload) - } - - return m -} - -func (o *Object) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*object.Object) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var err error - - objectID := v.GetObjectId() - if objectID == nil { - o.objectID = nil - } else { - if o.objectID == nil { - o.objectID = new(refs.ObjectID) - } - - err = o.objectID.FromGRPCMessage(objectID) - if err != nil { - return err - } - } - - idSig := v.GetSignature() - if idSig == nil { - o.idSig = nil - } else { - if o.idSig == nil { - o.idSig = new(refs.Signature) - } - - err = o.idSig.FromGRPCMessage(idSig) - if err != nil { - return err - } - } - - header := v.GetHeader() - if header == nil { - o.header = nil - } else { - if o.header == nil { - o.header = new(Header) - } - - err = o.header.FromGRPCMessage(header) - if err != nil { - return err - } - } - - o.payload = v.GetPayload() - - return nil -} - -func (s *SplitInfo) ToGRPCMessage() grpc.Message { - var m *object.SplitInfo - - if s != nil { - m = new(object.SplitInfo) - - m.SetLastPart(s.lastPart.ToGRPCMessage().(*refsGRPC.ObjectID)) - m.SetLink(s.link.ToGRPCMessage().(*refsGRPC.ObjectID)) - m.SetSplitId(s.splitID) - } - - return m -} - -func (s *SplitInfo) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*object.SplitInfo) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var err error - - lastPart := v.GetLastPart() - if lastPart == nil { - s.lastPart = nil - } else { - if s.lastPart == nil { - s.lastPart = new(refs.ObjectID) - } - - err = s.lastPart.FromGRPCMessage(lastPart) - if err != nil { - return err - } - } - - link := v.GetLink() - if link == nil { - s.link = nil - } else { - if s.link == nil { - s.link = new(refs.ObjectID) - } - - err = s.link.FromGRPCMessage(link) - if err != nil { - return err - } - } - - s.splitID = v.GetSplitId() - - return nil -} - -func (r *GetRequestBody) ToGRPCMessage() grpc.Message { - var m *object.GetRequest_Body - - if r != nil { - m = new(object.GetRequest_Body) - - m.SetAddress(r.addr.ToGRPCMessage().(*refsGRPC.Address)) - m.SetRaw(r.raw) - } - - return m -} - -func (r *GetRequestBody) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*object.GetRequest_Body) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var err error - - addr := v.GetAddress() - if addr == nil { - r.addr = nil - } else { - if r.addr == nil { - r.addr = new(refs.Address) - } - - err = r.addr.FromGRPCMessage(addr) - if err != nil { - return err - } - } - - r.raw = v.GetRaw() - - return nil -} - -func (r *GetRequest) ToGRPCMessage() grpc.Message { - var m *object.GetRequest - - if r != nil { - m = new(object.GetRequest) - - m.SetBody(r.body.ToGRPCMessage().(*object.GetRequest_Body)) - r.RequestHeaders.ToMessage(m) - } - - return m -} - -func (r *GetRequest) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*object.GetRequest) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var err error - - body := v.GetBody() - if body == nil { - r.body = nil - } else { - if r.body == nil { - r.body = new(GetRequestBody) - } - - err = r.body.FromGRPCMessage(body) - if err != nil { - return err - } - } - - return r.RequestHeaders.FromMessage(v) -} - -func (r *GetObjectPartInit) ToGRPCMessage() grpc.Message { - var m *object.GetResponse_Body_Init - - if r != nil { - m = new(object.GetResponse_Body_Init) - - m.SetObjectId(r.id.ToGRPCMessage().(*refsGRPC.ObjectID)) - m.SetSignature(r.sig.ToGRPCMessage().(*refsGRPC.Signature)) - m.SetHeader(r.hdr.ToGRPCMessage().(*object.Header)) - } - - return m -} - -func (r *GetObjectPartInit) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*object.GetResponse_Body_Init) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var err error - - id := v.GetObjectId() - if id == nil { - r.id = nil - } else { - if r.id == nil { - r.id = new(refs.ObjectID) - } - - err = r.id.FromGRPCMessage(id) - if err != nil { - return err - } - } - - sig := v.GetSignature() - if sig == nil { - r.sig = nil - } else { - if r.sig == nil { - r.sig = new(refs.Signature) - } - - err = r.sig.FromGRPCMessage(sig) - if err != nil { - return err - } - } - - hdr := v.GetHeader() - if hdr == nil { - r.hdr = nil - } else { - if r.hdr == nil { - r.hdr = new(Header) - } - - err = r.hdr.FromGRPCMessage(hdr) - } - - return err -} - -func (r *GetObjectPartChunk) ToGRPCMessage() grpc.Message { - var m *object.GetResponse_Body_Chunk - - if r != nil { - m = new(object.GetResponse_Body_Chunk) - - m.SetChunk(r.chunk) - } - - return m -} - -func (r *GetObjectPartChunk) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*object.GetResponse_Body_Chunk) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - r.chunk = v.GetChunk() - - return nil -} - -func (r *GetResponseBody) ToGRPCMessage() grpc.Message { - var m *object.GetResponse_Body - - if r != nil { - m = new(object.GetResponse_Body) - - switch v := r.GetObjectPart(); t := v.(type) { - case nil: - m.ObjectPart = nil - case *GetObjectPartInit: - m.SetInit(t.ToGRPCMessage().(*object.GetResponse_Body_Init)) - case *GetObjectPartChunk: - m.SetChunk(t.ToGRPCMessage().(*object.GetResponse_Body_Chunk)) - case *SplitInfo: - m.SetSplitInfo(t.ToGRPCMessage().(*object.SplitInfo)) - default: - panic(fmt.Sprintf("unknown get object part %T", t)) - } - } - - return m -} - -func (r *GetResponseBody) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*object.GetResponse_Body) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var err error - - r.objPart = nil - - switch pt := v.GetObjectPart().(type) { - case nil: - case *object.GetResponse_Body_Init_: - if pt != nil { - partInit := new(GetObjectPartInit) - r.objPart = partInit - err = partInit.FromGRPCMessage(pt.Init) - } - case *object.GetResponse_Body_Chunk: - if pt != nil { - partChunk := new(GetObjectPartChunk) - r.objPart = partChunk - err = partChunk.FromGRPCMessage(pt) - } - case *object.GetResponse_Body_SplitInfo: - if pt != nil { - partSplit := new(SplitInfo) - r.objPart = partSplit - err = partSplit.FromGRPCMessage(pt.SplitInfo) - } - default: - err = fmt.Errorf("unknown get object part %T", pt) - } - - return err -} - -func (r *GetResponse) ToGRPCMessage() grpc.Message { - var m *object.GetResponse - - if r != nil { - m = new(object.GetResponse) - - m.SetBody(r.body.ToGRPCMessage().(*object.GetResponse_Body)) - r.ResponseHeaders.ToMessage(m) - } - - return m -} - -func (r *GetResponse) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*object.GetResponse) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var err error - - body := v.GetBody() - if body == nil { - r.body = nil - } else { - if r.body == nil { - r.body = new(GetResponseBody) - } - - err = r.body.FromGRPCMessage(body) - if err != nil { - return err - } - } - - return r.ResponseHeaders.FromMessage(v) -} - -func (r *PutObjectPartInit) ToGRPCMessage() grpc.Message { - var m *object.PutRequest_Body_Init - - if r != nil { - m = new(object.PutRequest_Body_Init) - - m.SetObjectId(r.id.ToGRPCMessage().(*refsGRPC.ObjectID)) - m.SetSignature(r.sig.ToGRPCMessage().(*refsGRPC.Signature)) - m.SetHeader(r.hdr.ToGRPCMessage().(*object.Header)) - m.SetCopiesNumber(r.copyNum) - } - - return m -} - -func (r *PutObjectPartInit) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*object.PutRequest_Body_Init) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var err error - - id := v.GetObjectId() - if id == nil { - r.id = nil - } else { - if r.id == nil { - r.id = new(refs.ObjectID) - } - - err = r.id.FromGRPCMessage(id) - if err != nil { - return err - } - } - - sig := v.GetSignature() - if sig == nil { - r.sig = nil - } else { - if r.sig == nil { - r.sig = new(refs.Signature) - } - - err = r.sig.FromGRPCMessage(sig) - if err != nil { - return err - } - } - - hdr := v.GetHeader() - if hdr == nil { - r.hdr = nil - } else { - if r.hdr == nil { - r.hdr = new(Header) - } - - err = r.hdr.FromGRPCMessage(hdr) - if err != nil { - return err - } - } - - r.copyNum = v.GetCopiesNumber() - - return nil -} - -func (r *PutObjectPartChunk) ToGRPCMessage() grpc.Message { - var m *object.PutRequest_Body_Chunk - - if r != nil { - m = new(object.PutRequest_Body_Chunk) - - m.SetChunk(r.chunk) - } - - return m -} - -func (r *PutObjectPartChunk) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*object.PutRequest_Body_Chunk) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - r.chunk = v.GetChunk() - - return nil -} - -func (r *PutRequestBody) ToGRPCMessage() grpc.Message { - var m *object.PutRequest_Body - - if r != nil { - m = new(object.PutRequest_Body) - - switch v := r.GetObjectPart(); t := v.(type) { - case nil: - m.ObjectPart = nil - case *PutObjectPartInit: - m.SetInit(t.ToGRPCMessage().(*object.PutRequest_Body_Init)) - case *PutObjectPartChunk: - m.SetChunk(t.ToGRPCMessage().(*object.PutRequest_Body_Chunk)) - default: - panic(fmt.Sprintf("unknown put object part %T", t)) - } - } - - return m -} - -func (r *PutRequestBody) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*object.PutRequest_Body) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var err error - - r.objPart = nil - - switch pt := v.GetObjectPart().(type) { - case nil: - case *object.PutRequest_Body_Init_: - if pt != nil { - partInit := new(PutObjectPartInit) - r.objPart = partInit - err = partInit.FromGRPCMessage(pt.Init) - } - case *object.PutRequest_Body_Chunk: - if pt != nil { - partChunk := new(PutObjectPartChunk) - r.objPart = partChunk - err = partChunk.FromGRPCMessage(pt) - } - default: - err = fmt.Errorf("unknown put object part %T", pt) - } - - return err -} - -func (r *PutRequest) ToGRPCMessage() grpc.Message { - var m *object.PutRequest - - if r != nil { - m = new(object.PutRequest) - - m.SetBody(r.body.ToGRPCMessage().(*object.PutRequest_Body)) - r.RequestHeaders.ToMessage(m) - } - - return m -} - -func (r *PutRequest) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*object.PutRequest) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var err error - - body := v.GetBody() - if body == nil { - r.body = nil - } else { - if r.body == nil { - r.body = new(PutRequestBody) - } - - err = r.body.FromGRPCMessage(body) - if err != nil { - return err - } - } - - return r.RequestHeaders.FromMessage(v) -} - -func (r *PutResponseBody) ToGRPCMessage() grpc.Message { - var m *object.PutResponse_Body - - if r != nil { - m = new(object.PutResponse_Body) - - m.SetObjectId(r.id.ToGRPCMessage().(*refsGRPC.ObjectID)) - } - - return m -} - -func (r *PutResponseBody) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*object.PutResponse_Body) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var err error - - id := v.GetObjectId() - if id == nil { - r.id = nil - } else { - if r.id == nil { - r.id = new(refs.ObjectID) - } - - err = r.id.FromGRPCMessage(id) - } - - return err -} - -func (r *PutResponse) ToGRPCMessage() grpc.Message { - var m *object.PutResponse - - if r != nil { - m = new(object.PutResponse) - - m.SetBody(r.body.ToGRPCMessage().(*object.PutResponse_Body)) - r.ResponseHeaders.ToMessage(m) - } - - return m -} - -func (r *PutResponse) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*object.PutResponse) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var err error - - body := v.GetBody() - if body == nil { - r.body = nil - } else { - if r.body == nil { - r.body = new(PutResponseBody) - } - - err = r.body.FromGRPCMessage(body) - if err != nil { - return err - } - } - - return r.ResponseHeaders.FromMessage(v) -} - -func (r *DeleteRequestBody) ToGRPCMessage() grpc.Message { - var m *object.DeleteRequest_Body - - if r != nil { - m = new(object.DeleteRequest_Body) - - m.SetAddress(r.addr.ToGRPCMessage().(*refsGRPC.Address)) - } - - return m -} - -func (r *DeleteRequestBody) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*object.DeleteRequest_Body) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var err error - - addr := v.GetAddress() - if addr == nil { - r.addr = nil - } else { - if r.addr == nil { - r.addr = new(refs.Address) - } - - err = r.addr.FromGRPCMessage(addr) - } - - return err -} - -func (r *DeleteRequest) ToGRPCMessage() grpc.Message { - var m *object.DeleteRequest - - if r != nil { - m = new(object.DeleteRequest) - - m.SetBody(r.body.ToGRPCMessage().(*object.DeleteRequest_Body)) - r.RequestHeaders.ToMessage(m) - } - - return m -} - -func (r *DeleteRequest) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*object.DeleteRequest) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var err error - - body := v.GetBody() - if body == nil { - r.body = nil - } else { - if r.body == nil { - r.body = new(DeleteRequestBody) - } - - err = r.body.FromGRPCMessage(body) - if err != nil { - return err - } - } - - return r.RequestHeaders.FromMessage(v) -} - -func (r *DeleteResponseBody) ToGRPCMessage() grpc.Message { - var m *object.DeleteResponse_Body - - if r != nil { - m = new(object.DeleteResponse_Body) - - m.SetTombstone(r.tombstone.ToGRPCMessage().(*refsGRPC.Address)) - } - - return m -} - -func (r *DeleteResponseBody) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*object.DeleteResponse_Body) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var err error - - tombstone := v.GetTombstone() - if tombstone == nil { - r.tombstone = nil - } else { - if r.tombstone == nil { - r.tombstone = new(refs.Address) - } - - err = r.tombstone.FromGRPCMessage(tombstone) - } - - return err -} - -func (r *DeleteResponse) ToGRPCMessage() grpc.Message { - var m *object.DeleteResponse - - if r != nil { - m = new(object.DeleteResponse) - - m.SetBody(r.body.ToGRPCMessage().(*object.DeleteResponse_Body)) - r.ResponseHeaders.ToMessage(m) - } - - return m -} - -func (r *DeleteResponse) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*object.DeleteResponse) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var err error - - body := v.GetBody() - if body == nil { - r.body = nil - } else { - if r.body == nil { - r.body = new(DeleteResponseBody) - } - - err = r.body.FromGRPCMessage(body) - if err != nil { - return err - } - } - - return r.ResponseHeaders.FromMessage(v) -} - -func (r *HeadRequestBody) ToGRPCMessage() grpc.Message { - var m *object.HeadRequest_Body - - if r != nil { - m = new(object.HeadRequest_Body) - - m.SetAddress(r.addr.ToGRPCMessage().(*refsGRPC.Address)) - m.SetRaw(r.raw) - m.SetMainOnly(r.mainOnly) - } - - return m -} - -func (r *HeadRequestBody) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*object.HeadRequest_Body) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var err error - - addr := v.GetAddress() - if addr == nil { - r.addr = nil - } else { - if r.addr == nil { - r.addr = new(refs.Address) - } - - err = r.addr.FromGRPCMessage(addr) - if err != nil { - return err - } - } - - r.raw = v.GetRaw() - r.mainOnly = v.GetMainOnly() - - return nil -} - -func (r *HeadRequest) ToGRPCMessage() grpc.Message { - var m *object.HeadRequest - - if r != nil { - m = new(object.HeadRequest) - - m.SetBody(r.body.ToGRPCMessage().(*object.HeadRequest_Body)) - r.RequestHeaders.ToMessage(m) - } - - return m -} - -func (r *HeadRequest) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*object.HeadRequest) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var err error - - body := v.GetBody() - if body == nil { - r.body = nil - } else { - if r.body == nil { - r.body = new(HeadRequestBody) - } - - err = r.body.FromGRPCMessage(body) - if err != nil { - return err - } - } - - return r.RequestHeaders.FromMessage(v) -} - -func (r *HeadResponseBody) ToGRPCMessage() grpc.Message { - var m *object.HeadResponse_Body - - if r != nil { - m = new(object.HeadResponse_Body) - - switch v := r.hdrPart.(type) { - case nil: - m.Head = nil - case *HeaderWithSignature: - m.SetHeader(v.ToGRPCMessage().(*object.HeaderWithSignature)) - case *ShortHeader: - m.SetShortHeader(v.ToGRPCMessage().(*object.ShortHeader)) - case *SplitInfo: - m.SetSplitInfo(v.ToGRPCMessage().(*object.SplitInfo)) - default: - panic(fmt.Sprintf("unknown head part %T", v)) - } - } - - return m -} - -func (r *HeadResponseBody) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*object.HeadResponse_Body) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var err error - - r.hdrPart = nil - - switch pt := v.GetHead().(type) { - case nil: - case *object.HeadResponse_Body_Header: - if pt != nil { - partHdr := new(HeaderWithSignature) - r.hdrPart = partHdr - err = partHdr.FromGRPCMessage(pt.Header) - } - case *object.HeadResponse_Body_ShortHeader: - if pt != nil { - partShort := new(ShortHeader) - r.hdrPart = partShort - err = partShort.FromGRPCMessage(pt.ShortHeader) - } - case *object.HeadResponse_Body_SplitInfo: - if pt != nil { - partSplit := new(SplitInfo) - r.hdrPart = partSplit - err = partSplit.FromGRPCMessage(pt.SplitInfo) - } - default: - err = fmt.Errorf("unknown head part %T", pt) - } - - return err -} - -func (r *HeadResponse) ToGRPCMessage() grpc.Message { - var m *object.HeadResponse - - if r != nil { - m = new(object.HeadResponse) - - m.SetBody(r.body.ToGRPCMessage().(*object.HeadResponse_Body)) - r.ResponseHeaders.ToMessage(m) - } - - return m -} - -func (r *HeadResponse) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*object.HeadResponse) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var err error - - body := v.GetBody() - if body == nil { - r.body = nil - } else { - if r.body == nil { - r.body = new(HeadResponseBody) - } - - err = r.body.FromGRPCMessage(body) - if err != nil { - return err - } - } - - return r.ResponseHeaders.FromMessage(v) -} - -func (f *SearchFilter) ToGRPCMessage() grpc.Message { - var m *object.SearchRequest_Body_Filter - - if f != nil { - m = new(object.SearchRequest_Body_Filter) - - m.SetKey(f.key) - m.SetValue(f.val) - m.SetMatchType(MatchTypeToGRPCField(f.matchType)) - } - - return m -} - -func (f *SearchFilter) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*object.SearchRequest_Body_Filter) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - f.key = v.GetKey() - f.val = v.GetValue() - f.matchType = MatchTypeFromGRPCField(v.GetMatchType()) - - return nil -} - -func SearchFiltersToGRPC(fs []SearchFilter) (res []*object.SearchRequest_Body_Filter) { - if fs != nil { - res = make([]*object.SearchRequest_Body_Filter, 0, len(fs)) - - for i := range fs { - res = append(res, fs[i].ToGRPCMessage().(*object.SearchRequest_Body_Filter)) - } - } - - return -} - -func SearchFiltersFromGRPC(fs []*object.SearchRequest_Body_Filter) (res []SearchFilter, err error) { - if fs != nil { - res = make([]SearchFilter, len(fs)) - - for i := range fs { - if fs[i] != nil { - err = res[i].FromGRPCMessage(fs[i]) - if err != nil { - return - } - } - } - } - - return -} - -func (r *SearchRequestBody) ToGRPCMessage() grpc.Message { - var m *object.SearchRequest_Body - - if r != nil { - m = new(object.SearchRequest_Body) - - m.SetContainerId(r.cid.ToGRPCMessage().(*refsGRPC.ContainerID)) - m.SetFilters(SearchFiltersToGRPC(r.filters)) - m.SetVersion(r.version) - } - - return m -} - -func (r *SearchRequestBody) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*object.SearchRequest_Body) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var err error - - cid := v.GetContainerId() - if cid == nil { - r.cid = nil - } else { - if r.cid == nil { - r.cid = new(refs.ContainerID) - } - - err = r.cid.FromGRPCMessage(cid) - if err != nil { - return err - } - } - - r.filters, err = SearchFiltersFromGRPC(v.GetFilters()) - if err != nil { - return err - } - - r.version = v.GetVersion() - - return nil -} - -func (r *SearchRequest) ToGRPCMessage() grpc.Message { - var m *object.SearchRequest - - if r != nil { - m = new(object.SearchRequest) - - m.SetBody(r.body.ToGRPCMessage().(*object.SearchRequest_Body)) - r.RequestHeaders.ToMessage(m) - } - - return m -} - -func (r *SearchRequest) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*object.SearchRequest) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var err error - - body := v.GetBody() - if body == nil { - r.body = nil - } else { - if r.body == nil { - r.body = new(SearchRequestBody) - } - - err = r.body.FromGRPCMessage(body) - if err != nil { - return err - } - } - - return r.RequestHeaders.FromMessage(v) -} - -func (r *SearchResponseBody) ToGRPCMessage() grpc.Message { - var m *object.SearchResponse_Body - - if r != nil { - m = new(object.SearchResponse_Body) - - m.SetIdList(refs.ObjectIDListToGRPCMessage(r.idList)) - } - - return m -} - -func (r *SearchResponseBody) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*object.SearchResponse_Body) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var err error - - r.idList, err = refs.ObjectIDListFromGRPCMessage(v.GetIdList()) - - return err -} - -func (r *SearchResponse) ToGRPCMessage() grpc.Message { - var m *object.SearchResponse - - if r != nil { - m = new(object.SearchResponse) - - m.SetBody(r.body.ToGRPCMessage().(*object.SearchResponse_Body)) - r.ResponseHeaders.ToMessage(m) - } - - return m -} - -func (r *SearchResponse) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*object.SearchResponse) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var err error - - body := v.GetBody() - if body == nil { - r.body = nil - } else { - if r.body == nil { - r.body = new(SearchResponseBody) - } - - err = r.body.FromGRPCMessage(body) - if err != nil { - return err - } - } - - return r.ResponseHeaders.FromMessage(v) -} - -func (r *Range) ToGRPCMessage() grpc.Message { - var m *object.Range - - if r != nil { - m = new(object.Range) - - m.SetLength(r.len) - m.SetOffset(r.off) - } - - return m -} - -func (r *Range) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*object.Range) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - r.len = v.GetLength() - r.off = v.GetOffset() - - return nil -} - -func RangesToGRPC(rs []Range) (res []*object.Range) { - if rs != nil { - res = make([]*object.Range, 0, len(rs)) - - for i := range rs { - res = append(res, rs[i].ToGRPCMessage().(*object.Range)) - } - } - - return -} - -func RangesFromGRPC(rs []*object.Range) (res []Range, err error) { - if rs != nil { - res = make([]Range, len(rs)) - - for i := range rs { - if rs[i] != nil { - err = res[i].FromGRPCMessage(rs[i]) - if err != nil { - return - } - } - } - } - - return -} - -func (r *GetRangeRequestBody) ToGRPCMessage() grpc.Message { - var m *object.GetRangeRequest_Body - - if r != nil { - m = new(object.GetRangeRequest_Body) - - m.SetAddress(r.addr.ToGRPCMessage().(*refsGRPC.Address)) - m.SetRange(r.rng.ToGRPCMessage().(*object.Range)) - m.SetRaw(r.raw) - } - - return m -} - -func (r *GetRangeRequestBody) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*object.GetRangeRequest_Body) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var err error - - addr := v.GetAddress() - if addr == nil { - r.addr = nil - } else { - if r.addr == nil { - r.addr = new(refs.Address) - } - - err = r.addr.FromGRPCMessage(addr) - if err != nil { - return err - } - } - - rng := v.GetRange() - if rng == nil { - r.rng = nil - } else { - if r.rng == nil { - r.rng = new(Range) - } - - err = r.rng.FromGRPCMessage(rng) - if err != nil { - return err - } - } - - r.raw = v.GetRaw() - - return nil -} - -func (r *GetRangeRequest) ToGRPCMessage() grpc.Message { - var m *object.GetRangeRequest - - if r != nil { - m = new(object.GetRangeRequest) - - m.SetBody(r.body.ToGRPCMessage().(*object.GetRangeRequest_Body)) - r.RequestHeaders.ToMessage(m) - } - - return m -} - -func (r *GetRangeRequest) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*object.GetRangeRequest) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var err error - - body := v.GetBody() - if body == nil { - r.body = nil - } else { - if r.body == nil { - r.body = new(GetRangeRequestBody) - } - - err = r.body.FromGRPCMessage(body) - if err != nil { - return err - } - } - - return r.RequestHeaders.FromMessage(v) -} - -func (r *GetRangePartChunk) ToGRPCMessage() grpc.Message { - var m *object.GetRangeResponse_Body_Chunk - - if r != nil { - m = new(object.GetRangeResponse_Body_Chunk) - - m.SetChunk(r.chunk) - } - - return m -} - -func (r *GetRangePartChunk) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*object.GetRangeResponse_Body_Chunk) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - r.chunk = v.GetChunk() - - return nil -} - -func (r *GetRangeResponseBody) ToGRPCMessage() grpc.Message { - var m *object.GetRangeResponse_Body - - if r != nil { - m = new(object.GetRangeResponse_Body) - - switch v := r.rngPart.(type) { - case nil: - m.RangePart = nil - case *GetRangePartChunk: - m.SetChunk(v.ToGRPCMessage().(*object.GetRangeResponse_Body_Chunk)) - case *SplitInfo: - m.SetSplitInfo(v.ToGRPCMessage().(*object.SplitInfo)) - default: - panic(fmt.Sprintf("unknown get range part %T", v)) - } - } - - return m -} - -func (r *GetRangeResponseBody) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*object.GetRangeResponse_Body) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var err error - - r.rngPart = nil - - switch pt := v.GetRangePart().(type) { - case nil: - case *object.GetRangeResponse_Body_Chunk: - if pt != nil { - partChunk := new(GetRangePartChunk) - r.rngPart = partChunk - err = partChunk.FromGRPCMessage(pt) - } - case *object.GetRangeResponse_Body_SplitInfo: - if pt != nil { - partSplit := new(SplitInfo) - r.rngPart = partSplit - err = partSplit.FromGRPCMessage(pt.SplitInfo) - } - default: - err = fmt.Errorf("unknown get range part %T", pt) - } - - return err -} - -func (r *GetRangeResponse) ToGRPCMessage() grpc.Message { - var m *object.GetRangeResponse - - if r != nil { - m = new(object.GetRangeResponse) - - m.SetBody(r.body.ToGRPCMessage().(*object.GetRangeResponse_Body)) - r.ResponseHeaders.ToMessage(m) - } - - return m -} - -func (r *GetRangeResponse) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*object.GetRangeResponse) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var err error - - body := v.GetBody() - if body == nil { - r.body = nil - } else { - if r.body == nil { - r.body = new(GetRangeResponseBody) - } - - err = r.body.FromGRPCMessage(body) - if err != nil { - return err - } - } - - return r.ResponseHeaders.FromMessage(v) -} - -func (r *GetRangeHashRequestBody) ToGRPCMessage() grpc.Message { - var m *object.GetRangeHashRequest_Body - - if r != nil { - m = new(object.GetRangeHashRequest_Body) - - m.SetAddress(r.addr.ToGRPCMessage().(*refsGRPC.Address)) - m.SetRanges(RangesToGRPC(r.rngs)) - m.SetType(refs.ChecksumTypeToGRPC(r.typ)) - m.SetSalt(r.salt) - } - - return m -} - -func (r *GetRangeHashRequestBody) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*object.GetRangeHashRequest_Body) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var err error - - addr := v.GetAddress() - if addr == nil { - r.addr = nil - } else { - if r.addr == nil { - r.addr = new(refs.Address) - } - - err = r.addr.FromGRPCMessage(addr) - if err != nil { - return err - } - } - - r.rngs, err = RangesFromGRPC(v.GetRanges()) - if err != nil { - return err - } - - r.typ = refs.ChecksumTypeFromGRPC(v.GetType()) - r.salt = v.GetSalt() - - return nil -} - -func (r *GetRangeHashRequest) ToGRPCMessage() grpc.Message { - var m *object.GetRangeHashRequest - - if r != nil { - m = new(object.GetRangeHashRequest) - - m.SetBody(r.body.ToGRPCMessage().(*object.GetRangeHashRequest_Body)) - r.RequestHeaders.ToMessage(m) - } - - return m -} - -func (r *GetRangeHashRequest) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*object.GetRangeHashRequest) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var err error - - body := v.GetBody() - if body == nil { - r.body = nil - } else { - if r.body == nil { - r.body = new(GetRangeHashRequestBody) - } - - err = r.body.FromGRPCMessage(body) - if err != nil { - return err - } - } - - return r.RequestHeaders.FromMessage(v) -} - -func (r *GetRangeHashResponseBody) ToGRPCMessage() grpc.Message { - var m *object.GetRangeHashResponse_Body - - if r != nil { - m = new(object.GetRangeHashResponse_Body) - - m.SetType(refs.ChecksumTypeToGRPC(r.typ)) - m.SetHashList(r.hashList) - } - - return m -} - -func (r *GetRangeHashResponseBody) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*object.GetRangeHashResponse_Body) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - r.typ = refs.ChecksumTypeFromGRPC(v.GetType()) - r.hashList = v.GetHashList() - - return nil -} - -func (r *GetRangeHashResponse) ToGRPCMessage() grpc.Message { - var m *object.GetRangeHashResponse - - if r != nil { - m = new(object.GetRangeHashResponse) - - m.SetBody(r.body.ToGRPCMessage().(*object.GetRangeHashResponse_Body)) - r.ResponseHeaders.ToMessage(m) - } - - return m -} - -func (r *GetRangeHashResponse) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*object.GetRangeHashResponse) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var err error - - body := v.GetBody() - if body == nil { - r.body = nil - } else { - if r.body == nil { - r.body = new(GetRangeHashResponseBody) - } - - err = r.body.FromGRPCMessage(body) - if err != nil { - return err - } - } - - return r.ResponseHeaders.FromMessage(v) -} - -func (r *PutSingleRequestBody) ToGRPCMessage() grpc.Message { - var m *object.PutSingleRequest_Body - - if r != nil { - m = new(object.PutSingleRequest_Body) - m.SetObject(r.GetObject().ToGRPCMessage().(*object.Object)) - m.SetCopiesNumber(r.GetCopiesNumber()) - } - - return m -} - -func (r *PutSingleRequestBody) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*object.PutSingleRequest_Body) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - if v.GetObject() == nil { - r.object = nil - } else { - if r.object == nil { - r.object = new(Object) - } - - err := r.object.FromGRPCMessage(v.GetObject()) - if err != nil { - return err - } - } - - r.copyNum = v.GetCopiesNumber() - - return nil -} - -func (r *PutSingleRequest) ToGRPCMessage() grpc.Message { - var m *object.PutSingleRequest - - if r != nil { - m = new(object.PutSingleRequest) - - m.SetBody(r.body.ToGRPCMessage().(*object.PutSingleRequest_Body)) - r.RequestHeaders.ToMessage(m) - } - - return m -} - -func (r *PutSingleRequest) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*object.PutSingleRequest) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - body := v.GetBody() - if body == nil { - r.body = nil - } else { - if r.body == nil { - r.body = new(PutSingleRequestBody) - } - - err := r.body.FromGRPCMessage(body) - if err != nil { - return err - } - } - - return r.RequestHeaders.FromMessage(v) -} - -func (r *PutSingleResponseBody) ToGRPCMessage() grpc.Message { - var b *object.PutSingleResponse_Body - if r != nil { - b = new(object.PutSingleResponse_Body) - } - return b -} - -func (r *PutSingleResponseBody) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*object.PutSingleResponse_Body) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - return nil -} - -func (r *PutSingleResponse) ToGRPCMessage() grpc.Message { - var m *object.PutSingleResponse - - if r != nil { - m = new(object.PutSingleResponse) - - m.SetBody(r.body.ToGRPCMessage().(*object.PutSingleResponse_Body)) - r.ResponseHeaders.ToMessage(m) - } - - return m -} - -func (r *PutSingleResponse) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*object.PutSingleResponse) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var err error - - body := v.GetBody() - if body == nil { - r.body = nil - } else { - if r.body == nil { - r.body = new(PutSingleResponseBody) - } - - err = r.body.FromGRPCMessage(body) - if err != nil { - return err - } - } - - return r.ResponseHeaders.FromMessage(v) -} diff --git a/object/grpc/service.go b/object/grpc/service.go index 27645dd..c79cd33 100644 --- a/object/grpc/service.go +++ b/object/grpc/service.go @@ -5,6 +5,12 @@ import ( session "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/session/grpc" ) +type GetResponseBodyObjectPart = isGetResponse_Body_ObjectPart + +type GetRangeResponseBodyRangePart = isGetRangeResponse_Body_RangePart + +type HeadResponseBodyHead = isHeadResponse_Body_Head + // SetAddress sets address of the requested object. func (m *GetRequest_Body) SetAddress(v *refs.Address) { m.Address = v @@ -535,3 +541,11 @@ func (m *PutSingleResponse) SetMetaHeader(v *session.ResponseMetaHeader) { func (m *PutSingleResponse) SetVerifyHeader(v *session.ResponseVerificationHeader) { m.VerifyHeader = v } + +func (r *PutRequest_Body_Init_) GetCopiesNumber() []uint32 { + if r != nil { + return r.Init.CopiesNumber + } + + return nil +} diff --git a/object/grpc/service.pb.go b/object/grpc/service.pb.go index c6ffb20..4012a07 100644 Binary files a/object/grpc/service.pb.go and b/object/grpc/service.pb.go differ diff --git a/object/grpc/service_frostfs.pb.go b/object/grpc/service_frostfs.pb.go new file mode 100644 index 0000000..5abe6f9 Binary files /dev/null and b/object/grpc/service_frostfs.pb.go differ diff --git a/object/grpc/service_grpc.pb.go b/object/grpc/service_grpc.pb.go index 3c71ec8..ebf233b 100644 Binary files a/object/grpc/service_grpc.pb.go and b/object/grpc/service_grpc.pb.go differ diff --git a/object/grpc/types.pb.go b/object/grpc/types.pb.go index 5c79080..39cd2ed 100644 Binary files a/object/grpc/types.pb.go and b/object/grpc/types.pb.go differ diff --git a/object/grpc/types_frostfs.pb.go b/object/grpc/types_frostfs.pb.go new file mode 100644 index 0000000..708fd57 Binary files /dev/null and b/object/grpc/types_frostfs.pb.go differ diff --git a/object/json.go b/object/json.go deleted file mode 100644 index 1a04031..0000000 --- a/object/json.go +++ /dev/null @@ -1,78 +0,0 @@ -package object - -import ( - object "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/object/grpc" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message" -) - -func (h *ShortHeader) MarshalJSON() ([]byte, error) { - return message.MarshalJSON(h) -} - -func (h *ShortHeader) UnmarshalJSON(data []byte) error { - return message.UnmarshalJSON(h, data, new(object.ShortHeader)) -} - -func (a *Attribute) MarshalJSON() ([]byte, error) { - return message.MarshalJSON(a) -} - -func (a *Attribute) UnmarshalJSON(data []byte) error { - return message.UnmarshalJSON(a, data, new(object.Header_Attribute)) -} - -func (h *SplitHeader) MarshalJSON() ([]byte, error) { - return message.MarshalJSON(h) -} - -func (h *SplitHeader) UnmarshalJSON(data []byte) error { - return message.UnmarshalJSON(h, data, new(object.Header_Split)) -} - -func (h *Header) MarshalJSON() ([]byte, error) { - return message.MarshalJSON(h) -} - -func (h *Header) UnmarshalJSON(data []byte) error { - return message.UnmarshalJSON(h, data, new(object.Header)) -} - -func (h *HeaderWithSignature) MarshalJSON() ([]byte, error) { - return message.MarshalJSON(h) -} - -func (h *HeaderWithSignature) UnmarshalJSON(data []byte) error { - return message.UnmarshalJSON(h, data, new(object.HeaderWithSignature)) -} - -func (o *Object) MarshalJSON() ([]byte, error) { - return message.MarshalJSON(o) -} - -func (o *Object) UnmarshalJSON(data []byte) error { - return message.UnmarshalJSON(o, data, new(object.Object)) -} - -func (s *SplitInfo) MarshalJSON() ([]byte, error) { - return message.MarshalJSON(s) -} - -func (s *SplitInfo) UnmarshalJSON(data []byte) error { - return message.UnmarshalJSON(s, data, new(object.SplitInfo)) -} - -func (f *SearchFilter) MarshalJSON() ([]byte, error) { - return message.MarshalJSON(f) -} - -func (f *SearchFilter) UnmarshalJSON(data []byte) error { - return message.UnmarshalJSON(f, data, new(object.SearchRequest_Body_Filter)) -} - -func (r *Range) MarshalJSON() ([]byte, error) { - return message.MarshalJSON(r) -} - -func (r *Range) UnmarshalJSON(data []byte) error { - return message.UnmarshalJSON(r, data, new(object.Range)) -} diff --git a/object/lock.go b/object/lock.go deleted file mode 100644 index 62ba4a9..0000000 --- a/object/lock.go +++ /dev/null @@ -1,160 +0,0 @@ -package object - -import ( - "errors" - "fmt" - - lock "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/lock/grpc" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs" - refsGRPC "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs/grpc" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/grpc" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/util/proto" -) - -// Lock represents object Lock message from NeoFS API V2 protocol. -type Lock struct { - members []refs.ObjectID -} - -// NumberOfMembers returns length of lock list. -func (x *Lock) NumberOfMembers() int { - if x != nil { - return len(x.members) - } - - return 0 -} - -// IterateMembers passes members of the lock list to f. -func (x *Lock) IterateMembers(f func(refs.ObjectID)) { - if x != nil { - for i := range x.members { - f(x.members[i]) - } - } -} - -// SetMembers sets list of locked members. -// Arg must not be mutated for the duration of the Lock. -func (x *Lock) SetMembers(ids []refs.ObjectID) { - x.members = ids -} - -const ( - _ = iota - fNumLockMembers -) - -// StableMarshal encodes the Lock into Protocol Buffers binary format -// with direct field order. -func (x *Lock) StableMarshal(buf []byte) []byte { - if x == nil || len(x.members) == 0 { - return []byte{} - } - - if buf == nil { - buf = make([]byte, x.StableSize()) - } - - var offset int - - for i := range x.members { - offset += proto.NestedStructureMarshal(fNumLockMembers, buf[offset:], &x.members[i]) - } - - return buf -} - -// StableSize size of the buffer required to write the Lock in Protocol Buffers -// binary format. -func (x *Lock) StableSize() (sz int) { - if x != nil { - for i := range x.members { - sz += proto.NestedStructureSize(fNumLockMembers, &x.members[i]) - } - } - - return -} - -// Unmarshal decodes the Lock from its Protocol Buffers binary format. -func (x *Lock) Unmarshal(data []byte) error { - return message.Unmarshal(x, data, new(lock.Lock)) -} - -func (x *Lock) ToGRPCMessage() grpc.Message { - var m *lock.Lock - - if x != nil { - m = new(lock.Lock) - - var members []*refsGRPC.ObjectID - - if x.members != nil { - members = make([]*refsGRPC.ObjectID, len(x.members)) - - for i := range x.members { - members[i] = x.members[i].ToGRPCMessage().(*refsGRPC.ObjectID) - } - } - - m.SetMembers(members) - } - - return m -} - -func (x *Lock) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*lock.Lock) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - members := v.GetMembers() - if members == nil { - x.members = nil - } else { - x.members = make([]refs.ObjectID, len(members)) - var err error - - for i := range x.members { - err = x.members[i].FromGRPCMessage(members[i]) - if err != nil { - return err - } - } - } - - return nil -} - -// WriteLock writes Lock to the Object as a payload content. -// The object must not be nil. -func WriteLock(obj *Object, lock Lock) { - hdr := obj.GetHeader() - if hdr == nil { - hdr = new(Header) - obj.SetHeader(hdr) - } - - hdr.SetObjectType(TypeLock) - - payload := lock.StableMarshal(nil) - obj.SetPayload(payload) -} - -// ReadLock reads Lock from the Object payload content. -func ReadLock(lock *Lock, obj Object) error { - payload := obj.GetPayload() - if len(payload) == 0 { - return errors.New("empty payload") - } - - err := lock.Unmarshal(payload) - if err != nil { - return fmt.Errorf("decode lock content from payload: %w", err) - } - - return nil -} diff --git a/object/lock_test.go b/object/lock_test.go deleted file mode 100644 index 41b159d..0000000 --- a/object/lock_test.go +++ /dev/null @@ -1,26 +0,0 @@ -package object_test - -import ( - "testing" - - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/object" - objecttest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/object/test" - "github.com/stretchr/testify/require" -) - -func TestLockRW(t *testing.T) { - var l object.Lock - var obj object.Object - - require.Error(t, object.ReadLock(&l, obj)) - - l = *objecttest.GenerateLock(false) - - object.WriteLock(&obj, l) - - var l2 object.Lock - - require.NoError(t, object.ReadLock(&l2, obj)) - - require.Equal(t, l, l2) -} diff --git a/object/marshal.go b/object/marshal.go deleted file mode 100644 index fe0e232..0000000 --- a/object/marshal.go +++ /dev/null @@ -1,1120 +0,0 @@ -package object - -import ( - object "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/object/grpc" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/util/proto" -) - -const ( - shortHdrVersionField = 1 - shortHdrEpochField = 2 - shortHdrOwnerField = 3 - shortHdrObjectTypeField = 4 - shortHdrPayloadLength = 5 - shortHdrHashField = 6 - shortHdrHomoHashField = 7 - - attributeKeyField = 1 - attributeValueField = 2 - - splitHdrParentField = 1 - splitHdrPreviousField = 2 - splitHdrParentSignatureField = 3 - splitHdrParentHeaderField = 4 - splitHdrChildrenField = 5 - splitHdrSplitIDField = 6 - - hdrVersionField = 1 - hdrContainerIDField = 2 - hdrOwnerIDField = 3 - hdrEpochField = 4 - hdrPayloadLengthField = 5 - hdrPayloadHashField = 6 - hdrObjectTypeField = 7 - hdrHomomorphicHashField = 8 - hdrSessionTokenField = 9 - hdrAttributesField = 10 - hdrSplitField = 11 - - hdrWithSigHeaderField = 1 - hdrWithSigSignatureField = 2 - - objIDField = 1 - objSignatureField = 2 - objHeaderField = 3 - objPayloadField = 4 - - splitInfoSplitIDField = 1 - splitInfoLastPartField = 2 - splitInfoLinkField = 3 - - getReqBodyAddressField = 1 - getReqBodyRawFlagField = 2 - - getRespInitObjectIDField = 1 - getRespInitSignatureField = 2 - getRespInitHeaderField = 3 - - getRespBodyInitField = 1 - getRespBodyChunkField = 2 - getRespBodySplitInfoField = 3 - - putReqInitObjectIDField = 1 - putReqInitSignatureField = 2 - putReqInitHeaderField = 3 - putReqInitCopiesNumField = 4 - - putReqBodyInitField = 1 - putReqBodyChunkField = 2 - - putRespBodyObjectIDField = 1 - - deleteReqBodyAddressField = 1 - - deleteRespBodyTombstoneFNum = 1 - - headReqBodyAddressField = 1 - headReqBodyMainFlagField = 2 - headReqBodyRawFlagField = 3 - - headRespBodyHeaderField = 1 - headRespBodyShortHeaderField = 2 - headRespBodySplitInfoField = 3 - - searchFilterMatchField = 1 - searchFilterNameField = 2 - searchFilterValueField = 3 - - searchReqBodyContainerIDField = 1 - searchReqBodyVersionField = 2 - searchReqBodyFiltersField = 3 - - searchRespBodyObjectIDsField = 1 - - rangeOffsetField = 1 - rangeLengthField = 2 - - getRangeReqBodyAddressField = 1 - getRangeReqBodyRangeField = 2 - getRangeReqBodyRawField = 3 - - getRangeRespChunkField = 1 - getRangeRespSplitInfoField = 2 - - getRangeHashReqBodyAddressField = 1 - getRangeHashReqBodyRangesField = 2 - getRangeHashReqBodySaltField = 3 - getRangeHashReqBodyTypeField = 4 - - getRangeHashRespBodyTypeField = 1 - getRangeHashRespBodyHashListField = 2 - - putSingleReqObjectField = 1 - putSingleReqCopiesNumberField = 2 -) - -func (h *ShortHeader) StableMarshal(buf []byte) []byte { - if h == nil { - return []byte{} - } - - if buf == nil { - buf = make([]byte, h.StableSize()) - } - - var offset int - - offset += proto.NestedStructureMarshal(shortHdrVersionField, buf[offset:], h.version) - offset += proto.UInt64Marshal(shortHdrEpochField, buf[offset:], h.creatEpoch) - offset += proto.NestedStructureMarshal(shortHdrOwnerField, buf[offset:], h.ownerID) - offset += proto.EnumMarshal(shortHdrObjectTypeField, buf[offset:], int32(h.typ)) - offset += proto.UInt64Marshal(shortHdrPayloadLength, buf[offset:], h.payloadLen) - offset += proto.NestedStructureMarshal(shortHdrHashField, buf[offset:], h.payloadHash) - proto.NestedStructureMarshal(shortHdrHomoHashField, buf[offset:], h.homoHash) - - return buf -} - -func (h *ShortHeader) StableSize() (size int) { - if h == nil { - return 0 - } - - size += proto.NestedStructureSize(shortHdrVersionField, h.version) - size += proto.UInt64Size(shortHdrEpochField, h.creatEpoch) - size += proto.NestedStructureSize(shortHdrOwnerField, h.ownerID) - size += proto.EnumSize(shortHdrObjectTypeField, int32(h.typ)) - size += proto.UInt64Size(shortHdrPayloadLength, h.payloadLen) - size += proto.NestedStructureSize(shortHdrHashField, h.payloadHash) - size += proto.NestedStructureSize(shortHdrHomoHashField, h.homoHash) - - return size -} - -func (h *ShortHeader) Unmarshal(data []byte) error { - return message.Unmarshal(h, data, new(object.ShortHeader)) -} - -func (a *Attribute) StableMarshal(buf []byte) []byte { - if a == nil { - return []byte{} - } - - if buf == nil { - buf = make([]byte, a.StableSize()) - } - - var offset int - - offset += proto.StringMarshal(attributeKeyField, buf[offset:], a.key) - proto.StringMarshal(attributeValueField, buf[offset:], a.val) - - return buf -} - -func (a *Attribute) StableSize() (size int) { - if a == nil { - return 0 - } - - size += proto.StringSize(shortHdrVersionField, a.key) - size += proto.StringSize(shortHdrEpochField, a.val) - - return size -} - -func (a *Attribute) Unmarshal(data []byte) error { - return message.Unmarshal(a, data, new(object.Header_Attribute)) -} - -func (h *SplitHeader) StableMarshal(buf []byte) []byte { - if h == nil { - return []byte{} - } - - if buf == nil { - buf = make([]byte, h.StableSize()) - } - - var offset int - - offset += proto.NestedStructureMarshal(splitHdrParentField, buf[offset:], h.par) - offset += proto.NestedStructureMarshal(splitHdrPreviousField, buf[offset:], h.prev) - offset += proto.NestedStructureMarshal(splitHdrParentSignatureField, buf[offset:], h.parSig) - offset += proto.NestedStructureMarshal(splitHdrParentHeaderField, buf[offset:], h.parHdr) - offset += refs.ObjectIDNestedListMarshal(splitHdrChildrenField, buf[offset:], h.children) - proto.BytesMarshal(splitHdrSplitIDField, buf[offset:], h.splitID) - - return buf -} - -func (h *SplitHeader) StableSize() (size int) { - if h == nil { - return 0 - } - - size += proto.NestedStructureSize(splitHdrParentField, h.par) - size += proto.NestedStructureSize(splitHdrPreviousField, h.prev) - size += proto.NestedStructureSize(splitHdrParentSignatureField, h.parSig) - size += proto.NestedStructureSize(splitHdrParentHeaderField, h.parHdr) - size += refs.ObjectIDNestedListSize(splitHdrChildrenField, h.children) - size += proto.BytesSize(splitHdrSplitIDField, h.splitID) - - return size -} - -func (h *SplitHeader) Unmarshal(data []byte) error { - return message.Unmarshal(h, data, new(object.Header_Split)) -} - -func (h *Header) StableMarshal(buf []byte) []byte { - if h == nil { - return []byte{} - } - - if buf == nil { - buf = make([]byte, h.StableSize()) - } - - var offset int - - offset += proto.NestedStructureMarshal(hdrVersionField, buf[offset:], h.version) - offset += proto.NestedStructureMarshal(hdrContainerIDField, buf[offset:], h.cid) - offset += proto.NestedStructureMarshal(hdrOwnerIDField, buf[offset:], h.ownerID) - offset += proto.UInt64Marshal(hdrEpochField, buf[offset:], h.creatEpoch) - offset += proto.UInt64Marshal(hdrPayloadLengthField, buf[offset:], h.payloadLen) - offset += proto.NestedStructureMarshal(hdrPayloadHashField, buf[offset:], h.payloadHash) - offset += proto.EnumMarshal(hdrObjectTypeField, buf[offset:], int32(h.typ)) - offset += proto.NestedStructureMarshal(hdrHomomorphicHashField, buf[offset:], h.homoHash) - offset += proto.NestedStructureMarshal(hdrSessionTokenField, buf[offset:], h.sessionToken) - - for i := range h.attr { - offset += proto.NestedStructureMarshal(hdrAttributesField, buf[offset:], &h.attr[i]) - } - - proto.NestedStructureMarshal(hdrSplitField, buf[offset:], h.split) - - return buf -} - -func (h *Header) StableSize() (size int) { - if h == nil { - return 0 - } - - size += proto.NestedStructureSize(hdrVersionField, h.version) - size += proto.NestedStructureSize(hdrContainerIDField, h.cid) - size += proto.NestedStructureSize(hdrOwnerIDField, h.ownerID) - size += proto.UInt64Size(hdrEpochField, h.creatEpoch) - size += proto.UInt64Size(hdrPayloadLengthField, h.payloadLen) - size += proto.NestedStructureSize(hdrPayloadHashField, h.payloadHash) - size += proto.EnumSize(hdrObjectTypeField, int32(h.typ)) - size += proto.NestedStructureSize(hdrHomomorphicHashField, h.homoHash) - size += proto.NestedStructureSize(hdrSessionTokenField, h.sessionToken) - for i := range h.attr { - size += proto.NestedStructureSize(hdrAttributesField, &h.attr[i]) - } - size += proto.NestedStructureSize(hdrSplitField, h.split) - - return size -} - -func (h *Header) Unmarshal(data []byte) error { - return message.Unmarshal(h, data, new(object.Header)) -} - -func (h *HeaderWithSignature) StableMarshal(buf []byte) []byte { - if h == nil { - return []byte{} - } - - if buf == nil { - buf = make([]byte, h.StableSize()) - } - - var offset int - - offset += proto.NestedStructureMarshal(hdrWithSigHeaderField, buf[offset:], h.header) - proto.NestedStructureMarshal(hdrWithSigSignatureField, buf[offset:], h.signature) - - return buf -} - -func (h *HeaderWithSignature) StableSize() (size int) { - if h == nil { - return 0 - } - - size += proto.NestedStructureSize(hdrVersionField, h.header) - size += proto.NestedStructureSize(hdrContainerIDField, h.signature) - - return size -} - -func (h *HeaderWithSignature) Unmarshal(data []byte) error { - return message.Unmarshal(h, data, new(object.HeaderWithSignature)) -} - -func (o *Object) StableMarshal(buf []byte) []byte { - if o == nil { - return []byte{} - } - - if buf == nil { - buf = make([]byte, o.StableSize()) - } - - var offset int - - offset += proto.NestedStructureMarshal(objIDField, buf[offset:], o.objectID) - offset += proto.NestedStructureMarshal(objSignatureField, buf[offset:], o.idSig) - offset += proto.NestedStructureMarshal(objHeaderField, buf[offset:], o.header) - proto.BytesMarshal(objPayloadField, buf[offset:], o.payload) - - return buf -} - -func (o *Object) StableSize() (size int) { - if o == nil { - return 0 - } - - size += proto.NestedStructureSize(objIDField, o.objectID) - size += proto.NestedStructureSize(objSignatureField, o.idSig) - size += proto.NestedStructureSize(objHeaderField, o.header) - size += proto.BytesSize(objPayloadField, o.payload) - - return size -} - -func (o *Object) Unmarshal(data []byte) error { - return message.Unmarshal(o, data, new(object.Object)) -} - -func (s *SplitInfo) StableMarshal(buf []byte) []byte { - if s == nil { - return []byte{} - } - - if buf == nil { - buf = make([]byte, s.StableSize()) - } - - var offset int - - offset += proto.BytesMarshal(splitInfoSplitIDField, buf[offset:], s.splitID) - offset += proto.NestedStructureMarshal(splitInfoLastPartField, buf[offset:], s.lastPart) - proto.NestedStructureMarshal(splitInfoLinkField, buf[offset:], s.link) - - return buf -} - -func (s *SplitInfo) StableSize() (size int) { - if s == nil { - return 0 - } - - size += proto.BytesSize(splitInfoSplitIDField, s.splitID) - size += proto.NestedStructureSize(splitInfoLastPartField, s.lastPart) - size += proto.NestedStructureSize(splitInfoLinkField, s.link) - - return size -} - -func (s *SplitInfo) Unmarshal(data []byte) error { - return message.Unmarshal(s, data, new(object.SplitInfo)) -} - -func (r *GetRequestBody) StableMarshal(buf []byte) []byte { - if r == nil { - return []byte{} - } - - if buf == nil { - buf = make([]byte, r.StableSize()) - } - - var offset int - - offset += proto.NestedStructureMarshal(getReqBodyAddressField, buf[offset:], r.addr) - proto.BoolMarshal(getReqBodyRawFlagField, buf[offset:], r.raw) - - return buf -} - -func (r *GetRequestBody) StableSize() (size int) { - if r == nil { - return 0 - } - - size += proto.NestedStructureSize(getReqBodyAddressField, r.addr) - size += proto.BoolSize(getReqBodyRawFlagField, r.raw) - - return size -} - -func (r *GetRequestBody) Unmarshal(data []byte) error { - return message.Unmarshal(r, data, new(object.GetRequest_Body)) -} - -func (r *GetObjectPartInit) StableMarshal(buf []byte) []byte { - if r == nil { - return []byte{} - } - - if buf == nil { - buf = make([]byte, r.StableSize()) - } - - var offset int - - offset += proto.NestedStructureMarshal(getRespInitObjectIDField, buf[offset:], r.id) - offset += proto.NestedStructureMarshal(getRespInitSignatureField, buf[offset:], r.sig) - proto.NestedStructureMarshal(getRespInitHeaderField, buf[offset:], r.hdr) - - return buf -} - -func (r *GetObjectPartInit) StableSize() (size int) { - if r == nil { - return 0 - } - - size += proto.NestedStructureSize(getRespInitObjectIDField, r.id) - size += proto.NestedStructureSize(getRespInitSignatureField, r.sig) - size += proto.NestedStructureSize(getRespInitHeaderField, r.hdr) - - return size -} - -func (r *GetObjectPartInit) Unmarshal(data []byte) error { - return message.Unmarshal(r, data, new(object.GetResponse_Body_Init)) -} - -func (r *GetResponseBody) StableMarshal(buf []byte) []byte { - if r == nil { - return []byte{} - } - - if buf == nil { - buf = make([]byte, r.StableSize()) - } - - switch v := r.objPart.(type) { - case nil: - case *GetObjectPartInit: - proto.NestedStructureMarshal(getRespBodyInitField, buf, v) - case *GetObjectPartChunk: - if v != nil { - proto.BytesMarshal(getRespBodyChunkField, buf, v.chunk) - } - case *SplitInfo: - proto.NestedStructureMarshal(getRespBodySplitInfoField, buf, v) - default: - panic("unknown one of object get response body type") - } - - return buf -} - -func (r *GetResponseBody) StableSize() (size int) { - if r == nil { - return 0 - } - - switch v := r.objPart.(type) { - case nil: - case *GetObjectPartInit: - size += proto.NestedStructureSize(getRespBodyInitField, v) - case *GetObjectPartChunk: - if v != nil { - size += proto.BytesSize(getRespBodyChunkField, v.chunk) - } - case *SplitInfo: - size += proto.NestedStructureSize(getRespBodySplitInfoField, v) - default: - panic("unknown one of object get response body type") - } - - return -} - -func (r *GetResponseBody) Unmarshal(data []byte) error { - return message.Unmarshal(r, data, new(object.GetResponse_Body)) -} - -func (r *PutObjectPartInit) StableMarshal(buf []byte) []byte { - if r == nil { - return []byte{} - } - - if buf == nil { - buf = make([]byte, r.StableSize()) - } - - var offset int - - offset += proto.NestedStructureMarshal(putReqInitObjectIDField, buf[offset:], r.id) - offset += proto.NestedStructureMarshal(putReqInitSignatureField, buf[offset:], r.sig) - offset += proto.NestedStructureMarshal(putReqInitHeaderField, buf[offset:], r.hdr) - proto.RepeatedUInt32Marshal(putReqInitCopiesNumField, buf[offset:], r.copyNum) - - return buf -} - -func (r *PutObjectPartInit) StableSize() (size int) { - if r == nil { - return 0 - } - - size += proto.NestedStructureSize(putReqInitObjectIDField, r.id) - size += proto.NestedStructureSize(putReqInitSignatureField, r.sig) - size += proto.NestedStructureSize(putReqInitHeaderField, r.hdr) - - arrSize, _ := proto.RepeatedUInt32Size(putReqInitCopiesNumField, r.copyNum) - size += arrSize - - return size -} - -func (r *PutObjectPartInit) Unmarshal(data []byte) error { - return message.Unmarshal(r, data, new(object.PutRequest_Body_Init)) -} - -func (r *PutRequestBody) StableMarshal(buf []byte) []byte { - if r == nil { - return []byte{} - } - - if buf == nil { - buf = make([]byte, r.StableSize()) - } - - switch v := r.objPart.(type) { - case nil: - case *PutObjectPartInit: - proto.NestedStructureMarshal(putReqBodyInitField, buf, v) - case *PutObjectPartChunk: - if v != nil { - proto.BytesMarshal(putReqBodyChunkField, buf, v.chunk) - } - default: - panic("unknown one of object put request body type") - } - - return buf -} - -func (r *PutRequestBody) StableSize() (size int) { - if r == nil { - return 0 - } - - switch v := r.objPart.(type) { - case nil: - case *PutObjectPartInit: - size += proto.NestedStructureSize(putReqBodyInitField, v) - case *PutObjectPartChunk: - if v != nil { - size += proto.BytesSize(putReqBodyChunkField, v.chunk) - } - default: - panic("unknown one of object get response body type") - } - - return size -} - -func (r *PutRequestBody) Unmarshal(data []byte) error { - return message.Unmarshal(r, data, new(object.PutRequest_Body)) -} - -func (r *PutResponseBody) StableMarshal(buf []byte) []byte { - if r == nil { - return []byte{} - } - - if buf == nil { - buf = make([]byte, r.StableSize()) - } - - proto.NestedStructureMarshal(putRespBodyObjectIDField, buf, r.id) - - return buf -} - -func (r *PutResponseBody) StableSize() (size int) { - if r == nil { - return 0 - } - - size += proto.NestedStructureSize(putRespBodyObjectIDField, r.id) - - return size -} - -func (r *PutResponseBody) Unmarshal(data []byte) error { - return message.Unmarshal(r, data, new(object.PutResponse_Body)) -} - -func (r *DeleteRequestBody) StableMarshal(buf []byte) []byte { - if r == nil { - return []byte{} - } - - if buf == nil { - buf = make([]byte, r.StableSize()) - } - - proto.NestedStructureMarshal(deleteReqBodyAddressField, buf, r.addr) - - return buf -} - -func (r *DeleteRequestBody) StableSize() (size int) { - if r == nil { - return 0 - } - - size += proto.NestedStructureSize(deleteReqBodyAddressField, r.addr) - - return size -} - -func (r *DeleteRequestBody) Unmarshal(data []byte) error { - return message.Unmarshal(r, data, new(object.DeleteRequest_Body)) -} - -func (r *DeleteResponseBody) StableMarshal(buf []byte) []byte { - if r == nil { - return []byte{} - } - - if buf == nil { - buf = make([]byte, r.StableSize()) - } - - proto.NestedStructureMarshal(deleteRespBodyTombstoneFNum, buf, r.tombstone) - - return buf -} - -func (r *DeleteResponseBody) StableSize() (size int) { - if r == nil { - return 0 - } - - size += proto.NestedStructureSize(deleteRespBodyTombstoneFNum, r.tombstone) - - return size -} - -func (r *DeleteResponseBody) Unmarshal(data []byte) error { - return message.Unmarshal(r, data, new(object.DeleteResponse_Body)) -} - -func (r *HeadRequestBody) StableMarshal(buf []byte) []byte { - if r == nil { - return []byte{} - } - - if buf == nil { - buf = make([]byte, r.StableSize()) - } - - var offset int - - offset += proto.NestedStructureMarshal(headReqBodyAddressField, buf[offset:], r.addr) - offset += proto.BoolMarshal(headReqBodyMainFlagField, buf[offset:], r.mainOnly) - proto.BoolMarshal(headReqBodyRawFlagField, buf[offset:], r.raw) - - return buf -} - -func (r *HeadRequestBody) StableSize() (size int) { - if r == nil { - return 0 - } - - size += proto.NestedStructureSize(headReqBodyAddressField, r.addr) - size += proto.BoolSize(headReqBodyMainFlagField, r.mainOnly) - size += proto.BoolSize(headReqBodyRawFlagField, r.raw) - - return size -} - -func (r *HeadRequestBody) Unmarshal(data []byte) error { - return message.Unmarshal(r, data, new(object.HeadRequest_Body)) -} - -func (r *HeadResponseBody) StableMarshal(buf []byte) []byte { - if r == nil { - return []byte{} - } - - if buf == nil { - buf = make([]byte, r.StableSize()) - } - - switch v := r.hdrPart.(type) { - case nil: - case *HeaderWithSignature: - if v != nil { - proto.NestedStructureMarshal(headRespBodyHeaderField, buf, v) - } - case *ShortHeader: - if v != nil { - proto.NestedStructureMarshal(headRespBodyShortHeaderField, buf, v) - } - case *SplitInfo: - if v != nil { - proto.NestedStructureMarshal(headRespBodySplitInfoField, buf, v) - } - default: - panic("unknown one of object put request body type") - } - - return buf -} - -func (r *HeadResponseBody) StableSize() (size int) { - if r == nil { - return 0 - } - - switch v := r.hdrPart.(type) { - case nil: - case *HeaderWithSignature: - if v != nil { - size += proto.NestedStructureSize(headRespBodyHeaderField, v) - } - case *ShortHeader: - if v != nil { - size += proto.NestedStructureSize(headRespBodyShortHeaderField, v) - } - case *SplitInfo: - if v != nil { - size += proto.NestedStructureSize(headRespBodySplitInfoField, v) - } - default: - panic("unknown one of object put request body type") - } - - return -} - -func (r *HeadResponseBody) Unmarshal(data []byte) error { - return message.Unmarshal(r, data, new(object.HeadResponse_Body)) -} - -func (f *SearchFilter) StableMarshal(buf []byte) []byte { - if f == nil { - return []byte{} - } - - if buf == nil { - buf = make([]byte, f.StableSize()) - } - - var offset int - - offset += proto.EnumMarshal(searchFilterMatchField, buf[offset:], int32(f.matchType)) - offset += proto.StringMarshal(searchFilterNameField, buf[offset:], f.key) - proto.StringMarshal(searchFilterValueField, buf[offset:], f.val) - - return buf -} - -func (f *SearchFilter) StableSize() (size int) { - if f == nil { - return 0 - } - - size += proto.EnumSize(searchFilterMatchField, int32(f.matchType)) - size += proto.StringSize(searchFilterNameField, f.key) - size += proto.StringSize(searchFilterValueField, f.val) - - return size -} - -func (f *SearchFilter) Unmarshal(data []byte) error { - return message.Unmarshal(f, data, new(object.SearchRequest_Body_Filter)) -} - -func (r *SearchRequestBody) StableMarshal(buf []byte) []byte { - if r == nil { - return []byte{} - } - - if buf == nil { - buf = make([]byte, r.StableSize()) - } - - var offset int - - offset += proto.NestedStructureMarshal(searchReqBodyContainerIDField, buf[offset:], r.cid) - offset += proto.UInt32Marshal(searchReqBodyVersionField, buf[offset:], r.version) - - for i := range r.filters { - offset += proto.NestedStructureMarshal(searchReqBodyFiltersField, buf[offset:], &r.filters[i]) - } - - return buf -} - -func (r *SearchRequestBody) StableSize() (size int) { - if r == nil { - return 0 - } - - size += proto.NestedStructureSize(searchReqBodyContainerIDField, r.cid) - size += proto.UInt32Size(searchReqBodyVersionField, r.version) - - for i := range r.filters { - size += proto.NestedStructureSize(searchReqBodyFiltersField, &r.filters[i]) - } - - return size -} - -func (r *SearchRequestBody) Unmarshal(data []byte) error { - return message.Unmarshal(r, data, new(object.SearchRequest_Body)) -} - -func (r *SearchResponseBody) StableMarshal(buf []byte) []byte { - if r == nil { - return []byte{} - } - - if buf == nil { - buf = make([]byte, r.StableSize()) - } - - var offset int - - refs.ObjectIDNestedListMarshal(searchRespBodyObjectIDsField, buf[offset:], r.idList) - - return buf -} - -func (r *SearchResponseBody) StableSize() (size int) { - if r == nil { - return 0 - } - - size += refs.ObjectIDNestedListSize(searchRespBodyObjectIDsField, r.idList) - - return size -} - -func (r *SearchResponseBody) Unmarshal(data []byte) error { - return message.Unmarshal(r, data, new(object.SearchResponse_Body)) -} - -func (r *Range) StableMarshal(buf []byte) []byte { - if r == nil { - return []byte{} - } - - if buf == nil { - buf = make([]byte, r.StableSize()) - } - - var offset int - - offset += proto.UInt64Marshal(rangeOffsetField, buf[offset:], r.off) - proto.UInt64Marshal(rangeLengthField, buf[offset:], r.len) - - return buf -} - -func (r *Range) StableSize() (size int) { - if r == nil { - return 0 - } - - size += proto.UInt64Size(rangeOffsetField, r.off) - size += proto.UInt64Size(rangeLengthField, r.len) - - return size -} - -func (r *Range) Unmarshal(data []byte) error { - return message.Unmarshal(r, data, new(object.Range)) -} - -func (r *GetRangeRequestBody) StableMarshal(buf []byte) []byte { - if r == nil { - return []byte{} - } - - if buf == nil { - buf = make([]byte, r.StableSize()) - } - - var offset int - - offset += proto.NestedStructureMarshal(getRangeReqBodyAddressField, buf[offset:], r.addr) - offset += proto.NestedStructureMarshal(getRangeReqBodyRangeField, buf[offset:], r.rng) - proto.BoolMarshal(getRangeReqBodyRawField, buf[offset:], r.raw) - - return buf -} - -func (r *GetRangeRequestBody) StableSize() (size int) { - if r == nil { - return 0 - } - - size += proto.NestedStructureSize(getRangeReqBodyAddressField, r.addr) - size += proto.NestedStructureSize(getRangeReqBodyRangeField, r.rng) - size += proto.BoolSize(getRangeReqBodyRawField, r.raw) - - return size -} - -func (r *GetRangeRequestBody) Unmarshal(data []byte) error { - return message.Unmarshal(r, data, new(object.GetRangeRequest_Body)) -} - -func (r *GetRangeResponseBody) StableMarshal(buf []byte) []byte { - if r == nil { - return []byte{} - } - - if buf == nil { - buf = make([]byte, r.StableSize()) - } - - switch v := r.rngPart.(type) { - case nil: - case *GetRangePartChunk: - if v != nil { - proto.BytesMarshal(getRangeRespChunkField, buf, v.chunk) - } - case *SplitInfo: - if v != nil { - proto.NestedStructureMarshal(getRangeRespSplitInfoField, buf, v) - } - default: - panic("unknown one of object get range request body type") - } - - return buf -} - -func (r *GetRangeResponseBody) StableSize() (size int) { - if r == nil { - return 0 - } - - switch v := r.rngPart.(type) { - case nil: - case *GetRangePartChunk: - if v != nil { - size += proto.BytesSize(getRangeRespChunkField, v.chunk) - } - case *SplitInfo: - if v != nil { - size = proto.NestedStructureSize(getRangeRespSplitInfoField, v) - } - default: - panic("unknown one of object get range request body type") - } - - return -} - -func (r *GetRangeResponseBody) Unmarshal(data []byte) error { - return message.Unmarshal(r, data, new(object.GetRangeResponse_Body)) -} - -func (r *GetRangeHashRequestBody) StableMarshal(buf []byte) []byte { - if r == nil { - return []byte{} - } - - if buf == nil { - buf = make([]byte, r.StableSize()) - } - - var offset int - - offset += proto.NestedStructureMarshal(getRangeHashReqBodyAddressField, buf[offset:], r.addr) - - for i := range r.rngs { - offset += proto.NestedStructureMarshal(getRangeHashReqBodyRangesField, buf[offset:], &r.rngs[i]) - } - - offset += proto.BytesMarshal(getRangeHashReqBodySaltField, buf[offset:], r.salt) - proto.EnumMarshal(getRangeHashReqBodyTypeField, buf[offset:], int32(r.typ)) - - return buf -} - -func (r *GetRangeHashRequestBody) StableSize() (size int) { - if r == nil { - return 0 - } - - size += proto.NestedStructureSize(getRangeHashReqBodyAddressField, r.addr) - - for i := range r.rngs { - size += proto.NestedStructureSize(getRangeHashReqBodyRangesField, &r.rngs[i]) - } - - size += proto.BytesSize(getRangeHashReqBodySaltField, r.salt) - size += proto.EnumSize(getRangeHashReqBodyTypeField, int32(r.typ)) - - return size -} - -func (r *GetRangeHashRequestBody) Unmarshal(data []byte) error { - return message.Unmarshal(r, data, new(object.GetRangeHashRequest_Body)) -} - -func (r *GetRangeHashResponseBody) StableMarshal(buf []byte) []byte { - if r == nil { - return []byte{} - } - - if buf == nil { - buf = make([]byte, r.StableSize()) - } - - var offset int - - offset += proto.EnumMarshal(getRangeHashRespBodyTypeField, buf, int32(r.typ)) - proto.RepeatedBytesMarshal(getRangeHashRespBodyHashListField, buf[offset:], r.hashList) - - return buf -} - -func (r *GetRangeHashResponseBody) StableSize() (size int) { - if r == nil { - return 0 - } - - size += proto.EnumSize(getRangeHashRespBodyTypeField, int32(r.typ)) - size += proto.RepeatedBytesSize(getRangeHashRespBodyHashListField, r.hashList) - - return size -} - -func (r *GetRangeHashResponseBody) Unmarshal(data []byte) error { - return message.Unmarshal(r, data, new(object.GetRangeHashResponse_Body)) -} - -func (r *PutSingleRequestBody) StableMarshal(buf []byte) []byte { - if r == nil { - return []byte{} - } - if buf == nil { - buf = make([]byte, r.StableSize()) - } - - var offset int - offset += proto.NestedStructureMarshal(putSingleReqObjectField, buf[offset:], r.object) - proto.RepeatedUInt32Marshal(putSingleReqCopiesNumberField, buf[offset:], r.copyNum) - - return buf -} - -func (r *PutSingleRequestBody) StableSize() int { - if r == nil { - return 0 - } - - var size int - size += proto.NestedStructureSize(putSingleReqObjectField, r.object) - arrSize, _ := proto.RepeatedUInt32Size(putSingleReqCopiesNumberField, r.copyNum) - size += arrSize - - return size -} - -func (r *PutSingleRequestBody) Unmarshal(data []byte) error { - return message.Unmarshal(r, data, new(object.PutSingleRequest_Body)) -} - -func (r *PutSingleResponseBody) StableMarshal(buf []byte) []byte { - if r == nil { - return []byte{} - } - - if buf == nil { - buf = make([]byte, r.StableSize()) - } - - return buf -} - -func (r *PutSingleResponseBody) StableSize() int { - return 0 -} - -func (r *PutSingleResponseBody) Unmarshal(data []byte) error { - return message.Unmarshal(r, data, new(object.PutSingleResponse_Body)) -} diff --git a/object/message_test.go b/object/message_test.go index a111c60..3a1c711 100644 --- a/object/message_test.go +++ b/object/message_test.go @@ -4,54 +4,58 @@ import ( "testing" objecttest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/object/test" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message" messagetest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message/test" + "google.golang.org/protobuf/proto" ) func TestMessageConvert(t *testing.T) { messagetest.TestRPCMessage(t, - func(empty bool) message.Message { return objecttest.GenerateShortHeader(empty) }, - func(empty bool) message.Message { return objecttest.GenerateAttribute(empty) }, - func(empty bool) message.Message { return objecttest.GenerateSplitHeader(empty) }, - func(empty bool) message.Message { return objecttest.GenerateHeader(empty) }, - func(empty bool) message.Message { return objecttest.GenerateObject(empty) }, - func(empty bool) message.Message { return objecttest.GenerateSplitInfo(empty) }, - func(empty bool) message.Message { return objecttest.GenerateGetRequestBody(empty) }, - func(empty bool) message.Message { return objecttest.GenerateGetRequest(empty) }, - func(empty bool) message.Message { return objecttest.GenerateGetObjectPartInit(empty) }, - func(empty bool) message.Message { return objecttest.GenerateGetObjectPartChunk(empty) }, - func(empty bool) message.Message { return objecttest.GenerateGetResponseBody(empty) }, - func(empty bool) message.Message { return objecttest.GenerateGetResponse(empty) }, - func(empty bool) message.Message { return objecttest.GeneratePutObjectPartInit(empty) }, - func(empty bool) message.Message { return objecttest.GeneratePutObjectPartChunk(empty) }, - func(empty bool) message.Message { return objecttest.GeneratePutRequestBody(empty) }, - func(empty bool) message.Message { return objecttest.GeneratePutRequest(empty) }, - func(empty bool) message.Message { return objecttest.GeneratePutResponseBody(empty) }, - func(empty bool) message.Message { return objecttest.GeneratePutResponse(empty) }, - func(empty bool) message.Message { return objecttest.GenerateDeleteRequestBody(empty) }, - func(empty bool) message.Message { return objecttest.GenerateDeleteRequest(empty) }, - func(empty bool) message.Message { return objecttest.GenerateDeleteResponseBody(empty) }, - func(empty bool) message.Message { return objecttest.GenerateDeleteResponse(empty) }, - func(empty bool) message.Message { return objecttest.GenerateHeadRequestBody(empty) }, - func(empty bool) message.Message { return objecttest.GenerateHeadRequest(empty) }, - func(empty bool) message.Message { return objecttest.GenerateHeadResponseBody(empty) }, - func(empty bool) message.Message { return objecttest.GenerateHeadResponse(empty) }, - func(empty bool) message.Message { return objecttest.GenerateSearchFilter(empty) }, - func(empty bool) message.Message { return objecttest.GenerateSearchRequestBody(empty) }, - func(empty bool) message.Message { return objecttest.GenerateSearchRequest(empty) }, - func(empty bool) message.Message { return objecttest.GenerateSearchResponseBody(empty) }, - func(empty bool) message.Message { return objecttest.GenerateSearchResponse(empty) }, - func(empty bool) message.Message { return objecttest.GenerateRange(empty) }, - func(empty bool) message.Message { return objecttest.GenerateGetRangeRequestBody(empty) }, - func(empty bool) message.Message { return objecttest.GenerateGetRangeRequest(empty) }, - func(empty bool) message.Message { return objecttest.GenerateGetRangeResponseBody(empty) }, - func(empty bool) message.Message { return objecttest.GenerateGetRangeResponse(empty) }, - func(empty bool) message.Message { return objecttest.GenerateGetRangeHashRequestBody(empty) }, - func(empty bool) message.Message { return objecttest.GenerateGetRangeHashRequest(empty) }, - func(empty bool) message.Message { return objecttest.GenerateGetRangeHashResponseBody(empty) }, - func(empty bool) message.Message { return objecttest.GenerateGetRangeHashResponse(empty) }, - func(empty bool) message.Message { return objecttest.GenerateLock(empty) }, - func(empty bool) message.Message { return objecttest.GeneratePutSingleRequest(empty) }, - func(empty bool) message.Message { return objecttest.GeneratePutSingleResponse(empty) }, - ) + func(empty bool) proto.Message { return objecttest.GenerateShortHeader(empty) }, + func(empty bool) proto.Message { return objecttest.GenerateAttribute(empty) }, + func(empty bool) proto.Message { return objecttest.GenerateSplitHeader(empty) }, + func(empty bool) proto.Message { return objecttest.GenerateHeader(empty) }, + func(empty bool) proto.Message { return objecttest.GenerateObject(empty) }, + func(empty bool) proto.Message { return objecttest.GenerateSplitInfo(empty) }, + func(empty bool) proto.Message { return objecttest.GenerateGetRequestBody(empty) }, + func(empty bool) proto.Message { return objecttest.GenerateGetRequest(empty) }, + func(empty bool) proto.Message { return objecttest.GenerateGetObjectPartInit(empty) }, + func(empty bool) proto.Message { + return objecttest.GenerateGetResponseBodyWithBodyType(objecttest.InitType) + }, + func(empty bool) proto.Message { + return objecttest.GenerateGetResponseBodyWithBodyType(objecttest.ChunkType) + }, + func(empty bool) proto.Message { + return objecttest.GenerateGetResponseBodyWithBodyType(objecttest.SplitInfoType) + }, + func(empty bool) proto.Message { return objecttest.GenerateGetResponse(empty) }, + func(empty bool) proto.Message { return objecttest.GeneratePutObjectPartInit(empty) }, + func(empty bool) proto.Message { return objecttest.GeneratePutRequestBody(empty) }, + func(empty bool) proto.Message { return objecttest.GeneratePutRequest(empty) }, + func(empty bool) proto.Message { return objecttest.GeneratePutResponseBody(empty) }, + func(empty bool) proto.Message { return objecttest.GeneratePutResponse(empty) }, + func(empty bool) proto.Message { return objecttest.GenerateDeleteRequestBody(empty) }, + func(empty bool) proto.Message { return objecttest.GenerateDeleteRequest(empty) }, + func(empty bool) proto.Message { return objecttest.GenerateDeleteResponseBody(empty) }, + func(empty bool) proto.Message { return objecttest.GenerateDeleteResponse(empty) }, + func(empty bool) proto.Message { return objecttest.GenerateHeadRequestBody(empty) }, + func(empty bool) proto.Message { return objecttest.GenerateHeadRequest(empty) }, + func(empty bool) proto.Message { return objecttest.GenerateHeadResponseBody(empty) }, + func(empty bool) proto.Message { return objecttest.GenerateHeadResponse(empty) }, + func(empty bool) proto.Message { return objecttest.GenerateSearchFilter(empty) }, + func(empty bool) proto.Message { return objecttest.GenerateSearchRequestBody(empty) }, + func(empty bool) proto.Message { return objecttest.GenerateSearchRequest(empty) }, + func(empty bool) proto.Message { return objecttest.GenerateSearchResponseBody(empty) }, + func(empty bool) proto.Message { return objecttest.GenerateSearchResponse(empty) }, + func(empty bool) proto.Message { return objecttest.GenerateRange(empty) }, + func(empty bool) proto.Message { return objecttest.GenerateGetRangeRequestBody(empty) }, + func(empty bool) proto.Message { return objecttest.GenerateGetRangeRequest(empty) }, + func(empty bool) proto.Message { return objecttest.GenerateGetRangeResponseBody(empty) }, + func(empty bool) proto.Message { return objecttest.GenerateGetRangeResponse(empty) }, + func(empty bool) proto.Message { return objecttest.GenerateGetRangeHashRequestBody(empty) }, + func(empty bool) proto.Message { return objecttest.GenerateGetRangeHashRequest(empty) }, + func(empty bool) proto.Message { return objecttest.GenerateGetRangeHashResponseBody(empty) }, + func(empty bool) proto.Message { return objecttest.GenerateGetRangeHashResponse(empty) }, + func(empty bool) proto.Message { return objecttest.GeneratePutSingleRequest(empty) }, + func(empty bool) proto.Message { return objecttest.GeneratePutSingleResponse(empty) }) } diff --git a/object/status.go b/object/status.go index cff8275..36be3b8 100644 --- a/object/status.go +++ b/object/status.go @@ -53,11 +53,11 @@ const ( // into status.Status as a detail. The status must not be nil. // // Existing details are expected to be ID-unique, otherwise undefined behavior. -func WriteAccessDeniedDesc(st *status.Status, desc string) { +func WriteAccessDeniedDesc(st *statusgrpc.Status, desc string) { var found bool - st.IterateDetails(func(d *status.Detail) bool { - if d.ID() == detailAccessDeniedDesc { + st.IterateDetails(func(d *statusgrpc.Status_Detail) bool { + if d.GetId() == detailAccessDeniedDesc { found = true d.SetValue([]byte(desc)) } @@ -66,9 +66,9 @@ func WriteAccessDeniedDesc(st *status.Status, desc string) { }) if !found { - var d status.Detail + d := new(statusgrpc.Status_Detail) - d.SetID(detailAccessDeniedDesc) + d.SetId(detailAccessDeniedDesc) d.SetValue([]byte(desc)) st.AppendDetails(d) @@ -77,10 +77,10 @@ func WriteAccessDeniedDesc(st *status.Status, desc string) { // ReadAccessDeniedDesc looks up for status detail with human-readable description // of StatusAccessDenied. Returns empty string if detail is missing. -func ReadAccessDeniedDesc(st status.Status) (desc string) { - st.IterateDetails(func(d *status.Detail) bool { - if d.ID() == detailAccessDeniedDesc { - desc = string(d.Value()) +func ReadAccessDeniedDesc(st *statusgrpc.Status) (desc string) { + st.IterateDetails(func(d *statusgrpc.Status_Detail) bool { + if d.GetId() == detailAccessDeniedDesc { + desc = string(d.GetValue()) return true } diff --git a/object/status_test.go b/object/status_test.go index 7a9ac13..afa815e 100644 --- a/object/status_test.go +++ b/object/status_test.go @@ -4,7 +4,7 @@ import ( "testing" "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/object" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/status" + statusgrpc "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/status/grpc" statustest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/status/test" "github.com/stretchr/testify/require" ) @@ -21,15 +21,15 @@ func TestStatusCodes(t *testing.T) { } func TestAccessDeniedDesc(t *testing.T) { - var st status.Status + st := new(statusgrpc.Status) require.Empty(t, object.ReadAccessDeniedDesc(st)) const desc = "some description" - object.WriteAccessDeniedDesc(&st, desc) + object.WriteAccessDeniedDesc(st, desc) require.Equal(t, desc, object.ReadAccessDeniedDesc(st)) - object.WriteAccessDeniedDesc(&st, desc+"1") + object.WriteAccessDeniedDesc(st, desc+"1") require.Equal(t, desc+"1", object.ReadAccessDeniedDesc(st)) } diff --git a/object/string.go b/object/string.go deleted file mode 100644 index 6e42c81..0000000 --- a/object/string.go +++ /dev/null @@ -1,55 +0,0 @@ -package object - -import ( - object "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/object/grpc" -) - -// String returns string representation of Type. -func (t Type) String() string { - return TypeToGRPCField(t).String() -} - -// FromString parses Type from a string representation. -// It is a reverse action to String(). -// -// Returns true if s was parsed successfully. -func (t *Type) FromString(s string) bool { - var g object.ObjectType - - ok := g.FromString(s) - - if ok { - *t = TypeFromGRPCField(g) - } - - return ok -} - -// TypeFromString converts string to Type. -// -// Deprecated: use FromString method. -func TypeFromString(s string) (t Type) { - t.FromString(s) - return -} - -// String returns string representation of MatchType. -func (t MatchType) String() string { - return MatchTypeToGRPCField(t).String() -} - -// FromString parses MatchType from a string representation. -// It is a reverse action to String(). -// -// Returns true if s was parsed successfully. -func (t *MatchType) FromString(s string) bool { - var g object.MatchType - - ok := g.FromString(s) - - if ok { - *t = MatchTypeFromGRPCField(g) - } - - return ok -} diff --git a/object/test/generate.go b/object/test/generate.go index fca772c..2a1dd66 100644 --- a/object/test/generate.go +++ b/object/test/generate.go @@ -2,8 +2,7 @@ package objecttest import ( "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/internal/random" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/object" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs" + object "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/object/grpc" refstest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs/test" sessiontest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/session/test" ) @@ -15,7 +14,7 @@ func GenerateShortHeader(empty bool) *object.ShortHeader { m.SetObjectType(13) m.SetCreationEpoch(100) m.SetPayloadLength(12321) - m.SetOwnerID(refstest.GenerateOwnerID(false)) + m.SetOwnerId(refstest.GenerateOwnerID(false)) } m.SetVersion(refstest.GenerateVersion(empty)) @@ -25,8 +24,8 @@ func GenerateShortHeader(empty bool) *object.ShortHeader { return m } -func GenerateAttribute(empty bool) *object.Attribute { - m := new(object.Attribute) +func GenerateAttribute(empty bool) *object.Header_Attribute { + m := new(object.Header_Attribute) if !empty { m.SetKey("object key") @@ -36,28 +35,28 @@ func GenerateAttribute(empty bool) *object.Attribute { return m } -func GenerateAttributes(empty bool) []object.Attribute { - var res []object.Attribute +func GenerateAttributes(empty bool) []*object.Header_Attribute { + var res []*object.Header_Attribute if !empty { res = append(res, - *GenerateAttribute(false), - *GenerateAttribute(false), + GenerateAttribute(false), + GenerateAttribute(false), ) } return res } -func GenerateSplitHeader(empty bool) *object.SplitHeader { +func GenerateSplitHeader(empty bool) *object.Header_Split { return generateSplitHeader(empty, true) } -func generateSplitHeader(empty, withPar bool) *object.SplitHeader { - m := new(object.SplitHeader) +func generateSplitHeader(empty, withPar bool) *object.Header_Split { + m := new(object.Header_Split) if !empty { - m.SetSplitID([]byte{1, 3, 5}) + m.SetSplitId([]byte{1, 3, 5}) m.SetParent(refstest.GenerateObjectID(false)) m.SetPrevious(refstest.GenerateObjectID(false)) m.SetChildren(refstest.GenerateObjectIDs(false)) @@ -83,8 +82,8 @@ func generateHeader(empty, withSplit bool) *object.Header { m.SetPayloadLength(777) m.SetCreationEpoch(432) m.SetObjectType(111) - m.SetOwnerID(refstest.GenerateOwnerID(false)) - m.SetContainerID(refstest.GenerateContainerID(false)) + m.SetOwnerId(refstest.GenerateOwnerID(false)) + m.SetContainerId(refstest.GenerateContainerID(false)) m.SetAttributes(GenerateAttributes(false)) } @@ -114,7 +113,7 @@ func GenerateObject(empty bool) *object.Object { if !empty { m.SetPayload([]byte{7, 8, 9}) - m.SetObjectID(refstest.GenerateObjectID(false)) + m.SetObjectId(refstest.GenerateObjectID(false)) } m.SetSignature(refstest.GenerateSignature(empty)) @@ -127,7 +126,7 @@ func GenerateSplitInfo(empty bool) *object.SplitInfo { m := new(object.SplitInfo) if !empty { - m.SetSplitID([]byte("splitID")) + m.SetSplitId([]byte("splitID")) m.SetLastPart(refstest.GenerateObjectID(false)) m.SetLink(refstest.GenerateObjectID(false)) } @@ -135,8 +134,8 @@ func GenerateSplitInfo(empty bool) *object.SplitInfo { return m } -func GenerateGetRequestBody(empty bool) *object.GetRequestBody { - m := new(object.GetRequestBody) +func GenerateGetRequestBody(empty bool) *object.GetRequest_Body { + m := new(object.GetRequest_Body) if !empty { m.SetRaw(true) @@ -154,16 +153,16 @@ func GenerateGetRequest(empty bool) *object.GetRequest { } m.SetMetaHeader(sessiontest.GenerateRequestMetaHeader(empty)) - m.SetVerificationHeader(sessiontest.GenerateRequestVerificationHeader(empty)) + m.SetVerifyHeader(sessiontest.GenerateRequestVerificationHeader(empty)) return m } -func GenerateGetObjectPartInit(empty bool) *object.GetObjectPartInit { - m := new(object.GetObjectPartInit) +func GenerateGetObjectPartInit(empty bool) *object.GetResponse_Body_Init { + m := new(object.GetResponse_Body_Init) if !empty { - m.SetObjectID(refstest.GenerateObjectID(false)) + m.SetObjectId(refstest.GenerateObjectID(false)) } m.SetSignature(refstest.GenerateSignature(empty)) @@ -172,8 +171,8 @@ func GenerateGetObjectPartInit(empty bool) *object.GetObjectPartInit { return m } -func GenerateGetObjectPartChunk(empty bool) *object.GetObjectPartChunk { - m := new(object.GetObjectPartChunk) +func GenerateGetObjectPartChunk(empty bool) *object.GetResponse_Body_Chunk { + m := new(object.GetResponse_Body_Chunk) if !empty { m.SetChunk([]byte("get chunk")) @@ -182,23 +181,48 @@ func GenerateGetObjectPartChunk(empty bool) *object.GetObjectPartChunk { return m } -func GenerateGetResponseBody(empty bool) *object.GetResponseBody { - m := new(object.GetResponseBody) +func GenerateGetResponseBody(empty bool) *object.GetResponse_Body { + m := new(object.GetResponse_Body) if !empty { switch random.Uint32(3) { case 0: - m.SetObjectPart(GenerateGetObjectPartInit(false)) + m.SetInit(GenerateGetObjectPartInit(false)) case 1: - m.SetObjectPart(GenerateGetObjectPartChunk(false)) + m.SetChunk(GenerateGetObjectPartChunk(false)) case 2: - m.SetObjectPart(GenerateSplitInfo(false)) + m.SetSplitInfo(GenerateSplitInfo(false)) } } return m } +type GetResponseBodyType uint + +const ( + InitType GetResponseBodyType = iota + ChunkType + SplitInfoType +) + +func GenerateGetResponseBodyWithBodyType(bt GetResponseBodyType) *object.GetResponse_Body { + m := new(object.GetResponse_Body) + + switch bt { + case 0: + m.SetInit(GenerateGetObjectPartInit(false)) + case 1: + m.SetChunk(GenerateGetObjectPartChunk(false)) + case 2: + m.SetSplitInfo(GenerateSplitInfo(false)) + default: + panic("undefined body type") + } + + return m +} + func GenerateGetResponse(empty bool) *object.GetResponse { m := new(object.GetResponse) @@ -207,17 +231,17 @@ func GenerateGetResponse(empty bool) *object.GetResponse { } m.SetMetaHeader(sessiontest.GenerateResponseMetaHeader(empty)) - m.SetVerificationHeader(sessiontest.GenerateResponseVerificationHeader(empty)) + m.SetVerifyHeader(sessiontest.GenerateResponseVerificationHeader(empty)) return m } -func GeneratePutObjectPartInit(empty bool) *object.PutObjectPartInit { - m := new(object.PutObjectPartInit) +func GeneratePutObjectPartInit(empty bool) *object.PutRequest_Body_Init { + m := new(object.PutRequest_Body_Init) if !empty { m.SetCopiesNumber([]uint32{234}) - m.SetObjectID(refstest.GenerateObjectID(false)) + m.SetObjectId(refstest.GenerateObjectID(false)) } m.SetSignature(refstest.GenerateSignature(empty)) @@ -226,8 +250,8 @@ func GeneratePutObjectPartInit(empty bool) *object.PutObjectPartInit { return m } -func GeneratePutObjectPartChunk(empty bool) *object.PutObjectPartChunk { - m := new(object.PutObjectPartChunk) +func GeneratePutObjectPartChunk(empty bool) *object.PutRequest_Body_Chunk { + m := new(object.PutRequest_Body_Chunk) if !empty { m.SetChunk([]byte("put chunk")) @@ -236,15 +260,15 @@ func GeneratePutObjectPartChunk(empty bool) *object.PutObjectPartChunk { return m } -func GeneratePutRequestBody(empty bool) *object.PutRequestBody { - m := new(object.PutRequestBody) +func GeneratePutRequestBody(empty bool) *object.PutRequest_Body { + m := new(object.PutRequest_Body) if !empty { switch random.Uint32(2) { case 0: - m.SetObjectPart(GeneratePutObjectPartInit(false)) + m.SetInit(GeneratePutObjectPartInit(false)) case 1: - m.SetObjectPart(GeneratePutObjectPartChunk(false)) + m.SetChunk(GeneratePutObjectPartChunk(false)) } } @@ -259,16 +283,16 @@ func GeneratePutRequest(empty bool) *object.PutRequest { } m.SetMetaHeader(sessiontest.GenerateRequestMetaHeader(empty)) - m.SetVerificationHeader(sessiontest.GenerateRequestVerificationHeader(empty)) + m.SetVerifyHeader(sessiontest.GenerateRequestVerificationHeader(empty)) return m } -func GeneratePutResponseBody(empty bool) *object.PutResponseBody { - m := new(object.PutResponseBody) +func GeneratePutResponseBody(empty bool) *object.PutResponse_Body { + m := new(object.PutResponse_Body) if !empty { - m.SetObjectID(refstest.GenerateObjectID(false)) + m.SetObjectId(refstest.GenerateObjectID(false)) } return m @@ -282,13 +306,13 @@ func GeneratePutResponse(empty bool) *object.PutResponse { } m.SetMetaHeader(sessiontest.GenerateResponseMetaHeader(empty)) - m.SetVerificationHeader(sessiontest.GenerateResponseVerificationHeader(empty)) + m.SetVerifyHeader(sessiontest.GenerateResponseVerificationHeader(empty)) return m } -func GenerateDeleteRequestBody(empty bool) *object.DeleteRequestBody { - m := new(object.DeleteRequestBody) +func GenerateDeleteRequestBody(empty bool) *object.DeleteRequest_Body { + m := new(object.DeleteRequest_Body) if !empty { m.SetAddress(refstest.GenerateAddress(false)) @@ -305,13 +329,13 @@ func GenerateDeleteRequest(empty bool) *object.DeleteRequest { } m.SetMetaHeader(sessiontest.GenerateRequestMetaHeader(empty)) - m.SetVerificationHeader(sessiontest.GenerateRequestVerificationHeader(empty)) + m.SetVerifyHeader(sessiontest.GenerateRequestVerificationHeader(empty)) return m } -func GenerateDeleteResponseBody(empty bool) *object.DeleteResponseBody { - m := new(object.DeleteResponseBody) +func GenerateDeleteResponseBody(empty bool) *object.DeleteResponse_Body { + m := new(object.DeleteResponse_Body) if !empty { m.SetTombstone(refstest.GenerateAddress(false)) @@ -328,13 +352,13 @@ func GenerateDeleteResponse(empty bool) *object.DeleteResponse { } m.SetMetaHeader(sessiontest.GenerateResponseMetaHeader(empty)) - m.SetVerificationHeader(sessiontest.GenerateResponseVerificationHeader(empty)) + m.SetVerifyHeader(sessiontest.GenerateResponseVerificationHeader(empty)) return m } -func GenerateHeadRequestBody(empty bool) *object.HeadRequestBody { - m := new(object.HeadRequestBody) +func GenerateHeadRequestBody(empty bool) *object.HeadRequest_Body { + m := new(object.HeadRequest_Body) if !empty { m.SetRaw(true) @@ -353,22 +377,22 @@ func GenerateHeadRequest(empty bool) *object.HeadRequest { } m.SetMetaHeader(sessiontest.GenerateRequestMetaHeader(empty)) - m.SetVerificationHeader(sessiontest.GenerateRequestVerificationHeader(empty)) + m.SetVerifyHeader(sessiontest.GenerateRequestVerificationHeader(empty)) return m } -func GenerateHeadResponseBody(empty bool) *object.HeadResponseBody { - m := new(object.HeadResponseBody) +func GenerateHeadResponseBody(empty bool) *object.HeadResponse_Body { + m := new(object.HeadResponse_Body) if !empty { switch random.Uint32(3) { case 0: - m.SetHeaderPart(GenerateHeaderWithSignature(false)) + m.SetHeader(GenerateHeaderWithSignature(false)) case 1: - m.SetHeaderPart(GenerateShortHeader(false)) + m.SetShortHeader(GenerateShortHeader(false)) case 2: - m.SetHeaderPart(GenerateSplitInfo(false)) + m.SetSplitInfo(GenerateSplitInfo(false)) } } @@ -383,13 +407,13 @@ func GenerateHeadResponse(empty bool) *object.HeadResponse { } m.SetMetaHeader(sessiontest.GenerateResponseMetaHeader(empty)) - m.SetVerificationHeader(sessiontest.GenerateResponseVerificationHeader(empty)) + m.SetVerifyHeader(sessiontest.GenerateResponseVerificationHeader(empty)) return m } -func GenerateSearchFilter(empty bool) *object.SearchFilter { - m := new(object.SearchFilter) +func GenerateSearchFilter(empty bool) *object.SearchRequest_Body_Filter { + m := new(object.SearchRequest_Body_Filter) if !empty { m.SetKey("search filter key") @@ -400,25 +424,25 @@ func GenerateSearchFilter(empty bool) *object.SearchFilter { return m } -func GenerateSearchFilters(empty bool) []object.SearchFilter { - var res []object.SearchFilter +func GenerateSearchFilters(empty bool) []*object.SearchRequest_Body_Filter { + var res []*object.SearchRequest_Body_Filter if !empty { res = append(res, - *GenerateSearchFilter(false), - *GenerateSearchFilter(false), + GenerateSearchFilter(false), + GenerateSearchFilter(false), ) } return res } -func GenerateSearchRequestBody(empty bool) *object.SearchRequestBody { - m := new(object.SearchRequestBody) +func GenerateSearchRequestBody(empty bool) *object.SearchRequest_Body { + m := new(object.SearchRequest_Body) if !empty { m.SetVersion(555) - m.SetContainerID(refstest.GenerateContainerID(false)) + m.SetContainerId(refstest.GenerateContainerID(false)) m.SetFilters(GenerateSearchFilters(false)) } @@ -433,16 +457,16 @@ func GenerateSearchRequest(empty bool) *object.SearchRequest { } m.SetMetaHeader(sessiontest.GenerateRequestMetaHeader(empty)) - m.SetVerificationHeader(sessiontest.GenerateRequestVerificationHeader(empty)) + m.SetVerifyHeader(sessiontest.GenerateRequestVerificationHeader(empty)) return m } -func GenerateSearchResponseBody(empty bool) *object.SearchResponseBody { - m := new(object.SearchResponseBody) +func GenerateSearchResponseBody(empty bool) *object.SearchResponse_Body { + m := new(object.SearchResponse_Body) if !empty { - m.SetIDList(refstest.GenerateObjectIDs(false)) + m.SetIdList(refstest.GenerateObjectIDs(false)) } return m @@ -456,7 +480,7 @@ func GenerateSearchResponse(empty bool) *object.SearchResponse { } m.SetMetaHeader(sessiontest.GenerateResponseMetaHeader(empty)) - m.SetVerificationHeader(sessiontest.GenerateResponseVerificationHeader(empty)) + m.SetVerifyHeader(sessiontest.GenerateResponseVerificationHeader(empty)) return m } @@ -472,21 +496,21 @@ func GenerateRange(empty bool) *object.Range { return m } -func GenerateRanges(empty bool) []object.Range { - var res []object.Range +func GenerateRanges(empty bool) []*object.Range { + var res []*object.Range if !empty { res = append(res, - *GenerateRange(false), - *GenerateRange(false), + GenerateRange(false), + GenerateRange(false), ) } return res } -func GenerateGetRangeRequestBody(empty bool) *object.GetRangeRequestBody { - m := new(object.GetRangeRequestBody) +func GenerateGetRangeRequestBody(empty bool) *object.GetRangeRequest_Body { + m := new(object.GetRangeRequest_Body) if !empty { m.SetRaw(true) @@ -505,13 +529,13 @@ func GenerateGetRangeRequest(empty bool) *object.GetRangeRequest { } m.SetMetaHeader(sessiontest.GenerateRequestMetaHeader(empty)) - m.SetVerificationHeader(sessiontest.GenerateRequestVerificationHeader(empty)) + m.SetVerifyHeader(sessiontest.GenerateRequestVerificationHeader(empty)) return m } -func GenerateGetRangePartChunk(empty bool) *object.GetRangePartChunk { - m := new(object.GetRangePartChunk) +func GenerateGetRangePartChunk(empty bool) *object.GetRangeResponse_Body_Chunk { + m := new(object.GetRangeResponse_Body_Chunk) if !empty { m.SetChunk([]byte("get range chunk")) @@ -520,15 +544,15 @@ func GenerateGetRangePartChunk(empty bool) *object.GetRangePartChunk { return m } -func GenerateGetRangeResponseBody(empty bool) *object.GetRangeResponseBody { - m := new(object.GetRangeResponseBody) +func GenerateGetRangeResponseBody(empty bool) *object.GetRangeResponse_Body { + m := new(object.GetRangeResponse_Body) if !empty { switch random.Uint32(2) { case 0: - m.SetRangePart(GenerateGetRangePartChunk(false)) + m.SetChunk(GenerateGetRangePartChunk(false)) case 1: - m.SetRangePart(GenerateSplitInfo(false)) + m.SetSplitInfo(GenerateSplitInfo(false)) } } @@ -543,13 +567,13 @@ func GenerateGetRangeResponse(empty bool) *object.GetRangeResponse { } m.SetMetaHeader(sessiontest.GenerateResponseMetaHeader(empty)) - m.SetVerificationHeader(sessiontest.GenerateResponseVerificationHeader(empty)) + m.SetVerifyHeader(sessiontest.GenerateResponseVerificationHeader(empty)) return m } -func GenerateGetRangeHashRequestBody(empty bool) *object.GetRangeHashRequestBody { - m := new(object.GetRangeHashRequestBody) +func GenerateGetRangeHashRequestBody(empty bool) *object.GetRangeHashRequest_Body { + m := new(object.GetRangeHashRequest_Body) if !empty { m.SetSalt([]byte("range hash salt")) @@ -569,13 +593,13 @@ func GenerateGetRangeHashRequest(empty bool) *object.GetRangeHashRequest { } m.SetMetaHeader(sessiontest.GenerateRequestMetaHeader(empty)) - m.SetVerificationHeader(sessiontest.GenerateRequestVerificationHeader(empty)) + m.SetVerifyHeader(sessiontest.GenerateRequestVerificationHeader(empty)) return m } -func GenerateGetRangeHashResponseBody(empty bool) *object.GetRangeHashResponseBody { - m := new(object.GetRangeHashResponseBody) +func GenerateGetRangeHashResponseBody(empty bool) *object.GetRangeHashResponse_Body { + m := new(object.GetRangeHashResponse_Body) if !empty { m.SetType(678) @@ -593,20 +617,7 @@ func GenerateGetRangeHashResponse(empty bool) *object.GetRangeHashResponse { } m.SetMetaHeader(sessiontest.GenerateResponseMetaHeader(empty)) - m.SetVerificationHeader(sessiontest.GenerateResponseVerificationHeader(empty)) - - return m -} - -func GenerateLock(empty bool) *object.Lock { - m := new(object.Lock) - - if !empty { - m.SetMembers([]refs.ObjectID{ - *refstest.GenerateObjectID(false), - *refstest.GenerateObjectID(false), - }) - } + m.SetVerifyHeader(sessiontest.GenerateResponseVerificationHeader(empty)) return m } @@ -619,13 +630,13 @@ func GeneratePutSingleRequest(empty bool) *object.PutSingleRequest { } m.SetMetaHeader(sessiontest.GenerateRequestMetaHeader(empty)) - m.SetVerificationHeader(sessiontest.GenerateRequestVerificationHeader(empty)) + m.SetVerifyHeader(sessiontest.GenerateRequestVerificationHeader(empty)) return m } -func GeneratePutSingleRequestBody(empty bool) *object.PutSingleRequestBody { - b := new(object.PutSingleRequestBody) +func GeneratePutSingleRequestBody(empty bool) *object.PutSingleRequest_Body { + b := new(object.PutSingleRequest_Body) if !empty { b.SetObject(GenerateObject(empty)) b.SetCopiesNumber([]uint32{12345}) @@ -636,9 +647,9 @@ func GeneratePutSingleRequestBody(empty bool) *object.PutSingleRequestBody { func GeneratePutSingleResponse(empty bool) *object.PutSingleResponse { m := new(object.PutSingleResponse) if !empty { - m.SetBody(new(object.PutSingleResponseBody)) + m.SetBody(new(object.PutSingleResponse_Body)) } m.SetMetaHeader(sessiontest.GenerateResponseMetaHeader(empty)) - m.SetVerificationHeader(sessiontest.GenerateResponseVerificationHeader(empty)) + m.SetVerifyHeader(sessiontest.GenerateResponseVerificationHeader(empty)) return m } diff --git a/object/types.go b/object/types.go deleted file mode 100644 index d22b428..0000000 --- a/object/types.go +++ /dev/null @@ -1,1473 +0,0 @@ -package object - -import ( - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/session" -) - -type Type uint32 - -type MatchType uint32 - -type ShortHeader struct { - version *refs.Version - - creatEpoch uint64 - - ownerID *refs.OwnerID - - typ Type - - payloadLen uint64 - - payloadHash, homoHash *refs.Checksum -} - -type Attribute struct { - key, val string -} - -type SplitHeader struct { - par, prev *refs.ObjectID - - parSig *refs.Signature - - parHdr *Header - - children []refs.ObjectID - - splitID []byte -} - -type Header struct { - version *refs.Version - - cid *refs.ContainerID - - ownerID *refs.OwnerID - - creatEpoch uint64 - - payloadLen uint64 - - payloadHash, homoHash *refs.Checksum - - typ Type - - sessionToken *session.Token - - attr []Attribute - - split *SplitHeader -} - -type HeaderWithSignature struct { - header *Header - - signature *refs.Signature -} - -type Object struct { - objectID *refs.ObjectID - - idSig *refs.Signature - - header *Header - - payload []byte -} - -type SplitInfo struct { - splitID []byte - - lastPart *refs.ObjectID - - link *refs.ObjectID -} - -type GetRequestBody struct { - addr *refs.Address - - raw bool -} - -type GetObjectPart interface { - getObjectPart() -} - -type GetObjectPartInit struct { - id *refs.ObjectID - - sig *refs.Signature - - hdr *Header -} - -type GetObjectPartChunk struct { - chunk []byte -} - -type GetRequest struct { - body *GetRequestBody - - session.RequestHeaders -} - -type GetResponseBody struct { - objPart GetObjectPart -} - -type PutObjectPart interface { - putObjectPart() -} - -type PutObjectPartInit struct { - id *refs.ObjectID - - sig *refs.Signature - - hdr *Header - - copyNum []uint32 -} - -type PutObjectPartChunk struct { - chunk []byte -} - -type GetResponse struct { - body *GetResponseBody - - session.ResponseHeaders -} - -type PutRequestBody struct { - objPart PutObjectPart -} - -type PutRequest struct { - body *PutRequestBody - - session.RequestHeaders -} - -type PutResponseBody struct { - id *refs.ObjectID -} - -type PutResponse struct { - body *PutResponseBody - - session.ResponseHeaders -} - -type DeleteRequestBody struct { - addr *refs.Address -} - -type DeleteRequest struct { - body *DeleteRequestBody - - session.RequestHeaders -} - -type DeleteResponseBody struct { - tombstone *refs.Address -} - -type DeleteResponse struct { - body *DeleteResponseBody - - session.ResponseHeaders -} - -type HeadRequestBody struct { - addr *refs.Address - - mainOnly, raw bool -} - -type GetHeaderPart interface { - getHeaderPart() -} - -type HeadRequest struct { - body *HeadRequestBody - - session.RequestHeaders -} - -type HeadResponseBody struct { - hdrPart GetHeaderPart -} - -type HeadResponse struct { - body *HeadResponseBody - - session.ResponseHeaders -} - -type SearchFilter struct { - matchType MatchType - - key, val string -} - -type SearchRequestBody struct { - cid *refs.ContainerID - - version uint32 - - filters []SearchFilter -} - -type SearchRequest struct { - body *SearchRequestBody - - session.RequestHeaders -} - -type SearchResponseBody struct { - idList []refs.ObjectID -} - -type SearchResponse struct { - body *SearchResponseBody - - session.ResponseHeaders -} - -type Range struct { - off, len uint64 -} - -type GetRangeRequestBody struct { - addr *refs.Address - - rng *Range - - raw bool -} - -type GetRangeRequest struct { - body *GetRangeRequestBody - - session.RequestHeaders -} - -type GetRangePart interface { - getRangePart() -} - -type GetRangePartChunk struct { - chunk []byte -} - -type GetRangeResponseBody struct { - rngPart GetRangePart -} - -type GetRangeResponse struct { - body *GetRangeResponseBody - - session.ResponseHeaders -} - -type GetRangeHashRequestBody struct { - addr *refs.Address - - rngs []Range - - salt []byte - - typ refs.ChecksumType -} - -type GetRangeHashRequest struct { - body *GetRangeHashRequestBody - - session.RequestHeaders -} - -type GetRangeHashResponseBody struct { - typ refs.ChecksumType - - hashList [][]byte -} - -type GetRangeHashResponse struct { - body *GetRangeHashResponseBody - - session.ResponseHeaders -} - -type PutSingleRequestBody struct { - object *Object - copyNum []uint32 -} - -type PutSingleRequest struct { - body *PutSingleRequestBody - - session.RequestHeaders -} - -type PutSingleResponseBody struct { -} - -type PutSingleResponse struct { - body *PutSingleResponseBody - - session.ResponseHeaders -} - -const ( - TypeRegular Type = iota - TypeTombstone - TypeStorageGroup - TypeLock -) - -const ( - MatchUnknown MatchType = iota - MatchStringEqual - MatchStringNotEqual - MatchNotPresent - MatchCommonPrefix -) - -func (h *ShortHeader) GetVersion() *refs.Version { - if h != nil { - return h.version - } - - return nil -} - -func (h *ShortHeader) SetVersion(v *refs.Version) { - h.version = v -} - -func (h *ShortHeader) GetCreationEpoch() uint64 { - if h != nil { - return h.creatEpoch - } - - return 0 -} - -func (h *ShortHeader) SetCreationEpoch(v uint64) { - h.creatEpoch = v -} - -func (h *ShortHeader) GetOwnerID() *refs.OwnerID { - if h != nil { - return h.ownerID - } - - return nil -} - -func (h *ShortHeader) SetOwnerID(v *refs.OwnerID) { - h.ownerID = v -} - -func (h *ShortHeader) GetObjectType() Type { - if h != nil { - return h.typ - } - - return TypeRegular -} - -func (h *ShortHeader) SetObjectType(v Type) { - h.typ = v -} - -func (h *ShortHeader) GetPayloadLength() uint64 { - if h != nil { - return h.payloadLen - } - - return 0 -} - -func (h *ShortHeader) SetPayloadLength(v uint64) { - h.payloadLen = v -} - -func (h *ShortHeader) GetPayloadHash() *refs.Checksum { - if h != nil { - return h.payloadHash - } - - return nil -} - -func (h *ShortHeader) SetPayloadHash(v *refs.Checksum) { - h.payloadHash = v -} - -func (h *ShortHeader) GetHomomorphicHash() *refs.Checksum { - if h != nil { - return h.homoHash - } - - return nil -} - -func (h *ShortHeader) SetHomomorphicHash(v *refs.Checksum) { - h.homoHash = v -} - -func (h *ShortHeader) getHeaderPart() {} - -func (a *Attribute) GetKey() string { - if a != nil { - return a.key - } - - return "" -} - -func (a *Attribute) SetKey(v string) { - a.key = v -} - -func (a *Attribute) GetValue() string { - if a != nil { - return a.val - } - - return "" -} - -func (a *Attribute) SetValue(v string) { - a.val = v -} - -func (h *SplitHeader) GetParent() *refs.ObjectID { - if h != nil { - return h.par - } - - return nil -} - -func (h *SplitHeader) SetParent(v *refs.ObjectID) { - h.par = v -} - -func (h *SplitHeader) GetPrevious() *refs.ObjectID { - if h != nil { - return h.prev - } - - return nil -} - -func (h *SplitHeader) SetPrevious(v *refs.ObjectID) { - h.prev = v -} - -func (h *SplitHeader) GetParentSignature() *refs.Signature { - if h != nil { - return h.parSig - } - - return nil -} - -func (h *SplitHeader) SetParentSignature(v *refs.Signature) { - h.parSig = v -} - -func (h *SplitHeader) GetParentHeader() *Header { - if h != nil { - return h.parHdr - } - - return nil -} - -func (h *SplitHeader) SetParentHeader(v *Header) { - h.parHdr = v -} - -func (h *SplitHeader) GetChildren() []refs.ObjectID { - if h != nil { - return h.children - } - - return nil -} - -func (h *SplitHeader) SetChildren(v []refs.ObjectID) { - h.children = v -} - -func (h *SplitHeader) GetSplitID() []byte { - if h != nil { - return h.splitID - } - - return nil -} - -func (h *SplitHeader) SetSplitID(v []byte) { - h.splitID = v -} - -func (h *Header) GetVersion() *refs.Version { - if h != nil { - return h.version - } - - return nil -} - -func (h *Header) SetVersion(v *refs.Version) { - h.version = v -} - -func (h *Header) GetContainerID() *refs.ContainerID { - if h != nil { - return h.cid - } - - return nil -} - -func (h *Header) SetContainerID(v *refs.ContainerID) { - h.cid = v -} - -func (h *Header) GetOwnerID() *refs.OwnerID { - if h != nil { - return h.ownerID - } - - return nil -} - -func (h *Header) SetOwnerID(v *refs.OwnerID) { - h.ownerID = v -} - -func (h *Header) GetCreationEpoch() uint64 { - if h != nil { - return h.creatEpoch - } - - return 0 -} - -func (h *Header) SetCreationEpoch(v uint64) { - h.creatEpoch = v -} - -func (h *Header) GetPayloadLength() uint64 { - if h != nil { - return h.payloadLen - } - - return 0 -} - -func (h *Header) SetPayloadLength(v uint64) { - h.payloadLen = v -} - -func (h *Header) GetPayloadHash() *refs.Checksum { - if h != nil { - return h.payloadHash - } - - return nil -} - -func (h *Header) SetPayloadHash(v *refs.Checksum) { - h.payloadHash = v -} - -func (h *Header) GetObjectType() Type { - if h != nil { - return h.typ - } - - return TypeRegular -} - -func (h *Header) SetObjectType(v Type) { - h.typ = v -} - -func (h *Header) GetHomomorphicHash() *refs.Checksum { - if h != nil { - return h.homoHash - } - - return nil -} - -func (h *Header) SetHomomorphicHash(v *refs.Checksum) { - h.homoHash = v -} - -func (h *Header) GetSessionToken() *session.Token { - if h != nil { - return h.sessionToken - } - - return nil -} - -func (h *Header) SetSessionToken(v *session.Token) { - h.sessionToken = v -} - -func (h *Header) GetAttributes() []Attribute { - if h != nil { - return h.attr - } - - return nil -} - -func (h *Header) SetAttributes(v []Attribute) { - h.attr = v -} - -func (h *Header) GetSplit() *SplitHeader { - if h != nil { - return h.split - } - - return nil -} - -func (h *Header) SetSplit(v *SplitHeader) { - h.split = v -} - -func (h *HeaderWithSignature) GetHeader() *Header { - if h != nil { - return h.header - } - - return nil -} - -func (h *HeaderWithSignature) SetHeader(v *Header) { - h.header = v -} - -func (h *HeaderWithSignature) GetSignature() *refs.Signature { - if h != nil { - return h.signature - } - - return nil -} - -func (h *HeaderWithSignature) SetSignature(v *refs.Signature) { - h.signature = v -} - -func (h *HeaderWithSignature) getHeaderPart() {} - -func (o *Object) GetObjectID() *refs.ObjectID { - if o != nil { - return o.objectID - } - - return nil -} - -func (o *Object) SetObjectID(v *refs.ObjectID) { - o.objectID = v -} - -func (o *Object) GetSignature() *refs.Signature { - if o != nil { - return o.idSig - } - - return nil -} - -func (o *Object) SetSignature(v *refs.Signature) { - o.idSig = v -} - -func (o *Object) GetHeader() *Header { - if o != nil { - return o.header - } - - return nil -} - -func (o *Object) SetHeader(v *Header) { - o.header = v -} - -func (o *Object) GetPayload() []byte { - if o != nil { - return o.payload - } - - return nil -} - -func (o *Object) SetPayload(v []byte) { - o.payload = v -} - -func (s *SplitInfo) GetSplitID() []byte { - if s != nil { - return s.splitID - } - - return nil -} - -func (s *SplitInfo) SetSplitID(v []byte) { - s.splitID = v -} - -func (s *SplitInfo) GetLastPart() *refs.ObjectID { - if s != nil { - return s.lastPart - } - - return nil -} - -func (s *SplitInfo) SetLastPart(v *refs.ObjectID) { - s.lastPart = v -} - -func (s *SplitInfo) GetLink() *refs.ObjectID { - if s != nil { - return s.link - } - - return nil -} - -func (s *SplitInfo) SetLink(v *refs.ObjectID) { - s.link = v -} - -func (s *SplitInfo) getObjectPart() {} - -func (s *SplitInfo) getHeaderPart() {} - -func (s *SplitInfo) getRangePart() {} - -func (r *GetRequestBody) GetAddress() *refs.Address { - if r != nil { - return r.addr - } - - return nil -} - -func (r *GetRequestBody) SetAddress(v *refs.Address) { - r.addr = v -} - -func (r *GetRequestBody) GetRaw() bool { - if r != nil { - return r.raw - } - - return false -} - -func (r *GetRequestBody) SetRaw(v bool) { - r.raw = v -} - -func (r *GetRequest) GetBody() *GetRequestBody { - if r != nil { - return r.body - } - - return nil -} - -func (r *GetRequest) SetBody(v *GetRequestBody) { - r.body = v -} - -func (r *GetObjectPartInit) GetObjectID() *refs.ObjectID { - if r != nil { - return r.id - } - - return nil -} - -func (r *GetObjectPartInit) SetObjectID(v *refs.ObjectID) { - r.id = v -} - -func (r *GetObjectPartInit) GetSignature() *refs.Signature { - if r != nil { - return r.sig - } - - return nil -} - -func (r *GetObjectPartInit) SetSignature(v *refs.Signature) { - r.sig = v -} - -func (r *GetObjectPartInit) GetHeader() *Header { - if r != nil { - return r.hdr - } - - return nil -} - -func (r *GetObjectPartInit) SetHeader(v *Header) { - r.hdr = v -} - -func (r *GetObjectPartInit) getObjectPart() {} - -func (r *GetObjectPartChunk) GetChunk() []byte { - if r != nil { - return r.chunk - } - - return nil -} - -func (r *GetObjectPartChunk) SetChunk(v []byte) { - r.chunk = v -} - -func (r *GetObjectPartChunk) getObjectPart() {} - -func (r *GetResponseBody) GetObjectPart() GetObjectPart { - if r != nil { - return r.objPart - } - - return nil -} - -func (r *GetResponseBody) SetObjectPart(v GetObjectPart) { - r.objPart = v -} - -func (r *GetResponse) GetBody() *GetResponseBody { - if r != nil { - return r.body - } - - return nil -} - -func (r *GetResponse) SetBody(v *GetResponseBody) { - r.body = v -} - -func (r *PutObjectPartInit) GetObjectID() *refs.ObjectID { - if r != nil { - return r.id - } - - return nil -} - -func (r *PutObjectPartInit) SetObjectID(v *refs.ObjectID) { - r.id = v -} - -func (r *PutObjectPartInit) GetSignature() *refs.Signature { - if r != nil { - return r.sig - } - - return nil -} - -func (r *PutObjectPartInit) SetSignature(v *refs.Signature) { - r.sig = v -} - -func (r *PutObjectPartInit) GetHeader() *Header { - if r != nil { - return r.hdr - } - - return nil -} - -func (r *PutObjectPartInit) SetHeader(v *Header) { - r.hdr = v -} - -func (r *PutObjectPartInit) GetCopiesNumber() []uint32 { - if r != nil { - return r.copyNum - } - - return nil -} - -func (r *PutObjectPartInit) SetCopiesNumber(v []uint32) { - r.copyNum = v -} - -func (r *PutObjectPartInit) putObjectPart() {} - -func (r *PutObjectPartChunk) GetChunk() []byte { - if r != nil { - return r.chunk - } - - return nil -} - -func (r *PutObjectPartChunk) SetChunk(v []byte) { - r.chunk = v -} - -func (r *PutObjectPartChunk) putObjectPart() {} - -func (r *PutRequestBody) GetObjectPart() PutObjectPart { - if r != nil { - return r.objPart - } - - return nil -} - -func (r *PutRequestBody) SetObjectPart(v PutObjectPart) { - r.objPart = v -} - -func (r *PutRequest) GetBody() *PutRequestBody { - if r != nil { - return r.body - } - - return nil -} - -func (r *PutRequest) SetBody(v *PutRequestBody) { - r.body = v -} - -func (r *PutResponseBody) GetObjectID() *refs.ObjectID { - if r != nil { - return r.id - } - - return nil -} - -func (r *PutResponseBody) SetObjectID(v *refs.ObjectID) { - r.id = v -} - -func (r *PutResponse) GetBody() *PutResponseBody { - if r != nil { - return r.body - } - - return nil -} - -func (r *PutResponse) SetBody(v *PutResponseBody) { - r.body = v -} - -func (r *DeleteRequestBody) GetAddress() *refs.Address { - if r != nil { - return r.addr - } - - return nil -} - -func (r *DeleteRequestBody) SetAddress(v *refs.Address) { - r.addr = v -} - -func (r *DeleteRequest) GetBody() *DeleteRequestBody { - if r != nil { - return r.body - } - - return nil -} - -func (r *DeleteRequest) SetBody(v *DeleteRequestBody) { - r.body = v -} - -// GetTombstone returns tombstone address. -func (r *DeleteResponseBody) GetTombstone() *refs.Address { - if r != nil { - return r.tombstone - } - - return nil -} - -// SetTombstone sets tombstone address. -func (r *DeleteResponseBody) SetTombstone(v *refs.Address) { - r.tombstone = v -} - -func (r *DeleteResponse) GetBody() *DeleteResponseBody { - if r != nil { - return r.body - } - - return nil -} - -func (r *DeleteResponse) SetBody(v *DeleteResponseBody) { - r.body = v -} - -func (r *HeadRequestBody) GetAddress() *refs.Address { - if r != nil { - return r.addr - } - - return nil -} - -func (r *HeadRequestBody) SetAddress(v *refs.Address) { - r.addr = v -} - -func (r *HeadRequestBody) GetMainOnly() bool { - if r != nil { - return r.mainOnly - } - - return false -} - -func (r *HeadRequestBody) SetMainOnly(v bool) { - r.mainOnly = v -} - -func (r *HeadRequestBody) GetRaw() bool { - if r != nil { - return r.raw - } - - return false -} - -func (r *HeadRequestBody) SetRaw(v bool) { - r.raw = v -} - -func (r *HeadRequest) GetBody() *HeadRequestBody { - if r != nil { - return r.body - } - - return nil -} - -func (r *HeadRequest) SetBody(v *HeadRequestBody) { - r.body = v -} - -func (r *HeadResponseBody) GetHeaderPart() GetHeaderPart { - if r != nil { - return r.hdrPart - } - - return nil -} - -func (r *HeadResponseBody) SetHeaderPart(v GetHeaderPart) { - r.hdrPart = v -} - -func (r *HeadResponse) GetBody() *HeadResponseBody { - if r != nil { - return r.body - } - - return nil -} - -func (r *HeadResponse) SetBody(v *HeadResponseBody) { - r.body = v -} - -func (f *SearchFilter) GetMatchType() MatchType { - if f != nil { - return f.matchType - } - - return MatchUnknown -} - -func (f *SearchFilter) SetMatchType(v MatchType) { - f.matchType = v -} - -func (f *SearchFilter) GetKey() string { - if f != nil { - return f.key - } - - return "" -} - -func (f *SearchFilter) SetKey(v string) { - f.key = v -} - -func (f *SearchFilter) GetValue() string { - if f != nil { - return f.val - } - - return "" -} - -func (f *SearchFilter) SetValue(v string) { - f.val = v -} - -func (r *SearchRequestBody) GetContainerID() *refs.ContainerID { - if r != nil { - return r.cid - } - - return nil -} - -func (r *SearchRequestBody) SetContainerID(v *refs.ContainerID) { - r.cid = v -} - -func (r *SearchRequestBody) GetVersion() uint32 { - if r != nil { - return r.version - } - - return 0 -} - -func (r *SearchRequestBody) SetVersion(v uint32) { - r.version = v -} - -func (r *SearchRequestBody) GetFilters() []SearchFilter { - if r != nil { - return r.filters - } - - return nil -} - -func (r *SearchRequestBody) SetFilters(v []SearchFilter) { - r.filters = v -} - -func (r *SearchRequest) GetBody() *SearchRequestBody { - if r != nil { - return r.body - } - - return nil -} - -func (r *SearchRequest) SetBody(v *SearchRequestBody) { - r.body = v -} - -func (r *SearchResponseBody) GetIDList() []refs.ObjectID { - if r != nil { - return r.idList - } - - return nil -} - -func (r *SearchResponseBody) SetIDList(v []refs.ObjectID) { - r.idList = v -} - -func (r *SearchResponse) GetBody() *SearchResponseBody { - if r != nil { - return r.body - } - - return nil -} - -func (r *SearchResponse) SetBody(v *SearchResponseBody) { - r.body = v -} - -func (r *Range) GetOffset() uint64 { - if r != nil { - return r.off - } - - return 0 -} - -func (r *Range) SetOffset(v uint64) { - r.off = v -} - -func (r *Range) GetLength() uint64 { - if r != nil { - return r.len - } - - return 0 -} - -func (r *Range) SetLength(v uint64) { - r.len = v -} - -func (r *GetRangeRequestBody) GetAddress() *refs.Address { - if r != nil { - return r.addr - } - - return nil -} - -func (r *GetRangeRequestBody) SetAddress(v *refs.Address) { - r.addr = v -} - -func (r *GetRangeRequestBody) GetRange() *Range { - if r != nil { - return r.rng - } - - return nil -} - -func (r *GetRangeRequestBody) SetRange(v *Range) { - r.rng = v -} - -func (r *GetRangeRequestBody) GetRaw() bool { - if r != nil { - return r.raw - } - - return false -} - -func (r *GetRangeRequestBody) SetRaw(v bool) { - r.raw = v -} - -func (r *GetRangeRequest) GetBody() *GetRangeRequestBody { - if r != nil { - return r.body - } - - return nil -} - -func (r *GetRangeRequest) SetBody(v *GetRangeRequestBody) { - r.body = v -} - -func (r *GetRangePartChunk) GetChunk() []byte { - if r != nil { - return r.chunk - } - - return nil -} - -func (r *GetRangePartChunk) SetChunk(v []byte) { - r.chunk = v -} - -func (r *GetRangePartChunk) getRangePart() {} - -func (r *GetRangeResponseBody) GetRangePart() GetRangePart { - if r != nil { - return r.rngPart - } - - return nil -} - -func (r *GetRangeResponseBody) SetRangePart(v GetRangePart) { - r.rngPart = v -} - -func (r *GetRangeResponse) GetBody() *GetRangeResponseBody { - if r != nil { - return r.body - } - - return nil -} - -func (r *GetRangeResponse) SetBody(v *GetRangeResponseBody) { - r.body = v -} - -func (r *GetRangeHashRequestBody) GetAddress() *refs.Address { - if r != nil { - return r.addr - } - - return nil -} - -func (r *GetRangeHashRequestBody) SetAddress(v *refs.Address) { - r.addr = v -} - -func (r *GetRangeHashRequestBody) GetRanges() []Range { - if r != nil { - return r.rngs - } - - return nil -} - -func (r *GetRangeHashRequestBody) SetRanges(v []Range) { - r.rngs = v -} - -func (r *GetRangeHashRequestBody) GetSalt() []byte { - if r != nil { - return r.salt - } - - return nil -} - -func (r *GetRangeHashRequestBody) SetSalt(v []byte) { - r.salt = v -} - -func (r *GetRangeHashRequestBody) GetType() refs.ChecksumType { - if r != nil { - return r.typ - } - - return refs.UnknownChecksum -} - -func (r *GetRangeHashRequestBody) SetType(v refs.ChecksumType) { - r.typ = v -} - -func (r *GetRangeHashRequest) GetBody() *GetRangeHashRequestBody { - if r != nil { - return r.body - } - - return nil -} - -func (r *GetRangeHashRequest) SetBody(v *GetRangeHashRequestBody) { - r.body = v -} - -func (r *GetRangeHashResponseBody) GetType() refs.ChecksumType { - if r != nil { - return r.typ - } - - return refs.UnknownChecksum -} - -func (r *GetRangeHashResponseBody) SetType(v refs.ChecksumType) { - r.typ = v -} - -func (r *GetRangeHashResponseBody) GetHashList() [][]byte { - if r != nil { - return r.hashList - } - - return nil -} - -func (r *GetRangeHashResponseBody) SetHashList(v [][]byte) { - r.hashList = v -} - -func (r *GetRangeHashResponse) GetBody() *GetRangeHashResponseBody { - if r != nil { - return r.body - } - - return nil -} - -func (r *GetRangeHashResponse) SetBody(v *GetRangeHashResponseBody) { - r.body = v -} - -func (r *PutSingleRequest) GetBody() *PutSingleRequestBody { - if r != nil { - return r.body - } - - return nil -} - -func (r *PutSingleRequest) SetBody(v *PutSingleRequestBody) { - r.body = v -} - -func (b *PutSingleRequestBody) GetObject() *Object { - if b == nil { - return nil - } - return b.object -} - -func (b *PutSingleRequestBody) SetObject(o *Object) { - b.object = o -} - -func (b *PutSingleRequestBody) GetCopiesNumber() []uint32 { - if b == nil { - return nil - } - return b.copyNum -} - -func (b *PutSingleRequestBody) SetCopiesNumber(v []uint32) { - b.copyNum = v -} - -func (r *PutSingleResponse) GetBody() *PutSingleResponseBody { - if r != nil { - return r.body - } - - return nil -} - -func (r *PutSingleResponse) SetBody(v *PutSingleResponseBody) { - r.body = v -} diff --git a/refs/bench_test.go b/refs/bench_test.go index b24e674..8d3fc49 100644 --- a/refs/bench_test.go +++ b/refs/bench_test.go @@ -1,9 +1,11 @@ package refs import ( - "math/rand" "strconv" "testing" + + refstest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs/test" + "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/util/proto" ) func BenchmarkObjectIDSlice(b *testing.B) { @@ -15,37 +17,23 @@ func BenchmarkObjectIDSlice(b *testing.B) { } func benchmarkObjectIDSlice(b *testing.B, size int) { - ids := make([]ObjectID, size) - for i := range ids { - ids[i].val = make([]byte, 32) - rand.Read(ids[i].val) - } - raw := ObjectIDListToGRPCMessage(ids) + ids := refstest.GenerateObjectIDs(false) - b.Run("to grpc message", func(b *testing.B) { - b.ReportAllocs() - for i := 0; i < b.N; i++ { - raw := ObjectIDListToGRPCMessage(ids) - if len(raw) != len(ids) { - b.FailNow() - } - } - }) - b.Run("from grpc message", func(b *testing.B) { - b.ReportAllocs() - for i := 0; i < b.N; i++ { - ids, err := ObjectIDListFromGRPCMessage(raw) - if err != nil || len(raw) != len(ids) { - b.FailNow() - } - } - }) b.Run("marshal", func(b *testing.B) { b.ReportAllocs() for i := 0; i < b.N; i++ { - buf := make([]byte, ObjectIDNestedListSize(1, ids)) - n := ObjectIDNestedListMarshal(1, buf, ids) - if n != len(buf) { + size := 0 + for _, id := range ids { + size += proto.NestedStructureSize(9, id) + } + + buf := make([]byte, size) + offset := 0 + for _, id := range ids { + offset += proto.NestedStructureMarshal(9, buf[offset:], id) + } + + if offset != len(buf) { b.FailNow() } } diff --git a/refs/convert.go b/refs/convert.go deleted file mode 100644 index b2c353c..0000000 --- a/refs/convert.go +++ /dev/null @@ -1,268 +0,0 @@ -package refs - -import ( - refs "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs/grpc" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/grpc" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message" -) - -func (o *OwnerID) ToGRPCMessage() grpc.Message { - var m *refs.OwnerID - - if o != nil { - m = new(refs.OwnerID) - - m.SetValue(o.val) - } - - return m -} - -func (o *OwnerID) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*refs.OwnerID) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - o.val = v.GetValue() - - return nil -} - -func (c *ContainerID) ToGRPCMessage() grpc.Message { - var m *refs.ContainerID - - if c != nil { - m = new(refs.ContainerID) - - m.SetValue(c.val) - } - - return m -} - -func (c *ContainerID) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*refs.ContainerID) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - c.val = v.GetValue() - - return nil -} - -func ContainerIDsToGRPCMessage(ids []ContainerID) (res []*refs.ContainerID) { - if ids != nil { - res = make([]*refs.ContainerID, 0, len(ids)) - - for i := range ids { - res = append(res, ids[i].ToGRPCMessage().(*refs.ContainerID)) - } - } - - return -} - -func ContainerIDsFromGRPCMessage(idsV2 []*refs.ContainerID) (res []ContainerID, err error) { - if idsV2 != nil { - res = make([]ContainerID, len(idsV2)) - - for i := range idsV2 { - if idsV2[i] != nil { - err = res[i].FromGRPCMessage(idsV2[i]) - if err != nil { - return - } - } - } - } - - return -} - -func (o *ObjectID) ToGRPCMessage() grpc.Message { - var m *refs.ObjectID - - if o != nil { - m = new(refs.ObjectID) - - m.SetValue(o.val) - } - - return m -} - -func (o *ObjectID) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*refs.ObjectID) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - o.val = v.GetValue() - - return nil -} - -func ObjectIDListToGRPCMessage(ids []ObjectID) (res []*refs.ObjectID) { - if ids != nil { - res = make([]*refs.ObjectID, 0, len(ids)) - - for i := range ids { - res = append(res, ids[i].ToGRPCMessage().(*refs.ObjectID)) - } - } - - return -} - -func ObjectIDListFromGRPCMessage(idsV2 []*refs.ObjectID) (res []ObjectID, err error) { - if idsV2 != nil { - res = make([]ObjectID, len(idsV2)) - - for i := range idsV2 { - if idsV2[i] != nil { - err = res[i].FromGRPCMessage(idsV2[i]) - if err != nil { - return - } - } - } - } - - return -} - -func (a *Address) ToGRPCMessage() grpc.Message { - var m *refs.Address - - if a != nil { - m = new(refs.Address) - - m.SetContainerId(a.cid.ToGRPCMessage().(*refs.ContainerID)) - m.SetObjectId(a.oid.ToGRPCMessage().(*refs.ObjectID)) - } - - return m -} - -func (a *Address) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*refs.Address) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var err error - - cid := v.GetContainerId() - if cid == nil { - a.cid = nil - } else { - if a.cid == nil { - a.cid = new(ContainerID) - } - - err = a.cid.FromGRPCMessage(cid) - if err != nil { - return err - } - } - - oid := v.GetObjectId() - if oid == nil { - a.oid = nil - } else { - if a.oid == nil { - a.oid = new(ObjectID) - } - - err = a.oid.FromGRPCMessage(oid) - } - - return err -} - -func ChecksumTypeToGRPC(t ChecksumType) refs.ChecksumType { - return refs.ChecksumType(t) -} - -func ChecksumTypeFromGRPC(t refs.ChecksumType) ChecksumType { - return ChecksumType(t) -} - -func (c *Checksum) ToGRPCMessage() grpc.Message { - var m *refs.Checksum - - if c != nil { - m = new(refs.Checksum) - - m.SetChecksumType(ChecksumTypeToGRPC(c.typ)) - m.SetSum(c.sum) - } - - return m -} - -func (c *Checksum) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*refs.Checksum) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - c.typ = ChecksumTypeFromGRPC(v.GetType()) - c.sum = v.GetSum() - - return nil -} - -func (v *Version) ToGRPCMessage() grpc.Message { - var m *refs.Version - - if v != nil { - m = new(refs.Version) - - m.SetMajor(v.major) - m.SetMinor(v.minor) - } - - return m -} - -func (v *Version) FromGRPCMessage(m grpc.Message) error { - ver, ok := m.(*refs.Version) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - v.major = ver.GetMajor() - v.minor = ver.GetMinor() - - return nil -} - -func (s *Signature) ToGRPCMessage() grpc.Message { - var m *refs.Signature - - if s != nil { - m = new(refs.Signature) - - m.SetKey(s.key) - m.SetSign(s.sign) - m.SetScheme(refs.SignatureScheme(s.scheme)) - } - - return m -} - -func (s *Signature) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*refs.Signature) - if !ok { - return message.NewUnexpectedMessageType(m, s) - } - - s.key = v.GetKey() - s.sign = v.GetSign() - s.scheme = SignatureScheme(v.GetScheme()) - - return nil -} diff --git a/refs/grpc/types.go b/refs/grpc/types.go index 843a2ee..47a0ad8 100644 --- a/refs/grpc/types.go +++ b/refs/grpc/types.go @@ -95,3 +95,27 @@ func (x *ChecksumType) FromString(s string) bool { return ok } + +func (s *Signature) ToRFC6979() *SignatureRFC6979 { + var res *SignatureRFC6979 + + if s != nil { + res = new(SignatureRFC6979) + res.SetKey(s.GetKey()) + res.SetSign(s.GetSign()) + } + + return res +} + +func (s *SignatureRFC6979) FromRFC6979() *Signature { + var res *Signature + + if s != nil { + res = new(Signature) + res.SetKey(s.GetKey()) + res.SetSign(s.GetSign()) + } + + return res +} diff --git a/refs/grpc/types.pb.go b/refs/grpc/types.pb.go index f16583b..7db06b0 100644 Binary files a/refs/grpc/types.pb.go and b/refs/grpc/types.pb.go differ diff --git a/refs/grpc/types_frostfs.pb.go b/refs/grpc/types_frostfs.pb.go new file mode 100644 index 0000000..89de414 Binary files /dev/null and b/refs/grpc/types_frostfs.pb.go differ diff --git a/refs/json.go b/refs/json.go deleted file mode 100644 index 529723a..0000000 --- a/refs/json.go +++ /dev/null @@ -1,62 +0,0 @@ -package refs - -import ( - refs "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs/grpc" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message" -) - -func (a *Address) MarshalJSON() ([]byte, error) { - return message.MarshalJSON(a) -} - -func (a *Address) UnmarshalJSON(data []byte) error { - return message.UnmarshalJSON(a, data, new(refs.Address)) -} - -func (o *ObjectID) MarshalJSON() ([]byte, error) { - return message.MarshalJSON(o) -} - -func (o *ObjectID) UnmarshalJSON(data []byte) error { - return message.UnmarshalJSON(o, data, new(refs.ObjectID)) -} - -func (c *ContainerID) MarshalJSON() ([]byte, error) { - return message.MarshalJSON(c) -} - -func (c *ContainerID) UnmarshalJSON(data []byte) error { - return message.UnmarshalJSON(c, data, new(refs.ContainerID)) -} - -func (o *OwnerID) MarshalJSON() ([]byte, error) { - return message.MarshalJSON(o) -} - -func (o *OwnerID) UnmarshalJSON(data []byte) error { - return message.UnmarshalJSON(o, data, new(refs.OwnerID)) -} - -func (v *Version) MarshalJSON() ([]byte, error) { - return message.MarshalJSON(v) -} - -func (v *Version) UnmarshalJSON(data []byte) error { - return message.UnmarshalJSON(v, data, new(refs.Version)) -} - -func (s *Signature) MarshalJSON() ([]byte, error) { - return message.MarshalJSON(s) -} - -func (s *Signature) UnmarshalJSON(data []byte) error { - return message.UnmarshalJSON(s, data, new(refs.Signature)) -} - -func (c *Checksum) MarshalJSON() ([]byte, error) { - return message.MarshalJSON(c) -} - -func (c *Checksum) UnmarshalJSON(data []byte) error { - return message.UnmarshalJSON(c, data, new(refs.Checksum)) -} diff --git a/refs/marshal.go b/refs/marshal.go deleted file mode 100644 index 0382190..0000000 --- a/refs/marshal.go +++ /dev/null @@ -1,263 +0,0 @@ -package refs - -import ( - "encoding/binary" - - refs "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs/grpc" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/util/proto" -) - -const ( - ownerIDValField = 1 - - containerIDValField = 1 - - objectIDValField = 1 - - addressContainerField = 1 - addressObjectField = 2 - - checksumTypeField = 1 - checksumValueField = 2 - - signatureKeyField = 1 - signatureValueField = 2 - signatureSchemeField = 3 - - versionMajorField = 1 - versionMinorField = 2 -) - -func (o *OwnerID) StableMarshal(buf []byte) []byte { - if o == nil { - return []byte{} - } - - if buf == nil { - buf = make([]byte, o.StableSize()) - } - - proto.BytesMarshal(ownerIDValField, buf, o.val) - - return buf -} - -func (o *OwnerID) StableSize() int { - if o == nil { - return 0 - } - - return proto.BytesSize(ownerIDValField, o.val) -} - -func (o *OwnerID) Unmarshal(data []byte) error { - return message.Unmarshal(o, data, new(refs.OwnerID)) -} - -func (c *ContainerID) StableMarshal(buf []byte) []byte { - if c == nil { - return []byte{} - } - - if buf == nil { - buf = make([]byte, c.StableSize()) - } - - proto.BytesMarshal(containerIDValField, buf, c.val) - - return buf -} - -func (c *ContainerID) StableSize() int { - if c == nil { - return 0 - } - - return proto.BytesSize(containerIDValField, c.val) -} - -func (c *ContainerID) Unmarshal(data []byte) error { - return message.Unmarshal(c, data, new(refs.ContainerID)) -} - -func (o *ObjectID) StableMarshal(buf []byte) []byte { - if o == nil { - return []byte{} - } - - if buf == nil { - buf = make([]byte, o.StableSize()) - } - - proto.BytesMarshal(objectIDValField, buf, o.val) - - return buf -} - -// ObjectIDNestedListSize returns byte length of nested -// repeated ObjectID field with fNum number. -func ObjectIDNestedListSize(fNum int64, ids []ObjectID) (sz int) { - for i := range ids { - sz += proto.NestedStructureSize(fNum, &ids[i]) - } - - return -} - -func (o *ObjectID) StableSize() int { - if o == nil { - return 0 - } - - return proto.BytesSize(objectIDValField, o.val) -} - -// ObjectIDNestedListMarshal writes protobuf repeated ObjectID field -// with fNum number to buf. -func ObjectIDNestedListMarshal(fNum int64, buf []byte, ids []ObjectID) (off int) { - prefix, _ := proto.NestedStructurePrefix(fNum) - for i := range ids { - off += binary.PutUvarint(buf[off:], prefix) - - n := ids[i].StableSize() - off += binary.PutUvarint(buf[off:], uint64(n)) - off += proto.BytesMarshal(objectIDValField, buf[off:], ids[i].val) - } - - return -} - -func (o *ObjectID) Unmarshal(data []byte) error { - return message.Unmarshal(o, data, new(refs.ObjectID)) -} - -func (a *Address) StableMarshal(buf []byte) []byte { - if a == nil { - return []byte{} - } - - if buf == nil { - buf = make([]byte, a.StableSize()) - } - - var offset int - - offset += proto.NestedStructureMarshal(addressContainerField, buf[offset:], a.cid) - proto.NestedStructureMarshal(addressObjectField, buf[offset:], a.oid) - - return buf -} - -func (a *Address) StableSize() (size int) { - if a == nil { - return 0 - } - - size += proto.NestedStructureSize(addressContainerField, a.cid) - size += proto.NestedStructureSize(addressObjectField, a.oid) - - return size -} - -func (a *Address) Unmarshal(data []byte) error { - return message.Unmarshal(a, data, new(refs.Address)) -} - -func (c *Checksum) StableMarshal(buf []byte) []byte { - if c == nil { - return []byte{} - } - - if buf == nil { - buf = make([]byte, c.StableSize()) - } - - var offset int - - offset += proto.EnumMarshal(checksumTypeField, buf[offset:], int32(c.typ)) - proto.BytesMarshal(checksumValueField, buf[offset:], c.sum) - - return buf -} - -func (c *Checksum) StableSize() (size int) { - if c == nil { - return 0 - } - - size += proto.EnumSize(checksumTypeField, int32(c.typ)) - size += proto.BytesSize(checksumValueField, c.sum) - - return size -} - -func (c *Checksum) Unmarshal(data []byte) error { - return message.Unmarshal(c, data, new(refs.Checksum)) -} - -func (s *Signature) StableMarshal(buf []byte) []byte { - if s == nil { - return []byte{} - } - - if buf == nil { - buf = make([]byte, s.StableSize()) - } - - var offset int - - offset += proto.BytesMarshal(signatureKeyField, buf[offset:], s.key) - offset += proto.BytesMarshal(signatureValueField, buf[offset:], s.sign) - proto.EnumMarshal(signatureSchemeField, buf[offset:], int32(s.scheme)) - - return buf -} - -func (s *Signature) StableSize() (size int) { - if s == nil { - return 0 - } - - size += proto.BytesSize(signatureKeyField, s.key) - size += proto.BytesSize(signatureValueField, s.sign) - size += proto.EnumSize(signatureSchemeField, int32(s.scheme)) - - return size -} - -func (s *Signature) Unmarshal(data []byte) error { - return message.Unmarshal(s, data, new(refs.Signature)) -} - -func (v *Version) StableMarshal(buf []byte) []byte { - if v == nil { - return []byte{} - } - - if buf == nil { - buf = make([]byte, v.StableSize()) - } - - var offset int - - offset += proto.UInt32Marshal(versionMajorField, buf[offset:], v.major) - proto.UInt32Marshal(versionMinorField, buf[offset:], v.minor) - - return buf -} - -func (v *Version) StableSize() (size int) { - if v == nil { - return 0 - } - - size += proto.UInt32Size(versionMajorField, v.major) - size += proto.UInt32Size(versionMinorField, v.minor) - - return size -} - -func (v *Version) Unmarshal(data []byte) error { - return message.Unmarshal(v, data, new(refs.Version)) -} diff --git a/refs/message_test.go b/refs/message_test.go index 69f2242..c520f74 100644 --- a/refs/message_test.go +++ b/refs/message_test.go @@ -4,18 +4,18 @@ import ( "testing" refstest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs/test" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message" messagetest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message/test" + "google.golang.org/protobuf/proto" ) func TestMessageConvert(t *testing.T) { messagetest.TestRPCMessage(t, - func(empty bool) message.Message { return refstest.GenerateOwnerID(empty) }, - func(empty bool) message.Message { return refstest.GenerateObjectID(empty) }, - func(empty bool) message.Message { return refstest.GenerateContainerID(empty) }, - func(empty bool) message.Message { return refstest.GenerateAddress(empty) }, - func(empty bool) message.Message { return refstest.GenerateChecksum(empty) }, - func(empty bool) message.Message { return refstest.GenerateSignature(empty) }, - func(empty bool) message.Message { return refstest.GenerateVersion(empty) }, + func(empty bool) proto.Message { return refstest.GenerateOwnerID(empty) }, + func(empty bool) proto.Message { return refstest.GenerateObjectID(empty) }, + func(empty bool) proto.Message { return refstest.GenerateContainerID(empty) }, + func(empty bool) proto.Message { return refstest.GenerateAddress(empty) }, + func(empty bool) proto.Message { return refstest.GenerateChecksum(empty) }, + func(empty bool) proto.Message { return refstest.GenerateSignature(empty) }, + func(empty bool) proto.Message { return refstest.GenerateVersion(empty) }, ) } diff --git a/refs/string.go b/refs/string.go deleted file mode 100644 index 5389aa3..0000000 --- a/refs/string.go +++ /dev/null @@ -1,47 +0,0 @@ -package refs - -import ( - refs "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs/grpc" -) - -// String returns string representation of ChecksumType. -func (t ChecksumType) String() string { - return ChecksumTypeToGRPC(t).String() -} - -// FromString parses ChecksumType from a string representation. -// It is a reverse action to String(). -// -// Returns true if s was parsed successfully. -func (t *ChecksumType) FromString(s string) bool { - var g refs.ChecksumType - - ok := g.FromString(s) - - if ok { - *t = ChecksumTypeFromGRPC(g) - } - - return ok -} - -// String returns string representation of SignatureScheme. -func (t SignatureScheme) String() string { - return refs.SignatureScheme(t).String() -} - -// FromString parses SignatureScheme from a string representation. -// It is a reverse action to String(). -// -// Returns true if s was parsed successfully. -func (t *SignatureScheme) FromString(s string) bool { - var g refs.SignatureScheme - - ok := g.FromString(s) - - if ok { - *t = SignatureScheme(g) - } - - return ok -} diff --git a/refs/test/generate.go b/refs/test/generate.go index 6217a96..a1ee5d7 100644 --- a/refs/test/generate.go +++ b/refs/test/generate.go @@ -3,7 +3,7 @@ package refstest import ( "math/rand" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs" + refs "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs/grpc" ) func GenerateVersion(empty bool) *refs.Version { @@ -31,8 +31,8 @@ func GenerateAddress(empty bool) *refs.Address { m := new(refs.Address) if !empty { - m.SetObjectID(GenerateObjectID(false)) - m.SetContainerID(GenerateContainerID(false)) + m.SetObjectId(GenerateObjectID(false)) + m.SetContainerId(GenerateContainerID(false)) } return m @@ -48,13 +48,13 @@ func GenerateObjectID(empty bool) *refs.ObjectID { return m } -func GenerateObjectIDs(empty bool) []refs.ObjectID { - var ids []refs.ObjectID +func GenerateObjectIDs(empty bool) []*refs.ObjectID { + var ids []*refs.ObjectID if !empty { ids = append(ids, - *GenerateObjectID(false), - *GenerateObjectID(false), + GenerateObjectID(false), + GenerateObjectID(false), ) } @@ -71,13 +71,13 @@ func GenerateContainerID(empty bool) *refs.ContainerID { return m } -func GenerateContainerIDs(empty bool) []refs.ContainerID { - var res []refs.ContainerID +func GenerateContainerIDs(empty bool) []*refs.ContainerID { + var res []*refs.ContainerID if !empty { res = append(res, - *GenerateContainerID(false), - *GenerateContainerID(false), + GenerateContainerID(false), + GenerateContainerID(false), ) } @@ -96,11 +96,22 @@ func GenerateSignature(empty bool) *refs.Signature { return m } +func GenerateSignatureRFC6979(empty bool) *refs.SignatureRFC6979 { + m := new(refs.SignatureRFC6979) + + if !empty { + m.SetKey([]byte{1}) + m.SetSign([]byte{2}) + } + + return m +} + func GenerateChecksum(empty bool) *refs.Checksum { m := new(refs.Checksum) if !empty { - m.SetType(1) + m.SetChecksumType(1) m.SetSum([]byte{1, 2, 3}) } diff --git a/refs/types.go b/refs/types.go deleted file mode 100644 index d8f0d9b..0000000 --- a/refs/types.go +++ /dev/null @@ -1,194 +0,0 @@ -package refs - -type OwnerID struct { - val []byte -} - -type ContainerID struct { - val []byte -} - -type ObjectID struct { - val []byte -} - -type Address struct { - cid *ContainerID - - oid *ObjectID -} - -type Checksum struct { - typ ChecksumType - - sum []byte -} - -type ChecksumType uint32 - -type SignatureScheme uint32 - -//nolint:revive -const ( - ECDSA_SHA512 SignatureScheme = iota - ECDSA_RFC6979_SHA256 - ECDSA_RFC6979_SHA256_WALLET_CONNECT -) - -type Signature struct { - key, sign []byte - scheme SignatureScheme -} - -type Version struct { - major, minor uint32 -} - -const ( - UnknownChecksum ChecksumType = iota - TillichZemor - SHA256 -) - -func (o *OwnerID) GetValue() []byte { - if o != nil { - return o.val - } - - return nil -} - -func (o *OwnerID) SetValue(v []byte) { - o.val = v -} - -func (c *ContainerID) GetValue() []byte { - if c != nil { - return c.val - } - - return nil -} - -func (c *ContainerID) SetValue(v []byte) { - c.val = v -} - -func (o *ObjectID) GetValue() []byte { - if o != nil { - return o.val - } - - return nil -} - -func (o *ObjectID) SetValue(v []byte) { - o.val = v -} - -func (a *Address) GetContainerID() *ContainerID { - if a != nil { - return a.cid - } - - return nil -} - -func (a *Address) SetContainerID(v *ContainerID) { - a.cid = v -} - -func (a *Address) GetObjectID() *ObjectID { - if a != nil { - return a.oid - } - - return nil -} - -func (a *Address) SetObjectID(v *ObjectID) { - a.oid = v -} - -func (c *Checksum) GetType() ChecksumType { - if c != nil { - return c.typ - } - - return UnknownChecksum -} - -func (c *Checksum) SetType(v ChecksumType) { - c.typ = v -} - -func (c *Checksum) GetSum() []byte { - if c != nil { - return c.sum - } - - return nil -} - -func (c *Checksum) SetSum(v []byte) { - c.sum = v -} - -func (s *Signature) GetKey() []byte { - if s != nil { - return s.key - } - - return nil -} - -func (s *Signature) SetKey(v []byte) { - s.key = v -} - -func (s *Signature) GetSign() []byte { - if s != nil { - return s.sign - } - - return nil -} - -func (s *Signature) SetSign(v []byte) { - s.sign = v -} - -func (s *Signature) GetScheme() SignatureScheme { - if s != nil { - return s.scheme - } - return 0 -} - -func (s *Signature) SetScheme(scheme SignatureScheme) { - s.scheme = scheme -} - -func (v *Version) GetMajor() uint32 { - if v != nil { - return v.major - } - - return 0 -} - -func (v *Version) SetMajor(val uint32) { - v.major = val -} - -func (v *Version) GetMinor() uint32 { - if v != nil { - return v.minor - } - - return 0 -} - -func (v *Version) SetMinor(val uint32) { - v.minor = val -} diff --git a/rpc/accounting.go b/rpc/accounting.go index 4f324c9..46dedb8 100644 --- a/rpc/accounting.go +++ b/rpc/accounting.go @@ -1,7 +1,7 @@ package rpc import ( - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/accounting" + accounting "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/accounting/grpc" "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/client" "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/common" ) diff --git a/rpc/client/flows.go b/rpc/client/flows.go index a3da1e2..57917d9 100644 --- a/rpc/client/flows.go +++ b/rpc/client/flows.go @@ -6,12 +6,12 @@ import ( "sync" "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/common" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message" + "google.golang.org/protobuf/proto" ) // SendUnary initializes communication session by RPC info, performs unary RPC // and closes the session. -func SendUnary(cli *Client, info common.CallMethodInfo, req, resp message.Message, opts ...CallOption) error { +func SendUnary(cli *Client, info common.CallMethodInfo, req, resp proto.Message, opts ...CallOption) error { rw, err := cli.Init(info, opts...) if err != nil { return err @@ -40,7 +40,7 @@ type MessageWriterCloser interface { type clientStreamWriterCloser struct { MessageReadWriter - resp message.Message + resp proto.Message } func (c *clientStreamWriterCloser) Close() error { @@ -56,7 +56,7 @@ func (c *clientStreamWriterCloser) Close() error { // and returns its interface. // // All stream writes must be performed before the closing. Close must be called once. -func OpenClientStream(cli *Client, info common.CallMethodInfo, resp message.Message, opts ...CallOption) (MessageWriterCloser, error) { +func OpenClientStream(cli *Client, info common.CallMethodInfo, resp proto.Message, opts ...CallOption) (MessageWriterCloser, error) { rw, err := cli.Init(info, opts...) if err != nil { return nil, err @@ -80,10 +80,10 @@ type serverStreamReaderCloser struct { once sync.Once - req message.Message + req proto.Message } -func (s *serverStreamReaderCloser) ReadMessage(msg message.Message) error { +func (s *serverStreamReaderCloser) ReadMessage(msg proto.Message) error { var err error s.once.Do(func() { @@ -111,7 +111,7 @@ func (s *serverStreamReaderCloser) ReadMessage(msg message.Message) error { // and returns its interface. // // All stream reads must be performed before the closing. Close must be called once. -func OpenServerStream(cli *Client, info common.CallMethodInfo, req message.Message, opts ...CallOption) (MessageReader, error) { +func OpenServerStream(cli *Client, info common.CallMethodInfo, req proto.Message, opts ...CallOption) (MessageReader, error) { rw, err := cli.Init(info, opts...) if err != nil { return nil, err diff --git a/rpc/client/init.go b/rpc/client/init.go index 60ccda9..aa6d1c8 100644 --- a/rpc/client/init.go +++ b/rpc/client/init.go @@ -5,8 +5,8 @@ import ( "io" "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/common" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message" "google.golang.org/grpc" + "google.golang.org/protobuf/proto" ) // MessageReader is an interface of the Message reader. @@ -15,7 +15,7 @@ type MessageReader interface { // // Returns io.EOF if there are no more messages to read. // ReadMessage should not be called after io.EOF occasion. - ReadMessage(message.Message) error + ReadMessage(proto.Message) error } // MessageWriter is an interface of the Message writer. @@ -23,7 +23,7 @@ type MessageWriter interface { // WriteMessage writers the next Message. // // WriteMessage should not be called after any error. - WriteMessage(message.Message) error + WriteMessage(proto.Message) error } // MessageReadWriter is a component interface diff --git a/rpc/client/stream_wrapper.go b/rpc/client/stream_wrapper.go index 22033dd..3cc8d68 100644 --- a/rpc/client/stream_wrapper.go +++ b/rpc/client/stream_wrapper.go @@ -4,8 +4,8 @@ import ( "context" "time" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message" "google.golang.org/grpc" + "google.golang.org/protobuf/proto" ) type streamWrapper struct { @@ -14,23 +14,15 @@ type streamWrapper struct { cancel context.CancelFunc } -func (w streamWrapper) ReadMessage(m message.Message) error { - // Can be optimized: we can create blank message here. - gm := m.ToGRPCMessage() - - err := w.withTimeout(func() error { - return w.ClientStream.RecvMsg(gm) +func (w streamWrapper) ReadMessage(m proto.Message) error { + return w.withTimeout(func() error { + return w.ClientStream.RecvMsg(m) }) - if err != nil { - return err - } - - return m.FromGRPCMessage(gm) } -func (w streamWrapper) WriteMessage(m message.Message) error { +func (w streamWrapper) WriteMessage(m proto.Message) error { return w.withTimeout(func() error { - return w.ClientStream.SendMsg(m.ToGRPCMessage()) + return w.ClientStream.SendMsg(m) }) } diff --git a/rpc/container.go b/rpc/container.go index 1292c22..d8e6b3f 100644 --- a/rpc/container.go +++ b/rpc/container.go @@ -1,7 +1,7 @@ package rpc import ( - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/container" + container "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/container/grpc" "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/client" "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/common" ) diff --git a/rpc/message/test/message.go b/rpc/message/test/message.go index df769d2..ed6e834 100644 --- a/rpc/message/test/message.go +++ b/rpc/message/test/message.go @@ -1,65 +1,44 @@ package messagetest import ( - "encoding/json" - "errors" "fmt" "testing" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message" + utilproto "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/util/proto" "github.com/stretchr/testify/require" + "google.golang.org/protobuf/encoding/protojson" + "google.golang.org/protobuf/proto" ) -type jsonMessage interface { - json.Marshaler - json.Unmarshaler -} - -type binaryMessage interface { - StableMarshal([]byte) []byte - Unmarshal([]byte) error -} - -func TestRPCMessage(t *testing.T, msgGens ...func(empty bool) message.Message) { +func TestRPCMessage(t *testing.T, msgGens ...func(empty bool) proto.Message) { for _, msgGen := range msgGens { - msg := msgGen(false) - - t.Run(fmt.Sprintf("convert_%T", msg), func(t *testing.T) { - msg := msgGen(false) - - err := msg.FromGRPCMessage(100) - - require.True(t, errors.As(err, new(message.ErrUnexpectedMessageType))) - - msg2 := msgGen(true) - - err = msg2.FromGRPCMessage(msg.ToGRPCMessage()) - require.NoError(t, err) - - require.Equal(t, msg, msg2) - }) + msg1 := msgGen(false) t.Run("encoding", func(t *testing.T) { - if jm, ok := msg.(jsonMessage); ok { - t.Run(fmt.Sprintf("JSON_%T", msg), func(t *testing.T) { - data, err := jm.MarshalJSON() - require.NoError(t, err) + t.Run(fmt.Sprintf("JSON_%T", msg1), func(t *testing.T) { + data, err := protojson.MarshalOptions{ + EmitUnpopulated: true, + }.Marshal( + msg1, + ) + require.NoError(t, err) - jm2 := msgGen(true).(jsonMessage) - require.NoError(t, jm2.UnmarshalJSON(data)) + msg2 := msgGen(true) + require.NoError(t, protojson.Unmarshal(data, msg2)) - require.Equal(t, jm, jm2) - }) - } + require.True(t, proto.Equal(msg1, msg2)) + }) - if bm, ok := msg.(binaryMessage); ok { - t.Run(fmt.Sprintf("Binary_%T", msg), func(t *testing.T) { + if bm, ok := msg1.(utilproto.StableMarshaller); ok { + t.Run(fmt.Sprintf("Stable_%T", msg1), func(t *testing.T) { data := bm.StableMarshal(nil) - bm2 := msgGen(true).(binaryMessage) - require.NoError(t, bm2.Unmarshal(data)) + require.Len(t, data, bm.StableSize()) - require.Equal(t, bm, bm2) + msg2 := msgGen(true) + require.NoError(t, proto.Unmarshal(data, msg2)) + + require.True(t, proto.Equal(msg1, msg2)) }) } }) diff --git a/rpc/netmap.go b/rpc/netmap.go index 38bdd6d..e457d5c 100644 --- a/rpc/netmap.go +++ b/rpc/netmap.go @@ -1,7 +1,7 @@ package rpc import ( - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/netmap" + netmap "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/netmap/grpc" "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/client" "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/common" ) @@ -49,10 +49,10 @@ func NetworkInfo( // NetMapSnapshot executes NetmapService.NetmapSnapshot RPC. func NetMapSnapshot( cli *client.Client, - req *netmap.SnapshotRequest, + req *netmap.NetmapSnapshotRequest, opts ...client.CallOption, -) (*netmap.SnapshotResponse, error) { - resp := new(netmap.SnapshotResponse) +) (*netmap.NetmapSnapshotResponse, error) { + resp := new(netmap.NetmapSnapshotResponse) err := client.SendUnary(cli, common.CallMethodInfoUnary(serviceNetmap, rpcNetmapSnapshot), req, resp, opts...) if err != nil { diff --git a/rpc/object.go b/rpc/object.go index 1eca922..f7ad5b7 100644 --- a/rpc/object.go +++ b/rpc/object.go @@ -1,10 +1,10 @@ package rpc import ( - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/object" + object "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/object/grpc" "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/client" "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/common" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message" + "google.golang.org/protobuf/proto" ) const serviceObject = serviceNamePrefix + "object.ObjectService" @@ -25,7 +25,7 @@ const ( type PutRequestWriter struct { wc client.MessageWriterCloser - resp message.Message + resp proto.Message } // Write writes req to the stream. diff --git a/rpc/session.go b/rpc/session.go index f786734..4d63d0e 100644 --- a/rpc/session.go +++ b/rpc/session.go @@ -3,7 +3,7 @@ package rpc import ( "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/client" "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/common" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/session" + session "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/session/grpc" ) const serviceSession = serviceNamePrefix + "session.SessionService" diff --git a/session/convert.go b/session/convert.go deleted file mode 100644 index 870e208..0000000 --- a/session/convert.go +++ /dev/null @@ -1,893 +0,0 @@ -package session - -import ( - "fmt" - - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/acl" - aclGRPC "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/acl/grpc" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs" - refsGRPC "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs/grpc" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/grpc" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message" - session "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/session/grpc" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/status" - statusGRPC "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/status/grpc" -) - -func (c *CreateRequestBody) ToGRPCMessage() grpc.Message { - var m *session.CreateRequest_Body - - if c != nil { - m = new(session.CreateRequest_Body) - - m.SetOwnerId(c.ownerID.ToGRPCMessage().(*refsGRPC.OwnerID)) - m.SetExpiration(c.expiration) - } - - return m -} - -func (c *CreateRequestBody) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*session.CreateRequest_Body) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var err error - - ownerID := v.GetOwnerId() - if ownerID == nil { - c.ownerID = nil - } else { - if c.ownerID == nil { - c.ownerID = new(refs.OwnerID) - } - - err = c.ownerID.FromGRPCMessage(ownerID) - if err != nil { - return err - } - } - - c.expiration = v.GetExpiration() - - return nil -} - -func (c *CreateRequest) ToGRPCMessage() grpc.Message { - var m *session.CreateRequest - - if c != nil { - m = new(session.CreateRequest) - - m.SetBody(c.body.ToGRPCMessage().(*session.CreateRequest_Body)) - c.RequestHeaders.ToMessage(m) - } - - return m -} - -func (c *CreateRequest) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*session.CreateRequest) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var err error - - body := v.GetBody() - if body == nil { - c.body = nil - } else { - if c.body == nil { - c.body = new(CreateRequestBody) - } - - err = c.body.FromGRPCMessage(body) - if err != nil { - return err - } - } - - return c.RequestHeaders.FromMessage(v) -} - -func (c *CreateResponseBody) ToGRPCMessage() grpc.Message { - var m *session.CreateResponse_Body - - if c != nil { - m = new(session.CreateResponse_Body) - - m.SetSessionKey(c.sessionKey) - m.SetId(c.id) - } - - return m -} - -func (c *CreateResponseBody) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*session.CreateResponse_Body) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - c.sessionKey = v.GetSessionKey() - c.id = v.GetId() - - return nil -} - -func (c *CreateResponse) ToGRPCMessage() grpc.Message { - var m *session.CreateResponse - - if c != nil { - m = new(session.CreateResponse) - - m.SetBody(c.body.ToGRPCMessage().(*session.CreateResponse_Body)) - c.ResponseHeaders.ToMessage(m) - } - - return m -} - -func (c *CreateResponse) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*session.CreateResponse) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var err error - - body := v.GetBody() - if body == nil { - c.body = nil - } else { - if c.body == nil { - c.body = new(CreateResponseBody) - } - - err = c.body.FromGRPCMessage(body) - if err != nil { - return err - } - } - - return c.ResponseHeaders.FromMessage(v) -} - -func (l *TokenLifetime) ToGRPCMessage() grpc.Message { - var m *session.SessionToken_Body_TokenLifetime - - if l != nil { - m = new(session.SessionToken_Body_TokenLifetime) - - m.SetExp(l.exp) - m.SetIat(l.iat) - m.SetNbf(l.nbf) - } - - return m -} - -func (l *TokenLifetime) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*session.SessionToken_Body_TokenLifetime) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - l.exp = v.GetExp() - l.iat = v.GetIat() - l.nbf = v.GetNbf() - - return nil -} - -func (x *XHeader) ToGRPCMessage() grpc.Message { - var m *session.XHeader - - if x != nil { - m = new(session.XHeader) - - m.SetKey(x.key) - m.SetValue(x.val) - } - - return m -} - -func (x *XHeader) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*session.XHeader) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - x.key = v.GetKey() - x.val = v.GetValue() - - return nil -} - -func XHeadersToGRPC(xs []XHeader) (res []*session.XHeader) { - if xs != nil { - res = make([]*session.XHeader, 0, len(xs)) - - for i := range xs { - res = append(res, xs[i].ToGRPCMessage().(*session.XHeader)) - } - } - - return -} - -func XHeadersFromGRPC(xs []*session.XHeader) (res []XHeader, err error) { - if xs != nil { - res = make([]XHeader, len(xs)) - - for i := range xs { - if xs[i] != nil { - err = res[i].FromGRPCMessage(xs[i]) - if err != nil { - return - } - } - } - } - - return -} - -func (t *Token) ToGRPCMessage() grpc.Message { - var m *session.SessionToken - - if t != nil { - m = new(session.SessionToken) - - m.SetBody(t.body.ToGRPCMessage().(*session.SessionToken_Body)) - m.SetSignature(t.sig.ToGRPCMessage().(*refsGRPC.Signature)) - } - - return m -} - -func (t *Token) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*session.SessionToken) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var err error - - body := v.GetBody() - if body == nil { - t.body = nil - } else { - if t.body == nil { - t.body = new(TokenBody) - } - - err = t.body.FromGRPCMessage(body) - if err != nil { - return err - } - } - - sig := v.GetSignature() - if sig == nil { - t.sig = nil - } else { - if t.sig == nil { - t.sig = new(refs.Signature) - } - - err = t.sig.FromGRPCMessage(sig) - if err != nil { - return err - } - } - - return nil -} - -func (r *RequestVerificationHeader) ToGRPCMessage() grpc.Message { - var m *session.RequestVerificationHeader - - if r != nil { - m = new(session.RequestVerificationHeader) - - m.SetBodySignature(r.bodySig.ToGRPCMessage().(*refsGRPC.Signature)) - m.SetMetaSignature(r.metaSig.ToGRPCMessage().(*refsGRPC.Signature)) - m.SetOriginSignature(r.originSig.ToGRPCMessage().(*refsGRPC.Signature)) - m.SetOrigin(r.origin.ToGRPCMessage().(*session.RequestVerificationHeader)) - } - - return m -} - -func (r *RequestVerificationHeader) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*session.RequestVerificationHeader) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var err error - - originSig := v.GetOriginSignature() - if originSig == nil { - r.originSig = nil - } else { - if r.originSig == nil { - r.originSig = new(refs.Signature) - } - - err = r.originSig.FromGRPCMessage(originSig) - if err != nil { - return err - } - } - - metaSig := v.GetMetaSignature() - if metaSig == nil { - r.metaSig = nil - } else { - if r.metaSig == nil { - r.metaSig = new(refs.Signature) - } - - err = r.metaSig.FromGRPCMessage(metaSig) - if err != nil { - return err - } - } - - bodySig := v.GetBodySignature() - if bodySig == nil { - r.bodySig = nil - } else { - if r.bodySig == nil { - r.bodySig = new(refs.Signature) - } - - err = r.bodySig.FromGRPCMessage(bodySig) - if err != nil { - return err - } - } - - origin := v.GetOrigin() - if origin == nil { - r.origin = nil - } else { - if r.origin == nil { - r.origin = new(RequestVerificationHeader) - } - - err = r.origin.FromGRPCMessage(origin) - if err != nil { - return err - } - } - - return nil -} - -func (r *RequestMetaHeader) ToGRPCMessage() grpc.Message { - var m *session.RequestMetaHeader - - if r != nil { - m = new(session.RequestMetaHeader) - - m.SetVersion(r.version.ToGRPCMessage().(*refsGRPC.Version)) - m.SetSessionToken(r.sessionToken.ToGRPCMessage().(*session.SessionToken)) - m.SetBearerToken(r.bearerToken.ToGRPCMessage().(*aclGRPC.BearerToken)) - m.SetXHeaders(XHeadersToGRPC(r.xHeaders)) - m.SetEpoch(r.epoch) - m.SetTtl(r.ttl) - m.SetOrigin(r.origin.ToGRPCMessage().(*session.RequestMetaHeader)) - m.SetNetworkMagic(r.netMagic) - } - - return m -} - -func (r *RequestMetaHeader) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*session.RequestMetaHeader) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var err error - - version := v.GetVersion() - if version == nil { - r.version = nil - } else { - if r.version == nil { - r.version = new(refs.Version) - } - - err = r.version.FromGRPCMessage(version) - if err != nil { - return err - } - } - - sessionToken := v.GetSessionToken() - if sessionToken == nil { - r.sessionToken = nil - } else { - if r.sessionToken == nil { - r.sessionToken = new(Token) - } - - err = r.sessionToken.FromGRPCMessage(sessionToken) - if err != nil { - return err - } - } - - bearerToken := v.GetBearerToken() - if bearerToken == nil { - r.bearerToken = nil - } else { - if r.bearerToken == nil { - r.bearerToken = new(acl.BearerToken) - } - - err = r.bearerToken.FromGRPCMessage(bearerToken) - if err != nil { - return err - } - } - - origin := v.GetOrigin() - if origin == nil { - r.origin = nil - } else { - if r.origin == nil { - r.origin = new(RequestMetaHeader) - } - - err = r.origin.FromGRPCMessage(origin) - if err != nil { - return err - } - } - - r.xHeaders, err = XHeadersFromGRPC(v.GetXHeaders()) - if err != nil { - return err - } - - r.epoch = v.GetEpoch() - r.ttl = v.GetTtl() - r.netMagic = v.GetNetworkMagic() - - return nil -} - -func (r *ResponseVerificationHeader) ToGRPCMessage() grpc.Message { - var m *session.ResponseVerificationHeader - - if r != nil { - m = new(session.ResponseVerificationHeader) - - m.SetBodySignature(r.bodySig.ToGRPCMessage().(*refsGRPC.Signature)) - m.SetMetaSignature(r.metaSig.ToGRPCMessage().(*refsGRPC.Signature)) - m.SetOriginSignature(r.originSig.ToGRPCMessage().(*refsGRPC.Signature)) - m.SetOrigin(r.origin.ToGRPCMessage().(*session.ResponseVerificationHeader)) - } - - return m -} - -func (r *ResponseVerificationHeader) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*session.ResponseVerificationHeader) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var err error - - originSig := v.GetOriginSignature() - if originSig == nil { - r.originSig = nil - } else { - if r.originSig == nil { - r.originSig = new(refs.Signature) - } - - err = r.originSig.FromGRPCMessage(originSig) - if err != nil { - return err - } - } - - metaSig := v.GetMetaSignature() - if metaSig == nil { - r.metaSig = nil - } else { - if r.metaSig == nil { - r.metaSig = new(refs.Signature) - } - - err = r.metaSig.FromGRPCMessage(metaSig) - if err != nil { - return err - } - } - - bodySig := v.GetBodySignature() - if bodySig == nil { - r.bodySig = nil - } else { - if r.bodySig == nil { - r.bodySig = new(refs.Signature) - } - - err = r.bodySig.FromGRPCMessage(bodySig) - if err != nil { - return err - } - } - - origin := v.GetOrigin() - if origin == nil { - r.origin = nil - } else { - if r.origin == nil { - r.origin = new(ResponseVerificationHeader) - } - - err = r.origin.FromGRPCMessage(origin) - if err != nil { - return err - } - } - - return nil -} - -func (r *ResponseMetaHeader) ToGRPCMessage() grpc.Message { - var m *session.ResponseMetaHeader - - if r != nil { - m = new(session.ResponseMetaHeader) - - m.SetVersion(r.version.ToGRPCMessage().(*refsGRPC.Version)) - m.SetXHeaders(XHeadersToGRPC(r.xHeaders)) - m.SetEpoch(r.epoch) - m.SetTtl(r.ttl) - m.SetOrigin(r.origin.ToGRPCMessage().(*session.ResponseMetaHeader)) - m.SetStatus(r.status.ToGRPCMessage().(*statusGRPC.Status)) - } - - return m -} - -func (r *ResponseMetaHeader) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*session.ResponseMetaHeader) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var err error - - version := v.GetVersion() - if version == nil { - r.version = nil - } else { - if r.version == nil { - r.version = new(refs.Version) - } - - err = r.version.FromGRPCMessage(version) - if err != nil { - return err - } - } - - origin := v.GetOrigin() - if origin == nil { - r.origin = nil - } else { - if r.origin == nil { - r.origin = new(ResponseMetaHeader) - } - - err = r.origin.FromGRPCMessage(origin) - if err != nil { - return err - } - } - - st := v.GetStatus() - if st == nil { - r.status = nil - } else { - if r.status == nil { - r.status = new(status.Status) - } - - err = r.status.FromGRPCMessage(st) - if err != nil { - return err - } - } - - r.xHeaders, err = XHeadersFromGRPC(v.GetXHeaders()) - if err != nil { - return err - } - - r.epoch = v.GetEpoch() - r.ttl = v.GetTtl() - - return nil -} - -func ObjectSessionVerbToGRPCField(v ObjectSessionVerb) session.ObjectSessionContext_Verb { - switch v { - case ObjectVerbPut: - return session.ObjectSessionContext_PUT - case ObjectVerbGet: - return session.ObjectSessionContext_GET - case ObjectVerbHead: - return session.ObjectSessionContext_HEAD - case ObjectVerbSearch: - return session.ObjectSessionContext_SEARCH - case ObjectVerbDelete: - return session.ObjectSessionContext_DELETE - case ObjectVerbRange: - return session.ObjectSessionContext_RANGE - case ObjectVerbRangeHash: - return session.ObjectSessionContext_RANGEHASH - default: - return session.ObjectSessionContext_VERB_UNSPECIFIED - } -} - -func ObjectSessionVerbFromGRPCField(v session.ObjectSessionContext_Verb) ObjectSessionVerb { - switch v { - case session.ObjectSessionContext_PUT: - return ObjectVerbPut - case session.ObjectSessionContext_GET: - return ObjectVerbGet - case session.ObjectSessionContext_HEAD: - return ObjectVerbHead - case session.ObjectSessionContext_SEARCH: - return ObjectVerbSearch - case session.ObjectSessionContext_DELETE: - return ObjectVerbDelete - case session.ObjectSessionContext_RANGE: - return ObjectVerbRange - case session.ObjectSessionContext_RANGEHASH: - return ObjectVerbRangeHash - default: - return ObjectVerbUnknown - } -} - -func (c *ObjectSessionContext) ToGRPCMessage() grpc.Message { - var m *session.ObjectSessionContext - - if c != nil { - m = new(session.ObjectSessionContext) - - m.SetVerb(ObjectSessionVerbToGRPCField(c.verb)) - m.SetTarget(c.cnr.ToGRPCMessage().(*refsGRPC.ContainerID), refs.ObjectIDListToGRPCMessage(c.objs)) - } - - return m -} - -func (c *ObjectSessionContext) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*session.ObjectSessionContext) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var err error - - cnr := v.GetTarget().GetContainer() - if cnr == nil { - c.cnr = nil - } else { - if c.cnr == nil { - c.cnr = new(refs.ContainerID) - } - - err = c.cnr.FromGRPCMessage(cnr) - if err != nil { - return err - } - } - - c.objs, err = refs.ObjectIDListFromGRPCMessage(v.GetTarget().GetObjects()) - if err != nil { - return err - } - - c.verb = ObjectSessionVerbFromGRPCField(v.GetVerb()) - - return nil -} - -func (t *TokenBody) ToGRPCMessage() grpc.Message { - var m *session.SessionToken_Body - - if t != nil { - m = new(session.SessionToken_Body) - - switch typ := t.ctx.(type) { - default: - panic(fmt.Sprintf("unknown session context %T", typ)) - case nil: - m.Context = nil - case *ObjectSessionContext: - m.SetObjectSessionContext(typ.ToGRPCMessage().(*session.ObjectSessionContext)) - case *ContainerSessionContext: - m.SetContainerSessionContext(typ.ToGRPCMessage().(*session.ContainerSessionContext)) - } - - m.SetOwnerId(t.ownerID.ToGRPCMessage().(*refsGRPC.OwnerID)) - m.SetId(t.id) - m.SetSessionKey(t.sessionKey) - m.SetLifetime(t.lifetime.ToGRPCMessage().(*session.SessionToken_Body_TokenLifetime)) - } - - return m -} - -func (t *TokenBody) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*session.SessionToken_Body) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var err error - - t.ctx = nil - - switch val := v.GetContext().(type) { - default: - err = fmt.Errorf("unknown session context %T", val) - case nil: - case *session.SessionToken_Body_Object: - ctx, ok := t.ctx.(*ObjectSessionContext) - if !ok { - ctx = new(ObjectSessionContext) - t.ctx = ctx - } - - err = ctx.FromGRPCMessage(val.Object) - case *session.SessionToken_Body_Container: - ctx, ok := t.ctx.(*ContainerSessionContext) - if !ok { - ctx = new(ContainerSessionContext) - t.ctx = ctx - } - - err = ctx.FromGRPCMessage(val.Container) - } - - if err != nil { - return err - } - - ownerID := v.GetOwnerId() - if ownerID == nil { - t.ownerID = nil - } else { - if t.ownerID == nil { - t.ownerID = new(refs.OwnerID) - } - - err = t.ownerID.FromGRPCMessage(ownerID) - if err != nil { - return err - } - } - - lifetime := v.GetLifetime() - if lifetime == nil { - t.lifetime = nil - } else { - if t.lifetime == nil { - t.lifetime = new(TokenLifetime) - } - - err = t.lifetime.FromGRPCMessage(lifetime) - if err != nil { - return err - } - } - - t.id = v.GetId() - t.sessionKey = v.GetSessionKey() - - return nil -} - -// ContainerSessionVerbToGRPCField converts ContainerSessionVerb -// to gRPC-generated session.ContainerSessionContext_Verb. -// -// If v is outside of the ContainerSessionVerb enum, -// session.ContainerSessionContext_VERB_UNSPECIFIED is returned. -func ContainerSessionVerbToGRPCField(v ContainerSessionVerb) session.ContainerSessionContext_Verb { - switch v { - default: - return session.ContainerSessionContext_VERB_UNSPECIFIED - case ContainerVerbPut: - return session.ContainerSessionContext_PUT - case ContainerVerbDelete: - return session.ContainerSessionContext_DELETE - case ContainerVerbSetEACL: - return session.ContainerSessionContext_SETEACL - } -} - -// ContainerSessionVerbFromGRPCField converts gRPC-generated -// session.ContainerSessionContext_Verb to ContainerSessionVerb. -// -// If v is outside of the session.ContainerSessionContext_Verb enum, -// ContainerVerbUnknown is returned. -func ContainerSessionVerbFromGRPCField(v session.ContainerSessionContext_Verb) ContainerSessionVerb { - switch v { - default: - return ContainerVerbUnknown - case session.ContainerSessionContext_PUT: - return ContainerVerbPut - case session.ContainerSessionContext_DELETE: - return ContainerVerbDelete - case session.ContainerSessionContext_SETEACL: - return ContainerVerbSetEACL - } -} - -// ToGRPCMessage converts ContainerSessionContext to gRPC-generated -// session.ContainerSessionContext message. -func (x *ContainerSessionContext) ToGRPCMessage() grpc.Message { - var m *session.ContainerSessionContext - - if x != nil { - m = new(session.ContainerSessionContext) - - m.SetVerb(ContainerSessionVerbToGRPCField(x.verb)) - m.SetWildcard(x.wildcard) - m.SetContainerId(x.cid.ToGRPCMessage().(*refsGRPC.ContainerID)) - } - - return m -} - -// FromGRPCMessage tries to restore ContainerSessionContext from grpc.Message. -// -// Returns message.ErrUnexpectedMessageType if m is not -// a gRPC-generated session.ContainerSessionContext message. -func (x *ContainerSessionContext) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*session.ContainerSessionContext) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var err error - - cid := v.GetContainerId() - if cid == nil { - x.cid = nil - } else { - if x.cid == nil { - x.cid = new(refs.ContainerID) - } - - err = x.cid.FromGRPCMessage(cid) - if err != nil { - return err - } - } - - x.verb = ContainerSessionVerbFromGRPCField(v.GetVerb()) - x.wildcard = v.GetWildcard() - - return nil -} diff --git a/session/grpc/service.pb.go b/session/grpc/service.pb.go index 5ba114d..e0b29fd 100644 Binary files a/session/grpc/service.pb.go and b/session/grpc/service.pb.go differ diff --git a/session/grpc/service_frostfs.pb.go b/session/grpc/service_frostfs.pb.go new file mode 100644 index 0000000..6f64c3c Binary files /dev/null and b/session/grpc/service_frostfs.pb.go differ diff --git a/session/grpc/service_grpc.pb.go b/session/grpc/service_grpc.pb.go index 32793fe..a39bf63 100644 Binary files a/session/grpc/service_grpc.pb.go and b/session/grpc/service_grpc.pb.go differ diff --git a/session/grpc/types.go b/session/grpc/types.go index bcc92d1..63e483e 100644 --- a/session/grpc/types.go +++ b/session/grpc/types.go @@ -247,3 +247,20 @@ func (x *ContainerSessionContext_Verb) FromString(s string) bool { return ok } + +// SetStatus sets status of the message which can carry ResponseMetaHeader. +// +// Sets status field on the "highest" level of meta headers. +// If meta header is missing in message, it is allocated. +func SetStatus(msg interface { + GetMetaHeader() *ResponseMetaHeader + SetMetaHeader(*ResponseMetaHeader) +}, st *status.Status) { + meta := msg.GetMetaHeader() + if meta == nil { + meta = new(ResponseMetaHeader) + msg.SetMetaHeader(meta) + } + + meta.SetStatus(st) +} diff --git a/session/grpc/types.pb.go b/session/grpc/types.pb.go index 25e0715..fba44f1 100644 Binary files a/session/grpc/types.pb.go and b/session/grpc/types.pb.go differ diff --git a/session/grpc/types_frostfs.pb.go b/session/grpc/types_frostfs.pb.go new file mode 100644 index 0000000..9ff4f5d Binary files /dev/null and b/session/grpc/types_frostfs.pb.go differ diff --git a/session/json.go b/session/json.go deleted file mode 100644 index 77cbe10..0000000 --- a/session/json.go +++ /dev/null @@ -1,129 +0,0 @@ -package session - -import ( - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message" - session "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/session/grpc" - "google.golang.org/protobuf/encoding/protojson" -) - -func (c *ObjectSessionContext) MarshalJSON() ([]byte, error) { - return message.MarshalJSON(c) -} - -func (c *ObjectSessionContext) UnmarshalJSON(data []byte) error { - return message.UnmarshalJSON(c, data, new(session.ObjectSessionContext)) -} - -func (l *TokenLifetime) MarshalJSON() ([]byte, error) { - return message.MarshalJSON(l) -} - -func (l *TokenLifetime) UnmarshalJSON(data []byte) error { - return message.UnmarshalJSON(l, data, new(session.SessionToken_Body_TokenLifetime)) -} - -func (t *TokenBody) MarshalJSON() ([]byte, error) { - return message.MarshalJSON(t) -} - -func (t *TokenBody) UnmarshalJSON(data []byte) error { - msg := new(session.SessionToken_Body) - - if err := protojson.Unmarshal(data, msg); err != nil { - return err - } - - return t.FromGRPCMessage(msg) -} - -func (t *Token) MarshalJSON() ([]byte, error) { - return message.MarshalJSON(t) -} - -func (t *Token) UnmarshalJSON(data []byte) error { - msg := new(session.SessionToken) - - if err := protojson.Unmarshal(data, msg); err != nil { - return err - } - - return t.FromGRPCMessage(msg) -} - -func (x *XHeader) MarshalJSON() ([]byte, error) { - return message.MarshalJSON(x) -} - -func (x *XHeader) UnmarshalJSON(data []byte) error { - msg := new(session.XHeader) - - if err := protojson.Unmarshal(data, msg); err != nil { - return err - } - - return x.FromGRPCMessage(msg) -} - -func (r *RequestMetaHeader) MarshalJSON() ([]byte, error) { - return message.MarshalJSON(r) -} - -func (r *RequestMetaHeader) UnmarshalJSON(data []byte) error { - msg := new(session.RequestMetaHeader) - - if err := protojson.Unmarshal(data, msg); err != nil { - return err - } - - return r.FromGRPCMessage(msg) -} - -func (r *RequestVerificationHeader) MarshalJSON() ([]byte, error) { - return message.MarshalJSON(r) -} - -func (r *RequestVerificationHeader) UnmarshalJSON(data []byte) error { - msg := new(session.RequestVerificationHeader) - - if err := protojson.Unmarshal(data, msg); err != nil { - return err - } - - return r.FromGRPCMessage(msg) -} - -func (r *ResponseMetaHeader) MarshalJSON() ([]byte, error) { - return message.MarshalJSON(r) -} - -func (r *ResponseMetaHeader) UnmarshalJSON(data []byte) error { - msg := new(session.ResponseMetaHeader) - - if err := protojson.Unmarshal(data, msg); err != nil { - return err - } - - return r.FromGRPCMessage(msg) -} - -func (r *ResponseVerificationHeader) MarshalJSON() ([]byte, error) { - return message.MarshalJSON(r) -} - -func (r *ResponseVerificationHeader) UnmarshalJSON(data []byte) error { - msg := new(session.ResponseVerificationHeader) - - if err := protojson.Unmarshal(data, msg); err != nil { - return err - } - - return r.FromGRPCMessage(msg) -} - -func (x *ContainerSessionContext) MarshalJSON() ([]byte, error) { - return message.MarshalJSON(x) -} - -func (x *ContainerSessionContext) UnmarshalJSON(data []byte) error { - return message.UnmarshalJSON(x, data, new(session.ContainerSessionContext)) -} diff --git a/session/marshal.go b/session/marshal.go deleted file mode 100644 index 3c56cd4..0000000 --- a/session/marshal.go +++ /dev/null @@ -1,582 +0,0 @@ -package session - -import ( - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message" - session "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/session/grpc" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/util/proto" - goproto "google.golang.org/protobuf/proto" -) - -const ( - createReqBodyOwnerField = 1 - createReqBodyExpirationField = 2 - - createRespBodyIDField = 1 - createRespBodyKeyField = 2 - - xheaderKeyField = 1 - xheaderValueField = 2 - - lifetimeExpirationField = 1 - lifetimeNotValidBeforeField = 2 - lifetimeIssuedAtField = 3 - - objectCtxVerbField = 1 - objectCtxTargetField = 2 - - sessionTokenBodyIDField = 1 - sessionTokenBodyOwnerField = 2 - sessionTokenBodyLifetimeField = 3 - sessionTokenBodyKeyField = 4 - sessionTokenBodyObjectCtxField = 5 - sessionTokenBodyCnrCtxField = 6 - - sessionTokenBodyField = 1 - sessionTokenSignatureField = 2 - - reqMetaHeaderVersionField = 1 - reqMetaHeaderEpochField = 2 - reqMetaHeaderTTLField = 3 - reqMetaHeaderXHeadersField = 4 - reqMetaHeaderSessionTokenField = 5 - reqMetaHeaderBearerTokenField = 6 - reqMetaHeaderOriginField = 7 - reqMetaHeaderNetMagicField = 8 - - reqVerifHeaderBodySignatureField = 1 - reqVerifHeaderMetaSignatureField = 2 - reqVerifHeaderOriginSignatureField = 3 - reqVerifHeaderOriginField = 4 - - respMetaHeaderVersionField = 1 - respMetaHeaderEpochField = 2 - respMetaHeaderTTLField = 3 - respMetaHeaderXHeadersField = 4 - respMetaHeaderOriginField = 5 - respMetaHeaderStatusField = 6 - - respVerifHeaderBodySignatureField = 1 - respVerifHeaderMetaSignatureField = 2 - respVerifHeaderOriginSignatureField = 3 - respVerifHeaderOriginField = 4 -) - -func (c *CreateRequestBody) StableMarshal(buf []byte) []byte { - if c == nil { - return []byte{} - } - - if buf == nil { - buf = make([]byte, c.StableSize()) - } - - var offset int - - offset += proto.NestedStructureMarshal(createReqBodyOwnerField, buf[offset:], c.ownerID) - proto.UInt64Marshal(createReqBodyExpirationField, buf[offset:], c.expiration) - - return buf -} - -func (c *CreateRequestBody) StableSize() (size int) { - if c == nil { - return 0 - } - - size += proto.NestedStructureSize(createReqBodyOwnerField, c.ownerID) - size += proto.UInt64Size(createReqBodyExpirationField, c.expiration) - - return size -} - -func (c *CreateRequestBody) Unmarshal(data []byte) error { - return message.Unmarshal(c, data, new(session.CreateRequest_Body)) -} - -func (c *CreateResponseBody) StableMarshal(buf []byte) []byte { - if c == nil { - return []byte{} - } - - if buf == nil { - buf = make([]byte, c.StableSize()) - } - - var offset int - - offset += proto.BytesMarshal(createRespBodyIDField, buf[offset:], c.id) - proto.BytesMarshal(createRespBodyKeyField, buf[offset:], c.sessionKey) - - return buf -} - -func (c *CreateResponseBody) StableSize() (size int) { - if c == nil { - return 0 - } - - size += proto.BytesSize(createRespBodyIDField, c.id) - size += proto.BytesSize(createRespBodyKeyField, c.sessionKey) - - return size -} - -func (c *CreateResponseBody) Unmarshal(data []byte) error { - return message.Unmarshal(c, data, new(session.CreateResponse_Body)) -} - -func (x *XHeader) StableMarshal(buf []byte) []byte { - if x == nil { - return []byte{} - } - - if buf == nil { - buf = make([]byte, x.StableSize()) - } - - var offset int - - offset += proto.StringMarshal(xheaderKeyField, buf[offset:], x.key) - proto.StringMarshal(xheaderValueField, buf[offset:], x.val) - - return buf -} - -func (x *XHeader) StableSize() (size int) { - if x == nil { - return 0 - } - - size += proto.StringSize(xheaderKeyField, x.key) - size += proto.StringSize(xheaderValueField, x.val) - - return size -} - -func (x *XHeader) Unmarshal(data []byte) error { - m := new(session.XHeader) - if err := goproto.Unmarshal(data, m); err != nil { - return err - } - - return x.FromGRPCMessage(m) -} - -func (l *TokenLifetime) StableMarshal(buf []byte) []byte { - if l == nil { - return []byte{} - } - - if buf == nil { - buf = make([]byte, l.StableSize()) - } - - var offset int - - offset += proto.UInt64Marshal(lifetimeExpirationField, buf[offset:], l.exp) - offset += proto.UInt64Marshal(lifetimeNotValidBeforeField, buf[offset:], l.nbf) - proto.UInt64Marshal(lifetimeIssuedAtField, buf[offset:], l.iat) - - return buf -} - -func (l *TokenLifetime) StableSize() (size int) { - if l == nil { - return 0 - } - - size += proto.UInt64Size(lifetimeExpirationField, l.exp) - size += proto.UInt64Size(lifetimeNotValidBeforeField, l.nbf) - size += proto.UInt64Size(lifetimeIssuedAtField, l.iat) - - return size -} - -func (l *TokenLifetime) Unmarshal(data []byte) error { - m := new(session.SessionToken_Body_TokenLifetime) - if err := goproto.Unmarshal(data, m); err != nil { - return err - } - - return l.FromGRPCMessage(m) -} - -func (c *ObjectSessionContext) StableMarshal(buf []byte) []byte { - if c == nil { - return []byte{} - } - - if buf == nil { - buf = make([]byte, c.StableSize()) - } - - offset := proto.EnumMarshal(objectCtxVerbField, buf, int32(c.verb)) - proto.NestedStructureMarshal(objectCtxTargetField, buf[offset:], &objectSessionContextTarget{ - cnr: c.cnr, - objs: c.objs, - }) - - return buf -} - -func (c *ObjectSessionContext) StableSize() (size int) { - if c == nil { - return 0 - } - - size += proto.EnumSize(objectCtxVerbField, int32(c.verb)) - size += proto.NestedStructureSize(objectCtxTargetField, &objectSessionContextTarget{ - cnr: c.cnr, - objs: c.objs, - }) - - return size -} - -func (c *ObjectSessionContext) Unmarshal(data []byte) error { - m := new(session.ObjectSessionContext) - if err := goproto.Unmarshal(data, m); err != nil { - return err - } - - return c.FromGRPCMessage(m) -} - -const ( - _ = iota - cnrCtxVerbFNum - cnrCtxWildcardFNum - cnrCtxCidFNum -) - -func (x *ContainerSessionContext) StableMarshal(buf []byte) []byte { - if x == nil { - return []byte{} - } - - if buf == nil { - buf = make([]byte, x.StableSize()) - } - - var offset int - - offset += proto.EnumMarshal(cnrCtxVerbFNum, buf[offset:], int32(ContainerSessionVerbToGRPCField(x.verb))) - offset += proto.BoolMarshal(cnrCtxWildcardFNum, buf[offset:], x.wildcard) - proto.NestedStructureMarshal(cnrCtxCidFNum, buf[offset:], x.cid) - - return buf -} - -func (x *ContainerSessionContext) StableSize() (size int) { - if x == nil { - return 0 - } - - size += proto.EnumSize(cnrCtxVerbFNum, int32(ContainerSessionVerbToGRPCField(x.verb))) - size += proto.BoolSize(cnrCtxWildcardFNum, x.wildcard) - size += proto.NestedStructureSize(cnrCtxCidFNum, x.cid) - - return size -} - -func (x *ContainerSessionContext) Unmarshal(data []byte) error { - return message.Unmarshal(x, data, new(session.ContainerSessionContext)) -} - -func (t *TokenBody) StableMarshal(buf []byte) []byte { - if t == nil { - return []byte{} - } - - if buf == nil { - buf = make([]byte, t.StableSize()) - } - - var offset int - - offset += proto.BytesMarshal(sessionTokenBodyIDField, buf[offset:], t.id) - offset += proto.NestedStructureMarshal(sessionTokenBodyOwnerField, buf[offset:], t.ownerID) - offset += proto.NestedStructureMarshal(sessionTokenBodyLifetimeField, buf[offset:], t.lifetime) - offset += proto.BytesMarshal(sessionTokenBodyKeyField, buf[offset:], t.sessionKey) - - if t.ctx != nil { - switch v := t.ctx.(type) { - case *ObjectSessionContext: - proto.NestedStructureMarshal(sessionTokenBodyObjectCtxField, buf[offset:], v) - case *ContainerSessionContext: - proto.NestedStructureMarshal(sessionTokenBodyCnrCtxField, buf[offset:], v) - default: - panic("cannot marshal unknown session token context") - } - } - - return buf -} - -func (t *TokenBody) StableSize() (size int) { - if t == nil { - return 0 - } - - size += proto.BytesSize(sessionTokenBodyIDField, t.id) - size += proto.NestedStructureSize(sessionTokenBodyOwnerField, t.ownerID) - size += proto.NestedStructureSize(sessionTokenBodyLifetimeField, t.lifetime) - size += proto.BytesSize(sessionTokenBodyKeyField, t.sessionKey) - - if t.ctx != nil { - switch v := t.ctx.(type) { - case *ObjectSessionContext: - size += proto.NestedStructureSize(sessionTokenBodyObjectCtxField, v) - case *ContainerSessionContext: - size += proto.NestedStructureSize(sessionTokenBodyCnrCtxField, v) - default: - panic("cannot marshal unknown session token context") - } - } - - return size -} - -func (t *TokenBody) Unmarshal(data []byte) error { - m := new(session.SessionToken_Body) - if err := goproto.Unmarshal(data, m); err != nil { - return err - } - - return t.FromGRPCMessage(m) -} - -func (t *Token) StableMarshal(buf []byte) []byte { - if t == nil { - return []byte{} - } - - if buf == nil { - buf = make([]byte, t.StableSize()) - } - - var offset int - - offset += proto.NestedStructureMarshal(sessionTokenBodyField, buf[offset:], t.body) - proto.NestedStructureMarshal(sessionTokenSignatureField, buf[offset:], t.sig) - - return buf -} - -func (t *Token) StableSize() (size int) { - if t == nil { - return 0 - } - - size += proto.NestedStructureSize(sessionTokenBodyField, t.body) - size += proto.NestedStructureSize(sessionTokenSignatureField, t.sig) - - return size -} - -func (t *Token) Unmarshal(data []byte) error { - m := new(session.SessionToken) - if err := goproto.Unmarshal(data, m); err != nil { - return err - } - - return t.FromGRPCMessage(m) -} - -func (r *RequestMetaHeader) StableMarshal(buf []byte) []byte { - if r == nil { - return []byte{} - } - - if buf == nil { - buf = make([]byte, r.StableSize()) - } - - var offset int - - offset += proto.NestedStructureMarshal(reqMetaHeaderVersionField, buf[offset:], r.version) - offset += proto.UInt64Marshal(reqMetaHeaderEpochField, buf[offset:], r.epoch) - offset += proto.UInt32Marshal(reqMetaHeaderTTLField, buf[offset:], r.ttl) - - for i := range r.xHeaders { - offset += proto.NestedStructureMarshal(reqMetaHeaderXHeadersField, buf[offset:], &r.xHeaders[i]) - } - - offset += proto.NestedStructureMarshal(reqMetaHeaderSessionTokenField, buf[offset:], r.sessionToken) - offset += proto.NestedStructureMarshal(reqMetaHeaderBearerTokenField, buf[offset:], r.bearerToken) - offset += proto.NestedStructureMarshal(reqMetaHeaderOriginField, buf[offset:], r.origin) - proto.UInt64Marshal(reqMetaHeaderNetMagicField, buf[offset:], r.netMagic) - - return buf -} - -func (r *RequestMetaHeader) StableSize() (size int) { - if r == nil { - return 0 - } - - if r.version != nil { - size += proto.NestedStructureSize(reqMetaHeaderVersionField, r.version) - } - - size += proto.UInt64Size(reqMetaHeaderEpochField, r.epoch) - size += proto.UInt32Size(reqMetaHeaderTTLField, r.ttl) - - for i := range r.xHeaders { - size += proto.NestedStructureSize(reqMetaHeaderXHeadersField, &r.xHeaders[i]) - } - - size += proto.NestedStructureSize(reqMetaHeaderSessionTokenField, r.sessionToken) - size += proto.NestedStructureSize(reqMetaHeaderBearerTokenField, r.bearerToken) - size += proto.NestedStructureSize(reqMetaHeaderOriginField, r.origin) - size += proto.UInt64Size(reqMetaHeaderNetMagicField, r.netMagic) - - return size -} - -func (r *RequestMetaHeader) Unmarshal(data []byte) error { - m := new(session.RequestMetaHeader) - if err := goproto.Unmarshal(data, m); err != nil { - return err - } - - return r.FromGRPCMessage(m) -} - -func (r *RequestVerificationHeader) StableMarshal(buf []byte) []byte { - if r == nil { - return []byte{} - } - - if buf == nil { - buf = make([]byte, r.StableSize()) - } - - var offset int - - offset += proto.NestedStructureMarshal(reqVerifHeaderBodySignatureField, buf[offset:], r.bodySig) - offset += proto.NestedStructureMarshal(reqVerifHeaderMetaSignatureField, buf[offset:], r.metaSig) - offset += proto.NestedStructureMarshal(reqVerifHeaderOriginSignatureField, buf[offset:], r.originSig) - proto.NestedStructureMarshal(reqVerifHeaderOriginField, buf[offset:], r.origin) - - return buf -} - -func (r *RequestVerificationHeader) StableSize() (size int) { - if r == nil { - return 0 - } - - size += proto.NestedStructureSize(reqVerifHeaderBodySignatureField, r.bodySig) - size += proto.NestedStructureSize(reqVerifHeaderMetaSignatureField, r.metaSig) - size += proto.NestedStructureSize(reqVerifHeaderOriginSignatureField, r.originSig) - size += proto.NestedStructureSize(reqVerifHeaderOriginField, r.origin) - - return size -} - -func (r *RequestVerificationHeader) Unmarshal(data []byte) error { - m := new(session.RequestVerificationHeader) - if err := goproto.Unmarshal(data, m); err != nil { - return err - } - - return r.FromGRPCMessage(m) -} - -func (r *ResponseMetaHeader) StableMarshal(buf []byte) []byte { - if r == nil { - return []byte{} - } - - if buf == nil { - buf = make([]byte, r.StableSize()) - } - - var offset int - - offset += proto.NestedStructureMarshal(respMetaHeaderVersionField, buf[offset:], r.version) - offset += proto.UInt64Marshal(respMetaHeaderEpochField, buf[offset:], r.epoch) - offset += proto.UInt32Marshal(respMetaHeaderTTLField, buf[offset:], r.ttl) - - for i := range r.xHeaders { - offset += proto.NestedStructureMarshal(respMetaHeaderXHeadersField, buf[offset:], &r.xHeaders[i]) - } - - offset += proto.NestedStructureMarshal(respMetaHeaderOriginField, buf[offset:], r.origin) - proto.NestedStructureMarshal(respMetaHeaderStatusField, buf[offset:], r.status) - - return buf -} - -func (r *ResponseMetaHeader) StableSize() (size int) { - if r == nil { - return 0 - } - - if r.version != nil { - size += proto.NestedStructureSize(respMetaHeaderVersionField, r.version) - } - - size += proto.UInt64Size(respMetaHeaderEpochField, r.epoch) - size += proto.UInt32Size(respMetaHeaderTTLField, r.ttl) - - for i := range r.xHeaders { - size += proto.NestedStructureSize(respMetaHeaderXHeadersField, &r.xHeaders[i]) - } - - size += proto.NestedStructureSize(respMetaHeaderOriginField, r.origin) - size += proto.NestedStructureSize(respMetaHeaderStatusField, r.status) - - return size -} - -func (r *ResponseMetaHeader) Unmarshal(data []byte) error { - m := new(session.ResponseMetaHeader) - if err := goproto.Unmarshal(data, m); err != nil { - return err - } - - return r.FromGRPCMessage(m) -} - -func (r *ResponseVerificationHeader) StableMarshal(buf []byte) []byte { - if r == nil { - return []byte{} - } - - if buf == nil { - buf = make([]byte, r.StableSize()) - } - - var offset int - - offset += proto.NestedStructureMarshal(respVerifHeaderBodySignatureField, buf[offset:], r.bodySig) - offset += proto.NestedStructureMarshal(respVerifHeaderMetaSignatureField, buf[offset:], r.metaSig) - offset += proto.NestedStructureMarshal(respVerifHeaderOriginSignatureField, buf[offset:], r.originSig) - proto.NestedStructureMarshal(respVerifHeaderOriginField, buf[offset:], r.origin) - - return buf -} - -func (r *ResponseVerificationHeader) StableSize() (size int) { - if r == nil { - return 0 - } - - size += proto.NestedStructureSize(respVerifHeaderBodySignatureField, r.bodySig) - size += proto.NestedStructureSize(respVerifHeaderMetaSignatureField, r.metaSig) - size += proto.NestedStructureSize(respVerifHeaderOriginSignatureField, r.originSig) - size += proto.NestedStructureSize(respVerifHeaderOriginField, r.origin) - - return size -} - -func (r *ResponseVerificationHeader) Unmarshal(data []byte) error { - m := new(session.ResponseVerificationHeader) - if err := goproto.Unmarshal(data, m); err != nil { - return err - } - - return r.FromGRPCMessage(m) -} diff --git a/session/message_test.go b/session/message_test.go index 39dd336..034cf5f 100644 --- a/session/message_test.go +++ b/session/message_test.go @@ -3,25 +3,25 @@ package session_test import ( "testing" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message" rpctest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message/test" sessiontest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/session/test" + "google.golang.org/protobuf/proto" ) func TestMessageConvert(t *testing.T) { rpctest.TestRPCMessage(t, - func(empty bool) message.Message { return sessiontest.GenerateCreateRequestBody(empty) }, - func(empty bool) message.Message { return sessiontest.GenerateCreateRequest(empty) }, - func(empty bool) message.Message { return sessiontest.GenerateCreateResponseBody(empty) }, - func(empty bool) message.Message { return sessiontest.GenerateCreateResponse(empty) }, - func(empty bool) message.Message { return sessiontest.GenerateTokenLifetime(empty) }, - func(empty bool) message.Message { return sessiontest.GenerateXHeader(empty) }, - func(empty bool) message.Message { return sessiontest.GenerateSessionTokenBody(empty) }, - func(empty bool) message.Message { return sessiontest.GenerateSessionToken(empty) }, - func(empty bool) message.Message { return sessiontest.GenerateRequestMetaHeader(empty) }, - func(empty bool) message.Message { return sessiontest.GenerateRequestVerificationHeader(empty) }, - func(empty bool) message.Message { return sessiontest.GenerateResponseMetaHeader(empty) }, - func(empty bool) message.Message { return sessiontest.GenerateResponseVerificationHeader(empty) }, - func(empty bool) message.Message { return sessiontest.GenerateContainerSessionContext(empty) }, + func(empty bool) proto.Message { return sessiontest.GenerateCreateRequestBody(empty) }, + func(empty bool) proto.Message { return sessiontest.GenerateCreateRequest(empty) }, + func(empty bool) proto.Message { return sessiontest.GenerateCreateResponseBody(empty) }, + func(empty bool) proto.Message { return sessiontest.GenerateCreateResponse(empty) }, + func(empty bool) proto.Message { return sessiontest.GenerateTokenLifetime(empty) }, + func(empty bool) proto.Message { return sessiontest.GenerateXHeader(empty) }, + func(empty bool) proto.Message { return sessiontest.GenerateSessionTokenBody(empty) }, + func(empty bool) proto.Message { return sessiontest.GenerateSessionToken(empty) }, + func(empty bool) proto.Message { return sessiontest.GenerateRequestMetaHeader(empty) }, + func(empty bool) proto.Message { return sessiontest.GenerateRequestVerificationHeader(empty) }, + func(empty bool) proto.Message { return sessiontest.GenerateResponseMetaHeader(empty) }, + func(empty bool) proto.Message { return sessiontest.GenerateResponseVerificationHeader(empty) }, + func(empty bool) proto.Message { return sessiontest.GenerateContainerSessionContext(empty) }, ) } diff --git a/session/status_test.go b/session/status_test.go index 57ce4bd..c17265a 100644 --- a/session/status_test.go +++ b/session/status_test.go @@ -3,7 +3,7 @@ package session_test import ( "testing" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/session" + session "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/session" statustest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/status/test" ) diff --git a/session/string.go b/session/string.go deleted file mode 100644 index 0e7c48a..0000000 --- a/session/string.go +++ /dev/null @@ -1,47 +0,0 @@ -package session - -import ( - session "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/session/grpc" -) - -// String returns string representation of ObjectSessionVerb. -func (x ObjectSessionVerb) String() string { - return ObjectSessionVerbToGRPCField(x).String() -} - -// FromString parses ObjectSessionVerb from a string representation. -// It is a reverse action to String(). -// -// Returns true if s was parsed successfully. -func (x *ObjectSessionVerb) FromString(s string) bool { - var g session.ObjectSessionContext_Verb - - ok := g.FromString(s) - - if ok { - *x = ObjectSessionVerbFromGRPCField(g) - } - - return ok -} - -// String returns string representation of ContainerSessionVerb. -func (x ContainerSessionVerb) String() string { - return ContainerSessionVerbToGRPCField(x).String() -} - -// FromString parses ContainerSessionVerb from a string representation. -// It is a reverse action to String(). -// -// Returns true if s was parsed successfully. -func (x *ContainerSessionVerb) FromString(s string) bool { - var g session.ContainerSessionContext_Verb - - ok := g.FromString(s) - - if ok { - *x = ContainerSessionVerbFromGRPCField(g) - } - - return ok -} diff --git a/session/test/generate.go b/session/test/generate.go index cfce6cd..055370e 100644 --- a/session/test/generate.go +++ b/session/test/generate.go @@ -4,16 +4,16 @@ import ( acltest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/acl/test" "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/internal/random" refstest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs/test" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/session" + session "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/session/grpc" statustest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/status/test" ) -func GenerateCreateRequestBody(empty bool) *session.CreateRequestBody { - m := new(session.CreateRequestBody) +func GenerateCreateRequestBody(empty bool) *session.CreateRequest_Body { + m := new(session.CreateRequest_Body) if !empty { m.SetExpiration(555) - m.SetOwnerID(refstest.GenerateOwnerID(false)) + m.SetOwnerId(refstest.GenerateOwnerID(false)) } return m @@ -27,16 +27,16 @@ func GenerateCreateRequest(empty bool) *session.CreateRequest { } m.SetMetaHeader(GenerateRequestMetaHeader(empty)) - m.SetVerificationHeader(GenerateRequestVerificationHeader(empty)) + m.SetVerifyHeader(GenerateRequestVerificationHeader(empty)) return m } -func GenerateCreateResponseBody(empty bool) *session.CreateResponseBody { - m := new(session.CreateResponseBody) +func GenerateCreateResponseBody(empty bool) *session.CreateResponse_Body { + m := new(session.CreateResponse_Body) if !empty { - m.SetID([]byte{1, 2, 3}) + m.SetId([]byte{1, 2, 3}) m.SetSessionKey([]byte{4, 5, 6}) } @@ -51,7 +51,7 @@ func GenerateCreateResponse(empty bool) *session.CreateResponse { } m.SetMetaHeader(GenerateResponseMetaHeader(empty)) - m.SetVerificationHeader(GenerateResponseVerificationHeader(empty)) + m.SetVerifyHeader(GenerateResponseVerificationHeader(empty)) return m } @@ -86,7 +86,7 @@ func generateResponseMetaHeader(empty, withOrigin bool) *session.ResponseMetaHea if !empty { m.SetEpoch(13) - m.SetTTL(100) + m.SetTtl(100) } m.SetXHeaders(GenerateXHeaders(empty)) @@ -130,7 +130,7 @@ func generateRequestMetaHeader(empty, withOrigin bool) *session.RequestMetaHeade if !empty { m.SetEpoch(13) - m.SetTTL(100) + m.SetTtl(100) m.SetNetworkMagic(1337) } @@ -146,8 +146,8 @@ func generateRequestMetaHeader(empty, withOrigin bool) *session.RequestMetaHeade return m } -func GenerateSessionToken(empty bool) *session.Token { - m := new(session.Token) +func GenerateSessionToken(empty bool) *session.SessionToken { + m := new(session.SessionToken) if !empty { m.SetBody(GenerateSessionTokenBody(false)) @@ -158,28 +158,28 @@ func GenerateSessionToken(empty bool) *session.Token { return m } -func GenerateSessionTokenBody(empty bool) *session.TokenBody { - m := new(session.TokenBody) +func GenerateSessionTokenBody(empty bool) *session.SessionToken_Body { + m := new(session.SessionToken_Body) if !empty { - m.SetID([]byte{1}) + m.SetId([]byte{1}) m.SetSessionKey([]byte{2}) - m.SetOwnerID(refstest.GenerateOwnerID(false)) + m.SetOwnerId(refstest.GenerateOwnerID(false)) m.SetLifetime(GenerateTokenLifetime(false)) switch random.Uint32(2) { case 0: - m.SetContext(GenerateObjectSessionContext(false)) + m.SetObjectSessionContext(GenerateObjectSessionContext(false)) case 1: - m.SetContext(GenerateContainerSessionContext(false)) + m.SetContainerSessionContext(GenerateContainerSessionContext(false)) } } return m } -func GenerateTokenLifetime(empty bool) *session.TokenLifetime { - m := new(session.TokenLifetime) +func GenerateTokenLifetime(empty bool) *session.SessionToken_Body_TokenLifetime { + m := new(session.SessionToken_Body_TokenLifetime) if !empty { m.SetExp(1) @@ -194,8 +194,8 @@ func GenerateObjectSessionContext(empty bool) *session.ObjectSessionContext { m := new(session.ObjectSessionContext) if !empty { - m.SetVerb(session.ObjectVerbHead) - m.SetTarget(refstest.GenerateContainerID(false), refstest.GenerateObjectIDs(false)...) + m.SetVerb(session.ObjectSessionContext_HEAD) + m.SetTarget(refstest.GenerateContainerID(false), refstest.GenerateObjectIDs(false)) } return m @@ -205,9 +205,9 @@ func GenerateContainerSessionContext(empty bool) *session.ContainerSessionContex m := new(session.ContainerSessionContext) if !empty { - m.SetVerb(session.ContainerVerbDelete) + m.SetVerb(session.ContainerSessionContext_DELETE) m.SetWildcard(true) - m.SetContainerID(refstest.GenerateContainerID(false)) + m.SetContainerId(refstest.GenerateContainerID(false)) } return m @@ -224,13 +224,13 @@ func GenerateXHeader(empty bool) *session.XHeader { return m } -func GenerateXHeaders(empty bool) []session.XHeader { - var xs []session.XHeader +func GenerateXHeaders(empty bool) []*session.XHeader { + var xs []*session.XHeader if !empty { xs = append(xs, - *GenerateXHeader(false), - *GenerateXHeader(false), + GenerateXHeader(false), + GenerateXHeader(false), ) } diff --git a/session/types.go b/session/types.go deleted file mode 100644 index 19cfecc..0000000 --- a/session/types.go +++ /dev/null @@ -1,834 +0,0 @@ -package session - -import ( - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/acl" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/status" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/util/proto" -) - -type CreateRequestBody struct { - ownerID *refs.OwnerID - - expiration uint64 -} - -type CreateRequest struct { - body *CreateRequestBody - - RequestHeaders -} - -type CreateResponseBody struct { - id []byte - - sessionKey []byte -} - -type CreateResponse struct { - body *CreateResponseBody - - ResponseHeaders -} - -type XHeader struct { - key, val string -} - -type TokenLifetime struct { - exp, nbf, iat uint64 -} - -type ObjectSessionVerb uint32 - -type objectSessionContextTarget struct { - cnr *refs.ContainerID - - objs []refs.ObjectID -} - -const ( - _ = iota - fNumObjectTargetContainer - fNumObjectTargetObjects -) - -func (x objectSessionContextTarget) StableMarshal(buf []byte) []byte { - if buf == nil { - buf = make([]byte, x.StableSize()) - } - - offset := proto.NestedStructureMarshal(fNumObjectTargetContainer, buf, x.cnr) - - for i := range x.objs { - offset += proto.NestedStructureMarshal(fNumObjectTargetObjects, buf[offset:], &x.objs[i]) - } - - return buf -} - -func (x objectSessionContextTarget) StableSize() (size int) { - size += proto.NestedStructureSize(fNumObjectTargetContainer, x.cnr) - - for i := range x.objs { - size += proto.NestedStructureSize(fNumObjectTargetObjects, &x.objs[i]) - } - - return size -} - -type ObjectSessionContext struct { - verb ObjectSessionVerb - - cnr *refs.ContainerID - - objs []refs.ObjectID -} - -type TokenContext interface { - sessionTokenContext() -} - -// Deprecated: use TokenContext instead. -// -//nolint:revive -type SessionTokenContext = TokenContext - -type TokenBody struct { - id []byte - - ownerID *refs.OwnerID - - lifetime *TokenLifetime - - sessionKey []byte - - ctx TokenContext -} - -// Deprecated: use TokenBody instead. -// -//nolint:revive -type SessionTokenBody = TokenBody - -type Token struct { - body *TokenBody - - sig *refs.Signature -} - -// Deprecated: use Token instead. -// -//nolint:revive -type SessionToken = Token - -type RequestVerificationHeader struct { - bodySig, metaSig, originSig *refs.Signature - - origin *RequestVerificationHeader -} - -type RequestMetaHeader struct { - version *refs.Version - - ttl uint32 - - epoch uint64 - - xHeaders []XHeader - - sessionToken *Token - - bearerToken *acl.BearerToken - - origin *RequestMetaHeader - - netMagic uint64 -} - -type ResponseVerificationHeader struct { - bodySig, metaSig, originSig *refs.Signature - - origin *ResponseVerificationHeader -} - -type ResponseMetaHeader struct { - version *refs.Version - - ttl uint32 - - epoch uint64 - - xHeaders []XHeader - - origin *ResponseMetaHeader - - status *status.Status -} - -const ( - ObjectVerbUnknown ObjectSessionVerb = iota - ObjectVerbPut - ObjectVerbGet - ObjectVerbHead - ObjectVerbSearch - ObjectVerbDelete - ObjectVerbRange - ObjectVerbRangeHash -) - -func (c *CreateRequestBody) GetOwnerID() *refs.OwnerID { - if c != nil { - return c.ownerID - } - - return nil -} - -func (c *CreateRequestBody) SetOwnerID(v *refs.OwnerID) { - c.ownerID = v -} - -func (c *CreateRequestBody) GetExpiration() uint64 { - if c != nil { - return c.expiration - } - - return 0 -} - -func (c *CreateRequestBody) SetExpiration(v uint64) { - c.expiration = v -} - -func (c *CreateRequest) GetBody() *CreateRequestBody { - if c != nil { - return c.body - } - - return nil -} - -func (c *CreateRequest) SetBody(v *CreateRequestBody) { - c.body = v -} - -func (c *CreateRequest) GetMetaHeader() *RequestMetaHeader { - if c != nil { - return c.metaHeader - } - - return nil -} - -func (c *CreateRequest) SetMetaHeader(v *RequestMetaHeader) { - c.metaHeader = v -} - -func (c *CreateRequest) GetVerificationHeader() *RequestVerificationHeader { - if c != nil { - return c.verifyHeader - } - - return nil -} - -func (c *CreateRequest) SetVerificationHeader(v *RequestVerificationHeader) { - c.verifyHeader = v -} - -func (c *CreateResponseBody) GetID() []byte { - if c != nil { - return c.id - } - - return nil -} - -func (c *CreateResponseBody) SetID(v []byte) { - c.id = v -} - -func (c *CreateResponseBody) GetSessionKey() []byte { - if c != nil { - return c.sessionKey - } - - return nil -} - -func (c *CreateResponseBody) SetSessionKey(v []byte) { - c.sessionKey = v -} - -func (c *CreateResponse) GetBody() *CreateResponseBody { - if c != nil { - return c.body - } - - return nil -} - -func (c *CreateResponse) SetBody(v *CreateResponseBody) { - c.body = v -} - -func (c *CreateResponse) GetMetaHeader() *ResponseMetaHeader { - if c != nil { - return c.metaHeader - } - - return nil -} - -func (c *CreateResponse) SetMetaHeader(v *ResponseMetaHeader) { - c.metaHeader = v -} - -func (c *CreateResponse) GetVerificationHeader() *ResponseVerificationHeader { - if c != nil { - return c.verifyHeader - } - - return nil -} - -func (c *CreateResponse) SetVerificationHeader(v *ResponseVerificationHeader) { - c.verifyHeader = v -} - -func (x *XHeader) GetKey() string { - if x != nil { - return x.key - } - - return "" -} - -func (x *XHeader) SetKey(v string) { - x.key = v -} - -func (x *XHeader) GetValue() string { - if x != nil { - return x.val - } - - return "" -} - -func (x *XHeader) SetValue(v string) { - x.val = v -} - -func (r *RequestVerificationHeader) GetBodySignature() *refs.Signature { - if r != nil { - return r.bodySig - } - - return nil -} - -func (r *RequestVerificationHeader) SetBodySignature(v *refs.Signature) { - r.bodySig = v -} - -func (r *RequestVerificationHeader) GetMetaSignature() *refs.Signature { - if r != nil { - return r.metaSig - } - - return nil -} - -func (r *RequestVerificationHeader) SetMetaSignature(v *refs.Signature) { - r.metaSig = v -} - -func (r *RequestVerificationHeader) GetOriginSignature() *refs.Signature { - if r != nil { - return r.originSig - } - - return nil -} - -func (r *RequestVerificationHeader) SetOriginSignature(v *refs.Signature) { - r.originSig = v -} - -func (r *RequestVerificationHeader) GetOrigin() *RequestVerificationHeader { - if r != nil { - return r.origin - } - - return nil -} - -func (r *RequestVerificationHeader) SetOrigin(v *RequestVerificationHeader) { - r.origin = v -} - -func (r *RequestMetaHeader) GetVersion() *refs.Version { - if r != nil { - return r.version - } - - return nil -} - -func (r *RequestMetaHeader) SetVersion(v *refs.Version) { - r.version = v -} - -func (r *RequestMetaHeader) GetTTL() uint32 { - if r != nil { - return r.ttl - } - - return 0 -} - -func (r *RequestMetaHeader) SetTTL(v uint32) { - r.ttl = v -} - -func (r *RequestMetaHeader) GetEpoch() uint64 { - if r != nil { - return r.epoch - } - - return 0 -} - -func (r *RequestMetaHeader) SetEpoch(v uint64) { - r.epoch = v -} - -func (r *RequestMetaHeader) GetXHeaders() []XHeader { - if r != nil { - return r.xHeaders - } - - return nil -} - -func (r *RequestMetaHeader) SetXHeaders(v []XHeader) { - r.xHeaders = v -} - -func (r *RequestMetaHeader) GetSessionToken() *Token { - if r != nil { - return r.sessionToken - } - - return nil -} - -func (r *RequestMetaHeader) SetSessionToken(v *Token) { - r.sessionToken = v -} - -func (r *RequestMetaHeader) GetBearerToken() *acl.BearerToken { - if r != nil { - return r.bearerToken - } - - return nil -} - -func (r *RequestMetaHeader) SetBearerToken(v *acl.BearerToken) { - r.bearerToken = v -} - -func (r *RequestMetaHeader) GetOrigin() *RequestMetaHeader { - if r != nil { - return r.origin - } - - return nil -} - -func (r *RequestMetaHeader) SetOrigin(v *RequestMetaHeader) { - r.origin = v -} - -// GetNetworkMagic returns NeoFS network magic. -func (r *RequestMetaHeader) GetNetworkMagic() uint64 { - if r != nil { - return r.netMagic - } - - return 0 -} - -// SetNetworkMagic sets NeoFS network magic. -func (r *RequestMetaHeader) SetNetworkMagic(v uint64) { - r.netMagic = v -} - -func (l *TokenLifetime) GetExp() uint64 { - if l != nil { - return l.exp - } - - return 0 -} - -func (l *TokenLifetime) SetExp(v uint64) { - l.exp = v -} - -func (l *TokenLifetime) GetNbf() uint64 { - if l != nil { - return l.nbf - } - - return 0 -} - -func (l *TokenLifetime) SetNbf(v uint64) { - l.nbf = v -} - -func (l *TokenLifetime) GetIat() uint64 { - if l != nil { - return l.iat - } - - return 0 -} - -func (l *TokenLifetime) SetIat(v uint64) { - l.iat = v -} - -func (r *ResponseVerificationHeader) GetBodySignature() *refs.Signature { - if r != nil { - return r.bodySig - } - - return nil -} - -func (r *ResponseVerificationHeader) SetBodySignature(v *refs.Signature) { - r.bodySig = v -} - -func (r *ResponseVerificationHeader) GetMetaSignature() *refs.Signature { - if r != nil { - return r.metaSig - } - - return nil -} - -func (r *ResponseVerificationHeader) SetMetaSignature(v *refs.Signature) { - r.metaSig = v -} - -func (r *ResponseVerificationHeader) GetOriginSignature() *refs.Signature { - if r != nil { - return r.originSig - } - - return nil -} - -func (r *ResponseVerificationHeader) SetOriginSignature(v *refs.Signature) { - r.originSig = v -} - -func (r *ResponseVerificationHeader) GetOrigin() *ResponseVerificationHeader { - if r != nil { - return r.origin - } - - return nil -} - -func (r *ResponseVerificationHeader) SetOrigin(v *ResponseVerificationHeader) { - r.origin = v -} - -func (r *ResponseMetaHeader) GetVersion() *refs.Version { - if r != nil { - return r.version - } - - return nil -} - -func (r *ResponseMetaHeader) SetVersion(v *refs.Version) { - r.version = v -} - -func (r *ResponseMetaHeader) GetTTL() uint32 { - if r != nil { - return r.ttl - } - - return 0 -} - -func (r *ResponseMetaHeader) SetTTL(v uint32) { - r.ttl = v -} - -func (r *ResponseMetaHeader) GetEpoch() uint64 { - if r != nil { - return r.epoch - } - - return 0 -} - -func (r *ResponseMetaHeader) SetEpoch(v uint64) { - r.epoch = v -} - -func (r *ResponseMetaHeader) GetXHeaders() []XHeader { - if r != nil { - return r.xHeaders - } - - return nil -} - -func (r *ResponseMetaHeader) SetXHeaders(v []XHeader) { - r.xHeaders = v -} - -func (r *ResponseMetaHeader) GetOrigin() *ResponseMetaHeader { - if r != nil { - return r.origin - } - - return nil -} - -func (r *ResponseMetaHeader) SetOrigin(v *ResponseMetaHeader) { - r.origin = v -} - -// GetStatus returns response status. -func (r *ResponseMetaHeader) GetStatus() *status.Status { - if r != nil { - return r.status - } - - return nil -} - -// SetStatus sets response status. -func (r *ResponseMetaHeader) SetStatus(v *status.Status) { - r.status = v -} - -// SetStatus sets status of the message which can carry ResponseMetaHeader. -// -// Sets status field on the "highest" level of meta headers. -// If meta header is missing in message, it is allocated. -func SetStatus(msg interface { - GetMetaHeader() *ResponseMetaHeader - SetMetaHeader(*ResponseMetaHeader) -}, st *status.Status) { - meta := msg.GetMetaHeader() - if meta == nil { - meta = new(ResponseMetaHeader) - msg.SetMetaHeader(meta) - } - - meta.SetStatus(st) -} - -func (c *ObjectSessionContext) sessionTokenContext() {} - -func (c *ObjectSessionContext) GetVerb() ObjectSessionVerb { - if c != nil { - return c.verb - } - - return ObjectVerbUnknown -} - -func (c *ObjectSessionContext) SetVerb(v ObjectSessionVerb) { - c.verb = v -} - -func (c *ObjectSessionContext) GetContainer() *refs.ContainerID { - if c != nil { - return c.cnr - } - - return nil -} - -func (c *ObjectSessionContext) GetObjects() []refs.ObjectID { - if c != nil { - return c.objs - } - - return nil -} - -func (c *ObjectSessionContext) SetTarget(cnr *refs.ContainerID, objs ...refs.ObjectID) { - c.cnr = cnr - c.objs = objs -} - -func (t *TokenBody) GetID() []byte { - if t != nil { - return t.id - } - - return nil -} - -func (t *TokenBody) SetID(v []byte) { - t.id = v -} - -func (t *TokenBody) GetOwnerID() *refs.OwnerID { - if t != nil { - return t.ownerID - } - - return nil -} - -func (t *TokenBody) SetOwnerID(v *refs.OwnerID) { - t.ownerID = v -} - -func (t *TokenBody) GetLifetime() *TokenLifetime { - if t != nil { - return t.lifetime - } - - return nil -} - -func (t *TokenBody) SetLifetime(v *TokenLifetime) { - t.lifetime = v -} - -func (t *TokenBody) GetSessionKey() []byte { - if t != nil { - return t.sessionKey - } - - return nil -} - -func (t *TokenBody) SetSessionKey(v []byte) { - t.sessionKey = v -} - -func (t *TokenBody) GetContext() TokenContext { - if t != nil { - return t.ctx - } - - return nil -} - -func (t *TokenBody) SetContext(v TokenContext) { - t.ctx = v -} - -func (t *Token) GetBody() *TokenBody { - if t != nil { - return t.body - } - - return nil -} - -func (t *Token) SetBody(v *TokenBody) { - t.body = v -} - -func (t *Token) GetSignature() *refs.Signature { - if t != nil { - return t.sig - } - - return nil -} - -func (t *Token) SetSignature(v *refs.Signature) { - t.sig = v -} - -// ContainerSessionVerb represents NeoFS API v2 -// session.ContainerSessionContext.Verb enumeration. -type ContainerSessionVerb uint32 - -const ( - // ContainerVerbUnknown corresponds to VERB_UNSPECIFIED enum value. - ContainerVerbUnknown ContainerSessionVerb = iota - - // ContainerVerbPut corresponds to PUT enum value. - ContainerVerbPut - - // ContainerVerbDelete corresponds to DELETE enum value. - ContainerVerbDelete - - // ContainerVerbSetEACL corresponds to SETEACL enum value. - ContainerVerbSetEACL -) - -// ContainerSessionContext represents structure of the -// NeoFS API v2 session.ContainerSessionContext message. -type ContainerSessionContext struct { - verb ContainerSessionVerb - - wildcard bool - - cid *refs.ContainerID -} - -func (x *ContainerSessionContext) sessionTokenContext() {} - -// Verb returns type of request for which the token is issued. -func (x *ContainerSessionContext) Verb() ContainerSessionVerb { - if x != nil { - return x.verb - } - - return ContainerVerbUnknown -} - -// SetVerb sets type of request for which the token is issued. -func (x *ContainerSessionContext) SetVerb(v ContainerSessionVerb) { - x.verb = v -} - -// Wildcard returns wildcard flag of the container session. -func (x *ContainerSessionContext) Wildcard() bool { - if x != nil { - return x.wildcard - } - - return false -} - -// SetWildcard sets wildcard flag of the container session. -func (x *ContainerSessionContext) SetWildcard(v bool) { - x.wildcard = v -} - -// ContainerID returns identifier of the container related to the session. -func (x *ContainerSessionContext) ContainerID() *refs.ContainerID { - if x != nil { - return x.cid - } - - return nil -} - -// SetContainerID sets identifier of the container related to the session. -func (x *ContainerSessionContext) SetContainerID(v *refs.ContainerID) { - x.cid = v -} diff --git a/session/util.go b/session/util.go deleted file mode 100644 index 7edca29..0000000 --- a/session/util.go +++ /dev/null @@ -1,163 +0,0 @@ -package session - -import ( - session "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/session/grpc" -) - -// RequestHeaders represents common part of -// all NeoFS requests including headers. -type RequestHeaders struct { - metaHeader *RequestMetaHeader - - verifyHeader *RequestVerificationHeader -} - -// GetMetaHeader returns meta header of the request. -func (c *RequestHeaders) GetMetaHeader() *RequestMetaHeader { - if c != nil { - return c.metaHeader - } - - return nil -} - -// SetMetaHeader sets meta header of the request. -func (c *RequestHeaders) SetMetaHeader(v *RequestMetaHeader) { - c.metaHeader = v -} - -// GetVerificationHeader returns verification header of the request. -func (c *RequestHeaders) GetVerificationHeader() *RequestVerificationHeader { - if c != nil { - return c.verifyHeader - } - - return nil -} - -// SetVerificationHeader sets verification header of the request. -func (c *RequestHeaders) SetVerificationHeader(v *RequestVerificationHeader) { - c.verifyHeader = v -} - -func (c *RequestHeaders) ToMessage(m interface { - SetMetaHeader(*session.RequestMetaHeader) - SetVerifyHeader(*session.RequestVerificationHeader) -}) { - m.SetMetaHeader(c.metaHeader.ToGRPCMessage().(*session.RequestMetaHeader)) - m.SetVerifyHeader(c.verifyHeader.ToGRPCMessage().(*session.RequestVerificationHeader)) -} - -func (c *RequestHeaders) FromMessage(m interface { - GetMetaHeader() *session.RequestMetaHeader - GetVerifyHeader() *session.RequestVerificationHeader -}) error { - metaHdr := m.GetMetaHeader() - if metaHdr == nil { - c.metaHeader = nil - } else { - if c.metaHeader == nil { - c.metaHeader = new(RequestMetaHeader) - } - - err := c.metaHeader.FromGRPCMessage(metaHdr) - if err != nil { - return err - } - } - - verifyHdr := m.GetVerifyHeader() - if verifyHdr == nil { - c.verifyHeader = nil - } else { - if c.verifyHeader == nil { - c.verifyHeader = new(RequestVerificationHeader) - } - - err := c.verifyHeader.FromGRPCMessage(verifyHdr) - if err != nil { - return err - } - } - - return nil -} - -// ResponseHeaders represents common part of -// all NeoFS responses including headers. -type ResponseHeaders struct { - metaHeader *ResponseMetaHeader - - verifyHeader *ResponseVerificationHeader -} - -// GetMetaHeader returns meta header of the response. -func (c *ResponseHeaders) GetMetaHeader() *ResponseMetaHeader { - if c != nil { - return c.metaHeader - } - - return nil -} - -// SetMetaHeader sets meta header of the response. -func (c *ResponseHeaders) SetMetaHeader(v *ResponseMetaHeader) { - c.metaHeader = v -} - -// GetVerificationHeader returns verification header of the response. -func (c *ResponseHeaders) GetVerificationHeader() *ResponseVerificationHeader { - if c != nil { - return c.verifyHeader - } - - return nil -} - -// SetVerificationHeader sets verification header of the response. -func (c *ResponseHeaders) SetVerificationHeader(v *ResponseVerificationHeader) { - c.verifyHeader = v -} - -func (c *ResponseHeaders) ToMessage(m interface { - SetMetaHeader(*session.ResponseMetaHeader) - SetVerifyHeader(*session.ResponseVerificationHeader) -}) { - m.SetMetaHeader(c.metaHeader.ToGRPCMessage().(*session.ResponseMetaHeader)) - m.SetVerifyHeader(c.verifyHeader.ToGRPCMessage().(*session.ResponseVerificationHeader)) -} - -func (c *ResponseHeaders) FromMessage(m interface { - GetMetaHeader() *session.ResponseMetaHeader - GetVerifyHeader() *session.ResponseVerificationHeader -}) error { - metaHdr := m.GetMetaHeader() - if metaHdr == nil { - c.metaHeader = nil - } else { - if c.metaHeader == nil { - c.metaHeader = new(ResponseMetaHeader) - } - - err := c.metaHeader.FromGRPCMessage(metaHdr) - if err != nil { - return err - } - } - - verifyHdr := m.GetVerifyHeader() - if verifyHdr == nil { - c.verifyHeader = nil - } else { - if c.verifyHeader == nil { - c.verifyHeader = new(ResponseVerificationHeader) - } - - err := c.verifyHeader.FromGRPCMessage(verifyHdr) - if err != nil { - return err - } - } - - return nil -} diff --git a/signature/body.go b/signature/body.go index b7bb6b4..2720c82 100644 --- a/signature/body.go +++ b/signature/body.go @@ -3,11 +3,11 @@ package signature import ( "fmt" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/accounting" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/container" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/netmap" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/object" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/session" + accounting "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/accounting/grpc" + container "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/container/grpc" + netmap "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/netmap/grpc" + object "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/object/grpc" + session "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/session/grpc" ) // nolint:funlen @@ -101,9 +101,9 @@ func serviceMessageBody(req any) stableMarshaler { return v.GetBody() case *netmap.NetworkInfoResponse: return v.GetBody() - case *netmap.SnapshotRequest: + case *netmap.NetmapSnapshotRequest: return v.GetBody() - case *netmap.SnapshotResponse: + case *netmap.NetmapSnapshotResponse: return v.GetBody() } } diff --git a/signature/sign.go b/signature/sign.go index f50d83f..f1776f2 100644 --- a/signature/sign.go +++ b/signature/sign.go @@ -4,22 +4,22 @@ import ( "crypto/ecdsa" "fmt" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/session" + refs "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs/grpc" + session "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/session/grpc" "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/util/signature" "golang.org/x/sync/errgroup" ) type serviceRequest interface { GetMetaHeader() *session.RequestMetaHeader - GetVerificationHeader() *session.RequestVerificationHeader - SetVerificationHeader(*session.RequestVerificationHeader) + GetVerifyHeader() *session.RequestVerificationHeader + SetVerifyHeader(*session.RequestVerificationHeader) } type serviceResponse interface { GetMetaHeader() *session.ResponseMetaHeader - GetVerificationHeader() *session.ResponseVerificationHeader - SetVerificationHeader(*session.ResponseVerificationHeader) + GetVerifyHeader() *session.ResponseVerificationHeader + SetVerifyHeader(*session.ResponseVerificationHeader) } type signatureReceiver interface { @@ -46,12 +46,12 @@ func signServiceRequest(key *ecdsa.PrivateKey, v serviceRequest) error { result := &session.RequestVerificationHeader{} body := serviceMessageBody(v) meta := v.GetMetaHeader() - header := v.GetVerificationHeader() + header := v.GetVerifyHeader() if err := signMessageParts(key, body, meta, header, header != nil, result); err != nil { return err } result.SetOrigin(header) - v.SetVerificationHeader(result) + v.SetVerifyHeader(result) return nil } @@ -59,12 +59,12 @@ func signServiceResponse(key *ecdsa.PrivateKey, v serviceResponse) error { result := &session.ResponseVerificationHeader{} body := serviceMessageBody(v) meta := v.GetMetaHeader() - header := v.GetVerificationHeader() + header := v.GetVerifyHeader() if err := signMessageParts(key, body, meta, header, header != nil, result); err != nil { return err } result.SetOrigin(header) - v.SetVerificationHeader(result) + v.SetVerifyHeader(result) return nil } diff --git a/signature/sign_test.go b/signature/sign_test.go index c013525..106aef8 100644 --- a/signature/sign_test.go +++ b/signature/sign_test.go @@ -3,8 +3,8 @@ package signature import ( "testing" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/accounting" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/session" + accounting "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/accounting/grpc" + session "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/session/grpc" crypto "git.frostfs.info/TrueCloudLab/frostfs-crypto" "github.com/stretchr/testify/require" ) @@ -13,11 +13,11 @@ func TestBalanceResponse(t *testing.T) { dec := new(accounting.Decimal) dec.SetValue(100) - body := new(accounting.BalanceResponseBody) + body := new(accounting.BalanceResponse_Body) body.SetBalance(dec) meta := new(session.ResponseMetaHeader) - meta.SetTTL(1) + meta.SetTtl(1) req := new(accounting.BalanceResponse) req.SetBody(body) @@ -56,16 +56,16 @@ func TestBalanceResponse(t *testing.T) { dec.SetValue(dec.GetValue() - 1) // corrupt meta header - meta.SetTTL(meta.GetTTL() + 1) + meta.SetTtl(meta.GetTtl() + 1) // verification must fail require.Error(t, VerifyServiceMessage(req)) // restore meta header - meta.SetTTL(meta.GetTTL() - 1) + meta.SetTtl(meta.GetTtl() - 1) // corrupt origin verification header - req.GetVerificationHeader().SetOrigin(nil) + req.GetVerifyHeader().SetOrigin(nil) // verification must fail require.Error(t, VerifyServiceMessage(req)) @@ -82,11 +82,11 @@ func BenchmarkSignRequest(b *testing.B) { dec := new(accounting.Decimal) dec.SetValue(100) - body := new(accounting.BalanceResponseBody) + body := new(accounting.BalanceResponse_Body) body.SetBalance(dec) meta := new(session.ResponseMetaHeader) - meta.SetTTL(1) + meta.SetTtl(1) resp := new(accounting.BalanceResponse) resp.SetBody(body) @@ -108,11 +108,11 @@ func BenchmarkVerifyRequest(b *testing.B) { dec := new(accounting.Decimal) dec.SetValue(100) - body := new(accounting.BalanceResponseBody) + body := new(accounting.BalanceResponse_Body) body.SetBalance(dec) meta := new(session.ResponseMetaHeader) - meta.SetTTL(1) + meta.SetTtl(1) resp := new(accounting.BalanceResponse) resp.SetBody(body) diff --git a/signature/verify.go b/signature/verify.go index 7a8ed82..bd79553 100644 --- a/signature/verify.go +++ b/signature/verify.go @@ -4,8 +4,8 @@ import ( "errors" "fmt" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/session" + refs "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs/grpc" + session "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/session/grpc" "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/util/signature" "golang.org/x/sync/errgroup" ) @@ -32,7 +32,7 @@ func VerifyServiceMessage(msg any) error { func verifyServiceRequest(v serviceRequest) error { meta := v.GetMetaHeader() - verificationHeader := v.GetVerificationHeader() + verificationHeader := v.GetVerifyHeader() body := serviceMessageBody(v) return verifyServiceRequestRecursive(body, meta, verificationHeader) } @@ -95,7 +95,7 @@ func verifyMessageParts(body, meta, originHeader stableMarshaler, hasOriginHeade func verifyServiceResponse(v serviceResponse) error { meta := v.GetMetaHeader() - verificationHeader := v.GetVerificationHeader() + verificationHeader := v.GetVerifyHeader() body := serviceMessageBody(v) return verifyServiceResponseRecursive(body, meta, verificationHeader) } diff --git a/status/convert.go b/status/convert.go deleted file mode 100644 index 0743952..0000000 --- a/status/convert.go +++ /dev/null @@ -1,97 +0,0 @@ -package status - -import ( - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/grpc" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message" - status "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/status/grpc" -) - -func (x *Detail) ToGRPCMessage() grpc.Message { - var m *status.Status_Detail - - if x != nil { - m = new(status.Status_Detail) - - m.SetId(x.id) - m.SetValue(x.val) - } - - return m -} - -func (x *Detail) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*status.Status_Detail) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - x.id = v.GetId() - x.val = v.GetValue() - - return nil -} - -func CodeFromGRPC(v uint32) Code { - return Code(v) -} - -func CodeToGRPC(v Code) uint32 { - return uint32(v) -} - -func (x *Status) ToGRPCMessage() grpc.Message { - var m *status.Status - - if x != nil { - m = new(status.Status) - - m.SetCode(CodeToGRPC(x.code)) - m.SetMessage(x.msg) - - var ds []*status.Status_Detail - - if ln := len(x.details); ln > 0 { - ds = make([]*status.Status_Detail, 0, ln) - - for i := 0; i < ln; i++ { - ds = append(ds, x.details[i].ToGRPCMessage().(*status.Status_Detail)) - } - } - - m.SetDetails(ds) - } - - return m -} - -func (x *Status) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*status.Status) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var ( - ds []Detail - dsV2 = v.GetDetails() - ) - - if dsV2 != nil { - ln := len(dsV2) - - ds = make([]Detail, ln) - - for i := 0; i < ln; i++ { - if dsV2[i] != nil { - if err := ds[i].FromGRPCMessage(dsV2[i]); err != nil { - return err - } - } - } - } - - x.details = ds - x.msg = v.GetMessage() - x.code = CodeFromGRPC(v.GetCode()) - - return nil -} diff --git a/status/details.go b/status/details.go deleted file mode 100644 index 5b8f460..0000000 --- a/status/details.go +++ /dev/null @@ -1,8 +0,0 @@ -package status - -// details for WrongMagicNumber code. -const ( - // DetailIDCorrectMagic is an identifier of details with correct network magic - // which can be attached to WrongMagicNumber code. - DetailIDCorrectMagic = iota -) diff --git a/status/grpc/code.go b/status/grpc/code.go new file mode 100644 index 0000000..3e95c03 --- /dev/null +++ b/status/grpc/code.go @@ -0,0 +1,88 @@ +package status + +const sectionBitSize = 10 + +// EqualNumber checks if the numerical Code equals num. +func EqualNumber(code, num uint32) bool { + return code == num +} + +// InSections checks if the Code is in [i,j] section list. +func InSections(code, i, j uint32) bool { + return code >= i<