From bc16a32c24c326fc437a9093fa762a88bb038c19 Mon Sep 17 00:00:00 2001 From: Airat Arifullin Date: Tue, 13 Jun 2023 01:33:53 +0300 Subject: [PATCH] [#40] types: Generate StableMarshaler/StableSize methods for protobufs * Add plugin option for protogen in Makefile * Fix the generator for the plugin in util/protogen * Erase convertable types, move helpful methods to gRPC protobufs * Erase helpers for convertations * Generate StableMarshlal/StableSize for protobufs by the protoc plugin Signed-off-by: Airat Arifullin a.arifullin@yadro.com --- Makefile | 4 +- accounting/accounting.go | 104 -- accounting/convert.go | 178 -- accounting/grpc/service.pb.go | Bin 18993 -> 18993 bytes accounting/grpc/service_frostfs.pb.go | Bin 0 -> 4262 bytes accounting/grpc/service_grpc.pb.go | Bin 4321 -> 4321 bytes accounting/grpc/types.pb.go | Bin 6048 -> 6048 bytes accounting/grpc/types_frostfs.pb.go | Bin 0 -> 1112 bytes accounting/json.go | 14 - accounting/marshal.go | 104 -- accounting/message_test.go | 12 +- accounting/test/generate.go | 17 +- acl/bench_test.go | 41 +- acl/convert.go | 535 ------ acl/grpc/types.pb.go | Bin 39444 -> 39444 bytes acl/grpc/types_frostfs.pb.go | Bin 0 -> 8273 bytes acl/json.go | 62 - acl/marshal.go | 308 ---- acl/message_test.go | 16 +- acl/string.go | 110 -- acl/test/generate.go | 66 +- acl/types.go | 379 ----- audit/convert.go | 94 -- audit/grpc/types.pb.go | Bin 12413 -> 12413 bytes audit/grpc/types_frostfs.pb.go | Bin 0 -> 2561 bytes audit/json.go | 14 - audit/marshal.go | 88 - audit/message_test.go | 4 +- audit/test/generate.go | 8 +- audit/types.go | 243 --- container/attributes_test.go | 6 +- container/convert.go | 1280 --------------- container/{ => grpc}/attributes.go | 23 +- container/grpc/service.pb.go | Bin 112809 -> 112809 bytes container/grpc/service_frostfs.pb.go | Bin 0 -> 30609 bytes container/grpc/service_grpc.pb.go | Bin 18225 -> 18117 bytes container/grpc/types.pb.go | Bin 13484 -> 13484 bytes container/grpc/types_frostfs.pb.go | Bin 0 -> 2659 bytes container/json.go | 22 - container/marshal.go | 546 ------- container/message_test.go | 68 +- container/test/generate.go | 142 +- container/types.go | 717 -------- lock/grpc/lock_test.go | 28 + lock/grpc/types.go | 56 +- lock/grpc/types.pb.go | Bin 5767 -> 5767 bytes lock/grpc/types_frostfs.pb.go | Bin 0 -> 1091 bytes lock/test/generate.go | 20 + netmap/convert.go | 919 ----------- netmap/grpc/service.pb.go | Bin 46017 -> 46017 bytes netmap/grpc/service_frostfs.pb.go | Bin 0 -> 12073 bytes netmap/grpc/service_grpc.pb.go | Bin 9124 -> 9124 bytes netmap/grpc/types.go | 51 + netmap/grpc/types_frostfs.pb.go | Bin 0 -> 11909 bytes netmap/json.go | 62 - netmap/marshal.go | 554 ------- netmap/message_test.go | 38 +- netmap/string.go | 68 - netmap/test/generate.go | 114 +- netmap/types.go | 751 --------- object/attributes.go | 14 +- object/attributes_test.go | 19 +- object/bench_test.go | 45 - object/convert.go | 2171 ------------------------- object/grpc/service.go | 14 + object/grpc/service.pb.go | Bin 145650 -> 145650 bytes object/grpc/service_frostfs.pb.go | Bin 0 -> 41864 bytes object/grpc/service_grpc.pb.go | Bin 37991 -> 37545 bytes object/grpc/types.pb.go | Bin 41264 -> 41264 bytes object/grpc/types_frostfs.pb.go | Bin 0 -> 8771 bytes object/json.go | 78 - object/lock.go | 160 -- object/lock_test.go | 26 - object/marshal.go | 1120 ------------- object/message_test.go | 94 +- object/status.go | 18 +- object/status_test.go | 8 +- object/string.go | 55 - object/test/generate.go | 235 +-- object/types.go | 1473 ----------------- refs/bench_test.go | 44 +- refs/convert.go | 268 --- refs/grpc/types.go | 24 + refs/grpc/types.pb.go | Bin 27235 -> 27235 bytes refs/grpc/types_frostfs.pb.go | Bin 0 -> 7706 bytes refs/json.go | 62 - refs/marshal.go | 263 --- refs/message_test.go | 16 +- refs/string.go | 47 - refs/test/generate.go | 35 +- refs/types.go | 194 --- rpc/accounting.go | 2 +- rpc/client/flows.go | 14 +- rpc/client/init.go | 6 +- rpc/client/stream_wrapper.go | 20 +- rpc/container.go | 2 +- rpc/message/test/message.go | 67 +- rpc/netmap.go | 8 +- rpc/object.go | 6 +- rpc/session.go | 2 +- session/convert.go | 893 ---------- session/grpc/service.pb.go | Bin 18263 -> 18263 bytes session/grpc/service_frostfs.pb.go | Bin 0 -> 4429 bytes session/grpc/service_grpc.pb.go | Bin 4108 -> 4108 bytes session/grpc/types.go | 17 + session/grpc/types.pb.go | Bin 57088 -> 57088 bytes session/grpc/types_frostfs.pb.go | Bin 0 -> 14095 bytes session/json.go | 129 -- session/marshal.go | 582 ------- session/message_test.go | 28 +- session/status_test.go | 2 +- session/string.go | 47 - session/test/generate.go | 58 +- session/types.go | 834 ---------- session/util.go | 163 -- signature/body.go | 14 +- signature/sign.go | 20 +- signature/sign_test.go | 22 +- signature/verify.go | 8 +- status/convert.go | 97 -- status/details.go | 8 - status/grpc/code.go | 88 + status/grpc/details.go | 51 + status/grpc/types.pb.go | Bin 21744 -> 21744 bytes status/grpc/types_frostfs.pb.go | Bin 0 -> 2253 bytes status/marshal.go | 84 - status/message_test.go | 16 - status/test/generate.go | 16 +- status/types.go | 117 +- storagegroup/convert.go | 59 - storagegroup/grpc/types.pb.go | Bin 8923 -> 9009 bytes storagegroup/grpc/types_frostfs.pb.go | Bin 0 -> 1482 bytes storagegroup/json.go | 14 - storagegroup/marshal.go | 54 - storagegroup/message_test.go | 4 +- storagegroup/test/generate.go | 2 +- storagegroup/types.go | 79 - tombstone/convert.go | 41 - tombstone/grpc/types.pb.go | Bin 7272 -> 7272 bytes tombstone/grpc/types_frostfs.pb.go | Bin 0 -> 1318 bytes tombstone/json.go | 14 - tombstone/marshal.go | 56 - tombstone/message_test.go | 4 +- tombstone/test/generate.go | 4 +- tombstone/types.go | 57 - util/proto/marshal.go | 6 +- util/proto/test/test.pb.go | Bin 13851 -> 13851 bytes util/protogen/main.go | 111 +- util/signature/data.go | 2 +- util/signature/options.go | 18 +- util/signature/sign_test.go | 4 +- 151 files changed, 1099 insertions(+), 17200 deletions(-) delete mode 100644 accounting/accounting.go delete mode 100644 accounting/convert.go create mode 100644 accounting/grpc/service_frostfs.pb.go create mode 100644 accounting/grpc/types_frostfs.pb.go delete mode 100644 accounting/json.go delete mode 100644 accounting/marshal.go delete mode 100644 acl/convert.go create mode 100644 acl/grpc/types_frostfs.pb.go delete mode 100644 acl/json.go delete mode 100644 acl/marshal.go delete mode 100644 acl/string.go delete mode 100644 acl/types.go delete mode 100644 audit/convert.go create mode 100644 audit/grpc/types_frostfs.pb.go delete mode 100644 audit/json.go delete mode 100644 audit/marshal.go delete mode 100644 audit/types.go delete mode 100644 container/convert.go rename container/{ => grpc}/attributes.go (77%) create mode 100644 container/grpc/service_frostfs.pb.go create mode 100644 container/grpc/types_frostfs.pb.go delete mode 100644 container/json.go delete mode 100644 container/marshal.go delete mode 100644 container/types.go create mode 100644 lock/grpc/lock_test.go create mode 100644 lock/grpc/types_frostfs.pb.go create mode 100644 lock/test/generate.go delete mode 100644 netmap/convert.go create mode 100644 netmap/grpc/service_frostfs.pb.go create mode 100644 netmap/grpc/types_frostfs.pb.go delete mode 100644 netmap/json.go delete mode 100644 netmap/marshal.go delete mode 100644 netmap/string.go delete mode 100644 netmap/types.go delete mode 100644 object/bench_test.go delete mode 100644 object/convert.go create mode 100644 object/grpc/service_frostfs.pb.go create mode 100644 object/grpc/types_frostfs.pb.go delete mode 100644 object/json.go delete mode 100644 object/lock.go delete mode 100644 object/lock_test.go delete mode 100644 object/marshal.go delete mode 100644 object/string.go delete mode 100644 object/types.go delete mode 100644 refs/convert.go create mode 100644 refs/grpc/types_frostfs.pb.go delete mode 100644 refs/json.go delete mode 100644 refs/marshal.go delete mode 100644 refs/string.go delete mode 100644 refs/types.go delete mode 100644 session/convert.go create mode 100644 session/grpc/service_frostfs.pb.go create mode 100644 session/grpc/types_frostfs.pb.go delete mode 100644 session/json.go delete mode 100644 session/marshal.go delete mode 100644 session/string.go delete mode 100644 session/types.go delete mode 100644 session/util.go delete mode 100644 status/convert.go delete mode 100644 status/details.go create mode 100644 status/grpc/code.go create mode 100644 status/grpc/details.go create mode 100644 status/grpc/types_frostfs.pb.go delete mode 100644 status/marshal.go delete mode 100644 status/message_test.go delete mode 100644 storagegroup/convert.go create mode 100644 storagegroup/grpc/types_frostfs.pb.go delete mode 100644 storagegroup/json.go delete mode 100644 storagegroup/marshal.go delete mode 100644 storagegroup/types.go delete mode 100644 tombstone/convert.go create mode 100644 tombstone/grpc/types_frostfs.pb.go delete mode 100644 tombstone/json.go delete mode 100644 tombstone/marshal.go delete mode 100644 tombstone/types.go 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 9699622c290ee7cc4515ab0a56c1f05ed3ff5473..4c0e5290b6aa45aaff8e360f763d73798e7aea50 100644 GIT binary patch delta 43 tcmdlug>mB)#tFf4#s+!@T>AP7oCQVsCHct;P*7&9XK18nva#@hCjb*Y3_bt= delta 43 tcmdlug>mB)#tFf4MizR8T>AP7oCQVsCHct;P*7&9XJn{nxv}toCjb;&3`+n2 diff --git a/accounting/grpc/service_frostfs.pb.go b/accounting/grpc/service_frostfs.pb.go new file mode 100644 index 0000000000000000000000000000000000000000..faacb90d4cbabd1e47c2646427f0dc7bec0d7cfe GIT binary patch literal 4262 zcmeH~OHbQC5XaB)rx(YEWrqY-KVy8N&JS3cj42 zUS&x#W5q2SBe0@SwX|H0lY~!aN?X_)bDMQ;TvjT-(ls6nRhQq`D34DDY{n^mK0nB7 z%SGDGtOlB$*kq<8S{hzTYOyuhF2VSgN{vh6Qrmi8g_ z32|xraG&(JOYHCvBp2?o7cz$rN$(-)dCT{QA?xg%0%Cb-W2){$(~tXbmkk?g!)e)1 zI&bHfJS-LEjA=7r0;b_;)`}57CDbHT!1!Xu?^n7+-PP)}0xDpI8U)HQ6^k1>Gp^W7 zQZ|b=r2T!6*mUM($AnOY1Evdh5gWy13#hfyfYOtJny6|fyqG}AOOVQX=LQ4jx;)nbSH<*` z^ZAaNSM8%$TrQmRO4)aUClK8l^}2%Zfa?_G^!eXvJ;J@=VnKwjFBU7jZy1K4Uk~%N z1juSd0Zua8u<)3fk_P|HAP|R--5{{VgTNC!yp7c%489BYwp)&ybb0pifEVE_OC literal 0 HcmV?d00001 diff --git a/accounting/grpc/service_grpc.pb.go b/accounting/grpc/service_grpc.pb.go index 1e1b17e20923032c26033210575bccaa9759f088..c72e811a8f731e09826e236003610df900ad6d5d 100644 GIT binary patch delta 15 WcmaE;_)u{|EsLR%p2^0>1OWgsPz8Me delta 15 WcmaE;_)u{|EsK$%p5?~I1OWgsY6XG- diff --git a/accounting/grpc/types.pb.go b/accounting/grpc/types.pb.go index b8dff215d33a7d5a6f8fdbe8c0a52ce9bfd37e97..da24b0691ad5b81d9b86399620a0b37bb0101b76 100644 GIT binary patch delta 41 rcmZ3Wzd(ONu$-}ho&lG>z5-`KQGQ8&vH}#88S5Du>6vUS)E5T;>7)vc delta 41 rcmZ3Wzd(ONu$+;Fo*|dMz5-`KQGQ8&vH}#88S5Dt>RE0q)E5T;>ca|} diff --git a/accounting/grpc/types_frostfs.pb.go b/accounting/grpc/types_frostfs.pb.go new file mode 100644 index 0000000000000000000000000000000000000000..028311c36f1462f30946ca7877bab2b79f3b5d4b GIT binary patch literal 1112 zcmbW0Pmj|u5XH~+rx@)ifi{7HI3V@3ptaa?lcAA#ees{)kqU~0| z0jW~{y*GV%^Glw?t*H=d)M&ZK3W_rvtnsE?(7i=%7Q!0mh09>Qg|FK^d|Gez8Dj@t zKJXfWm!;{nm%3(5wg+Q9+|<%%lTB)2^1bcwR++B)%!_<{vfu|v^Yh~}@4Qs`@UJ(F z0xeazoW->8 zhRvSXY*4;l#iZFr`w#EKD7u4D z+`5Jk2aWwC zCmmPHlmVe>*!OXDT%Q50H5O10te_>%`bL%wRI&nX{9x{(w=#eFo`y@>>;ooI8KAga0&zjcBe(Qj2#21&49{lc`Ahbue1sp3y^ETU_m?nU T`y!5$k%+uD{((=D5T3sQnILvF literal 0 HcmV?d00001 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 94a8e4751780de1a937133934ac45bed9cfe0aec..8ca9677971df34eb4dbf74453de546b91e7656b7 100644 GIT binary patch delta 43 tcmbQTg=xwbrU}7v#s+!@T>AP7oCQVsCHct;P*7&9XK18nvaxXSOaK&H40!+m delta 43 tcmbQTg=xwbrU}7vMizR8T>AP7oCQVsCHct;P*7&9XJn{nxv_BZOaK*n42A#z diff --git a/acl/grpc/types_frostfs.pb.go b/acl/grpc/types_frostfs.pb.go new file mode 100644 index 0000000000000000000000000000000000000000..bb571f01ed606e24425d728bd0e589fb398e0f69 GIT binary patch literal 8273 zcmeHMQE%Ev5Ppt-#i&nkmzcY>x`#@6NK#IRE)7z`^(Bg;#U8^dW*4oO0ImApZ+6!k zY-6a~Yjlo;goKS}X2(0<_j$(jdT=RYgb4~%Ok)h=HO!UNGCHB(PA2jsQ8Lp>7Q%-i zTn|Uk|1cPZK`>|0Bby+wC=CKWn@gqP&4laF+jEh~-bgL*GL?(?ij8~ul@m7S6u9?v z+FNLz_Uv+Rf}q!fTg}EP-tx}~3iU#X4D=KsGe5`#R=|bJZoEh!k!r?tNPf;$Eh2Kk z43=C^ogbSaBplNio>;n|OH=lQn@eLZm|ENLVUR3D1f3Q9(m%hvy1_`Q_~B2UYE<1q zUY#y5m$8;n5?P+Hf z{)H??HCoTH+udn@y0QPrbTq9uztxJ1iCy6BF|5MBalI9?VDrw{d@|cYR(aMY-{5PZ z6d#$&rYwb-`_3vQ$T!ec!tHxzOPKFE?I9{(p+N#vwgeTVC?-@Qp3zZeO3Vc1vMGM2 zdkg}X-kj`Mn##!F(+9iB;lacjP${VZMI;x3%0(bvPI)win8zTbw$4jfDz0gNZ1rQN z8ANh6Pf=sKHbG%XNK;Fm;c*FjdCCMl7u4XHsrq(gz+4I8cq?5bo0;B9vozTI_ctZdBbWOrgsqq8QqhaATNP*sb}B;apw zOM?7p(2!Qu*cD>=WokO1?_yfRWokO79pr1FvX0F3=>cdJ=|4<+l{(mP)D_drg(@@J zS{?W59Bd19DTQX72J}HpPFs5DX4R&8Xf-x>Ip|@V$G;L9J&ju^hZWrVOt&V$BJvxm z$(A;*!tWqM!$oS8aR)zICRrEA6umo=k0>54WW0W`hgUp7&1XMN$Nm`z{l~kFeDzoJ zE$J%QSjD;?C;M!y1`U`dn?onovQDfSs65GAC`S&9KEWClasaN1L)ooHcpRqpyVXcZ z3Fa*qkQZ-#`t)ysd#p8Xeuhim_+;jd+PCM&XZ@=#aUo@DWz3F*=k!K-IhfI;n@K_M ztqxk$zIRkrE%NyEmz3+_p-$d_wX=|63jesMP}GVdL5Gs!GC`upZA literal 0 HcmV?d00001 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 a2cac438899cffba3df1e2a0773962127101d0ec..ef5795be2ec1254f97a7a12e86769d4c9218bf53 100644 GIT binary patch delta 41 rcmeyH@Hb&Xu$-}ho&lG>z5-`KQGQ8&vH}#88S5Du>6vUSRE0q$XZfZ2hBETiXe`y;OZL$qiTyHnW`qtNPt{Z6_@_ zlrjkkNbWhl_VxM2F`UR0VT1w|Gnm3~0aGQ7OxpCUJ(BHANo_LSfzxZay1s$4(~Fx< z6ir!j&qfHWNV$n3KAB2oU}wZlr&4f{$@oSUc#_K^{lSKD`KHaLoUG%A{kSkZkKKYh zQ5458Fl?CPfd55MXbL4Xm@$I34`c>&;KKJeEHcQXnlRHLotLU2Aqi@jaWnQhHbKZZ z<|#a|yr5TO_JA+1hFmbUaQ2-jD?|d#IlMb%hJCU7>Z2}l(^~4P*@C8Ph6{TB7&W+U zs@DU-bNjd9yN11}@f0;&<@=uRxO0V?PIzF-Hti;x-CdY>exuS{idHB%=W|St4qf5C zEp$ztO=U8!)vhx?u$mJo4C6H3i?k;Cx-h7n{h=-WSqyWYe8)w-P|DoZeejl(X^sYK zWxp&cmY+=f_xNx@U+Wt89S*` zR8>STGN9aMs31o%qKtA)zqHLb6LfMf>2J1nLEx+^r#hDBGO^pP%=#rCm{gFd}qC1h!=X4%&WANf>65x!B8Gx zu(F|igf^>O41HX-Dm7&#R4=2lrX^TbQsQMOJt;38ooT4_D546Lvj;#w_JqS8!i%%I5b*4K#Swhz{B|s-I^O)^7;+on(JC3JQS`V Zxth4;c-ZhV)weTQb6wYfp4K7G{{!_?StbAg literal 0 HcmV?d00001 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 e3bdaf0c8a0ac920cb107136c95fb5201a7c0dcf..c2f4e5fb316f719a690101e33a17e71ec6415f3b 100644 GIT binary patch delta 46 wcmZ4ak!|Hiwh6&<#s+!@T>AP7oCQVsCHct;P*7&9XK18n(pb2)kkMiX09LmR&;S4c delta 46 wcmZ4ak!|Hiwh6&AP7oCQVsCHct;P*7&9XJn{n*;u%>kkMiX09XAD-2eap diff --git a/container/grpc/service_frostfs.pb.go b/container/grpc/service_frostfs.pb.go new file mode 100644 index 0000000000000000000000000000000000000000..13dd0becace408585991ae39876eee70063f5899 GIT binary patch literal 30609 zcmeHQ-*4MC5PpvT3ZhTWme^Z2?4dv&x+K^Fw9QbbdkKPqwkVs3OnDL=$1D23??{P` zq|o}|*bc275Fl|ZQWWpIk9WsAvEL`>p~uLW2^LYwJThF8Srp1}bPE4F9fzlW6vonz zd*tGpe7e3Nmlszzy-sIFNB4Bh$S4$&a%kP@@aZg!BzZIDvS(Ux;fMX3XwJ@qaPEDe z!+!eBDV=fXzW?yHKbJh{>zlsmbozZVkaQTZ0sohgh{<^*Vj?Gu#OfcRPaX*u$ry)o zpZH-krLqU@lBUso1Wi~>7F!&spG+2O7-bs|kHzPhSnWpwUuy-|P5uF(TbZ z^21+q`I-F#SIe)zhu-oyGpg<}>FU97A&<$o&JkCGIy)nR2kPTdGHUWu=jeOqNMHHm zSu*0@C+LuQ1DOs}J!JRi6Y|(QH}iO0r^#E@WWdLQs)vOp=`GdGI^Q$1_>o5Oga%}q z{EiE=mp*$kiOH13diK)^3nPz3W^%850yFNjhy+ZGVRm^8f5l2VRH*T+N0(y+2N*>~Xqpb3CJ1NfYYx*N2$LetR(Xb^a~V9KX` zo!EnBV(nwC^9nWlVf4ZE=)-ytwSrLcrbA7q;2=W~IYF950Zou3WQ$?Tmj=C`g)Oak zYXxVZ5wd|1V(~qjlMjX(9Sb!YCAUboT-8%aI_9M39|spn*u4b_5!~C`)!v>RaOJAA zW{=pltvy^N8?2Iluvf|v$VN<+yPn%LO>u}@{`=nYUjv6$@Iv0>cGC`cnt!wb&<0T1 zNjuE%c@DN#=sB+cP1k>m6V=>BR*N_(jk#|lNwE4ZI#Xx>Iek17H{m@Km=)k&R)D4+ z3+!4!Kr2H7khh({e$8GiIYV|ua4h`A!Cpsf|OgLY2?yXOOs_Z#@Q zUO<5f20dJ?b6AIkRjYlp(8q2%R02%i6APgB1!%O_I|kO%}AZ zLd$XOZ@l(fywB#u1IZ_ZlXqt%q5>*OGc}M`UaSi#tBE5Y7J+uR{0=-vD0joG1IMxs z68f+p#~~7_hGflXLRre3 zn_Eh8*9!7Lv*ZP4iN%3!PDU7S|Kx1LY z#zHCXTA}^uaX0X|i*T^`V$D77>e#+cCD?o?p!x<_TyX$NPBp;S3P#%M213nk2#fP_ zC?ys-=LHiZafFF5&IIu84_>;NA5L|U(L5u zrp~3vp2o2Gc@ZeNNz23Zul<8VqMyrQ{?s0#_vHcN)t(B0n z`8ihPIm}K8^2`7&shXE5%4^y+mh_4|@QeNA2VgOaR@3~X3y#H#N&&Gs`#ej)HTO}Z z)+i}F*ATP9T|Fnqh-roREU_3I8C7*40$c;2MQtyf`D7l(!aHU%G}w!nJrDvgGSfB# zz9&CDpbXE}GDn_m;cP9VCPmIL&@&q509|a(1?U*P%rV+Z)ENB`_x%uypvwus%~UN5 ZsbQQESm&lM{K=Cnw7}O%_zu-F%I`gApvy$>{I~J%=}ObU;xMPQDN7?eSm&j0%$(vD@}t+BHV4FEDbXW>~5fE>?Xfb6Pz5WV?H^6i+8fOY6?^n9&cQO NDuFwHv!=!zIRH@>X5#<= diff --git a/container/grpc/types.pb.go b/container/grpc/types.pb.go index 0cd53eb0f167fe4e103aefa3271e1b3717f66bb1..9634ff7d34b6bd964245e93175ca76b3552e787f 100644 GIT binary patch delta 41 rcmZ3Jxh8W$u$-}ho&lG>z5-`KQGQ8&vH}#88S5Du>6vUSv^D_%|3wQz delta 41 rcmZ3Jxh8W$u$+;Fo*|dMz5-`KQGQ8&vH}#88S5Dt>RE0qv^D_%0CNjZ diff --git a/container/grpc/types_frostfs.pb.go b/container/grpc/types_frostfs.pb.go new file mode 100644 index 0000000000000000000000000000000000000000..bc7e62bd9509ee1cc665b0ef5d6a25af60213874 GIT binary patch literal 2659 zcmeHHO;6iE5Ix7gV#LX5iQPim15yrr^boZrs8B8lRcm{ktk~>EyX!as@!vbUwsB$t zqE%IKs1(VuJ@0vT=DiokaI7+f2};z=Vg|_y=2}^m4(Qonq6WEE#^xr1lQEo*FW~dZ z=pqV&IZJQY1R+(@GEV3q;Ip~X7Ir4wMh%L~T*Vi?=#+`ptmNInl?9y|}Pk z#Qvi@K@i7qZdoGmoZlj7w1t)i>=ePc2P%gpa9Q=36glKd&zOw}S3z}=5(EvD+)gVT zn<3;JMFtBd3VJnV3v6E{Tr$1#^ihx(GKFvnZ;qRD{XDc*^Q5rYU+XOFL+Bgg()Qsl z=yBKBa0rqMciXEvhj&5mKIr+%x5KLI=$!cE#GNmEzYELg3$FUl)a<#MOV>G7)wGT< zxL=#rH>S;$37Az^)0t9z#%fsAXpEn7Js71k)Xfk_InZQt)F4n!Xo}p>KjXH*B=yqn zC+zQn#Ih-;Iwpilosb%`@AU?mTmfpWG@wjXAuVcBTRG+F6f&NHRMvw_C^fe`N%D@O`r5`!+e!QBmc)Gd=XDpDsI52vmirA68FL<{&+l{9jDiB9UBgifYc z*U8E$sJcEQn5y88L_@KI%HPtKZ!oMXojBGPLK-39f@!i!ZqSlhY|yL!cO=*} zNGc@WtE%YWy4B?KFcM}L){!Z_-cYI2{KnF}G5)=$|CW~RUI+I)5BCyA?X!391KA- zNol=|9@5PCnA#-T*4{_Q*rKlZHPJrGv~9>w4tXY6iZhh>cw%GZFWaQ~C*^>^ZLQ4N%*4c*J literal 0 HcmV?d00001 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 958476c73e5f17064810f0b1b36b2d0a18cd15c4..ed902b264df54e91247c05c871920b2333bf4288 100644 GIT binary patch delta 41 qcmZqIZP%R;EN5(>XTYVeufSPQlwXpctN;aN#(IWEdL|nS#l!&N1qwX? delta 41 qcmZqIZP%R;EN5h)XUL_mufSPQlwXpctN;aN#(GAEdX^gt#l!&OBnnCZ diff --git a/lock/grpc/types_frostfs.pb.go b/lock/grpc/types_frostfs.pb.go new file mode 100644 index 0000000000000000000000000000000000000000..267de94f58e78e77cc71564cd5b1257216055219 GIT binary patch literal 1091 zcmb7@&2HN;5QNX>Q!H|l8e3|64B%7JLx3a(YTpbWC}}AXrbvUNEW1J8y-QK5-J(fR zK!AR@vmDNT%5%6k6+(>~E%#VKafX96-joaawy4cQSmV5K89c1uWwn8C509ISu>&vn zyhc!_+%qQIgRvfNYU#5{Ahj_0#&&qGOjkYeA|F>4{2-}we*BtuUaEZ9?}o8FhqdR0 z!nOQ?V9|G0JMayH3m=St6G$EH6`cTKY|DK{x+t|>NfLC>OW#BtZxMt4}b%URg;}NCpQ|`xIW;Oa>>*C1|O_>nvJ@&usR_X5XnrrNjAeWQ>*xi`X>KGRVnQXz5W;o_^*0|A0)S{S}dM2uVP4yDQEf)A9ZRE3xpE zc%h4U3gRoGhF2Qv9+OxZsJNa$ 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 acfe43c41c18da00dda38033bfff90758005e225..a932e0e9364bcca7eb15f022ad8611f568389eae 100644 GIT binary patch delta 43 tcmX^3oax|mrU}7v#s+!@T>AP7oCQVsCHct;P*7&9XK18nvav8=GXOG)4FCWD delta 43 tcmX^3oax|mrU}7vMizR8T>AP7oCQVsCHct;P*7&9XJn{nxv?-{GXOKF4GjPQ diff --git a/netmap/grpc/service_frostfs.pb.go b/netmap/grpc/service_frostfs.pb.go new file mode 100644 index 0000000000000000000000000000000000000000..aaaab81edcebfa979075d4797807ab8decfb4af0 GIT binary patch literal 12073 zcmeHN-%r~x5Poj{iW5)mMw|V3o5agt(vYA?fcApW&Aog1e3{-_lFSi2!zzR@B}7`Yc2-4aU-S~^yO%rpvGisCWRAn zq?+&)cPp+fmP~%NlNxvD;&g) z#hq&i+?QiENB74)8*iO11p!9)E-;!lKkpK(^1uihPmlg$MjxYQKamk^Tg%9NH8Q_Y z@pyVKRoLFVuwr~4OKTKM4t9&f=n>Ae@penRNq;oP#9)b8^RGmiSJ<>84M@uDM$jU` zYo;h?#3^dZ8aikc|38Lkw^9N%z2L%*{&rb{_>vP4&gUnnpnl0|2>SEW)CU5Ms>Fc_ z%?iclq4~eEXF8T5#aE`!r^zL!BC=1)rC5qtayD{Fo+Lc0tapa4!I6tt3V@mvy&>E( z!|am0P(v>dVY~^P;8KL)tLN>em!t!~Gx59pN+oAG#Nlo$=%c{+%emt{ZB4qUCsJMc zvL3dztbfA8i$i`ri~5HuIRf*E(;naXQ#B#a1vyNy!-o*Q~lOtTsweOj4WzU=<{s|{94*a#PuODjV^QX_B=KjnIZ=lphlf&KOK=M_# zmh%@({O@SOk21jvnH4?s z@e&O$Z_wGt^P66h%yD{;Cj>DfXLz0@bT;QgqBj#Nd)9=qjQ4LuNd`GD$A98czxw6~ z&nfusKOFZQ!pU~T2MJPc6dfmMoB(K4>&L3t0{gU^;aXxuvlsLy(BAHiaJa5(A>0P}_PDd`UCz6$b&U(YQ@;LEJBL+pyAVb1PmsV2Qn&1x zeHMBHZp=ec02;uNxug23zbRjp$t}GDhp^RZ-^x1q(a7Kh7R40jXl8yFUgoO%ZW3tH zRp`uD$>L&6giY*uh9KJ+5hy2Y0-2=+{8cDqU=BLWUG(?ug0l@u{MXOluJpNjcI+KpN?EhfeqNL($GCZa`gsgv8#Hj#;U2(aeEC#se0>*sLH@fi*d({`P2L0|aJ(-&?cj{he}I@npLl zkj1w%)bY&}dF;i2KdzC>Cg0TX$r=NtT;m-H=6m%hX59nJeD@nT2g@AFDUvz})RcZT z(Yz)(NhN<>+5B>@bWqEamd$};a!U|H!a2xsS&+xY^MeHW9+g0xEt1`kMp(Aj#K<(! zho}liu2_J1m#|4UMP@9wsq`?)?-R@^bzO>k=%`>)ABy8VuCPP}Ns8 zU9pa)wa2IRkh&lB>sfb)r<~_n-E>j)h0(ut^SUppA}gvk&?X{{Yhl%LOAkDJA=}W8 z1*FirS(Czd<%(%Q69@cRto5(6A>>wj`(z^Tc%eWm>~q`qq}XjC5-9k5x<__Y3}IM$ z4pYsqbyfQx4GBZ@KT~Vhm7ksKx%vs{Bx>N*Sgp1E3JW;nin^FqX3hYi%FBLc_u4bN z&9JgmiLhdHJHLQThUajuSwI^ts(s~facyr*K9L!{1T^X?jPWnBd(jpkk?*WIy=zrtn|KwQ9_mNP7Ft@C z{>9T)ReS&bu9m~IIZvk{VN;miRnxRgYJ;_$?fcQl`q7~SBdY)rDwIK}4KN^4J3!Xg zfeoS(kggz#<5PqM7x&O5XLRxv>N$90;ssyG@Cv3-sZ=k~)VDS1p7imNej8FO$s$yN z$Lf@D_vBaw*zEx|W?n!4z;E>^YlYbLJU5M!)s=d>z2|q#{I-aRh}DllamRByPz2PN z_Djw0K}|eHBpALRJlYI+*xzm+s0ds-_~x1r_Vxs3 XsSZPYV~-=&O=}JTuX2V-W0dS4LNciO literal 0 HcmV?d00001 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 c6ffb2080157494425159a11f163e5813a0c56cc..4012a071a26c4e7a34e37e9911f490cd20a6d09d 100644 GIT binary patch delta 23 ecmezLk>k@xjtRLehDLfOjfJg+j9Uwt8Z7{Un+azC delta 23 ecmezLk>k@xjtRLeMuvKpjfJg+j9Uwt8Z7{U(+O+< diff --git a/object/grpc/service_frostfs.pb.go b/object/grpc/service_frostfs.pb.go new file mode 100644 index 0000000000000000000000000000000000000000..5abe6f9baef2601c5adc011f4e36c8e120f98596 GIT binary patch literal 41864 zcmeHQU31&G6@9jT1!kY*){)v|rw`llL*s0_o+j~*<+cx*jE9mSi!}|ZBos@V+5g@P zfLA0wD3P|9Kr&`BZ9VO}bzjVTTz4&2~W}N(R7xMu&iP%a6t}i?X%s ze$bmO*@X00C4H)jGvOPy^~l>>inFrI1#^|s9BRg z^-g~8oyaTyc&=tV_y`@+>4+E86koFc=QFYz{B1ggS?8x_gSTm#$g5t9tFEI*xT5G^ z^xXTsa?3tMSw4>v@}Pd^#;q#8sJdh7{^asj7k4MkrZmGlc{w9+duKEw31xS1E8`sg zmy1UcF_=mDkou=*gwaR59IlI!B%KH-VQ1IHV~p6E&@4+cLfIr;GEOtV+v7Z*%*iyK z5|(n=_>nwjF^}1ud`i=ZM`V&dEE39TvKF0^D?mi{80Yj%!$>h@0Ep^T;6^rwS&1$= zWjLqJGiVPL#M~~h6wjkCaQf-gu09>%cVo5YWVifKIcahE@1bgQ|eE z_T&VZzlU{qZrGANOsjU$fHd$Alt;hN2n^9;0#}I!asJN2K>~h+O zOCL>=5}%!~Pw z-Peuz7KC^%M*=XYk<|518fvsiVtxs3ZryOk3sDXX_)!Cwt>xfByZNZyDriQt@rXU2 zX^#yV&+-iSY@+5gq>#!ZV-xx;{Z^v%9Ipj0E@Zbo0<_H_l7GaCl=z*Yno;{ePQ{(+T z*9|sq#L<}6xz!M-ydqNY9BHB@`S>3r!x_JE z(uZ-*Qzo`f2N~e03~&JADA>UPKF=Znx=98p0138Y(JUloc9oRr2Ha6td(Z+cw17y= z_)gJ)T-&3jr*eOYVs^!nwUubKxlCqPX<4+QKP`>6Ky%3W{?-}ab)Y&5dMSen=7Qyp zlMvfJX0=}XB}iqkS(GTMu)W|9B4ZVQVE)+rDmbof1rd-nVi~nvbX@A zwjo`XCNM=TsY2vjbj^gUkEWSl@Y2}i*c z`*84#!uIxNmY{*!pgP<=b8zivzAq-J)iM_;Vu+NOd zqS#p$F{pUG8Yte&8&))v%u_V^6n};e!9fl&GtXjX^=L%91oJuEdaXM0O(s#;$1mz2 zpoYd^_G=g-4&b1w8vF2>vN~t0kka(hQ<^kVLcF0B9W)<>1;G{zf(V1XECyI==5qQz z&Ur&IBSS)}MbI+7mVVxX7mvte8xR``3CrDD4cyrDR7dDBH5tnY)i{e&eZm~%QwPn{L7CRvW04!^2i}8P+Pf7 z23Fq7Bc(zV*1ssMh7OOEf@zcrQ8+<|2-qNTdrL>4!vv>i_A3si6DC|;hS`@n8^M~= zuFD{HnW>*I=G`NEfJd|KIxxs)lep?4gAim8WstFPf zg`j2g_)RRGb4rM9zVz6p@hU^aq1hcY$%N=;i|A$vguTQ!?H!ept}6#rsrOrDFtZS^ zE_2Egqd;k@U4mOrjM_b1dG6C@3#C4!@hXy14BkWAwkV1Y!ge_yw##kBvq$u{2Sc$0 zkT_fozoO-rb!9u|EDYl$a&qByp?0=QnX+k1|3L0Hi&@gE%2sFhrFE40} zNcbhnwf(<{2q{mxShp&Db!)9qimawP@XDZ6zFD-^1y`x@DdvO3mqlkm;}9o#>2Z=e$Q=c31by-}ed6$O+fz_j z=J9Nqr()`k2fW?jy?O72$x&Rq|Ijv*Moi)s?cGG>^s!RfG(Z7#a#+uu#UZCTOeVnoV9-K=3fCy!{`~ Ci=K`E literal 0 HcmV?d00001 diff --git a/object/grpc/service_grpc.pb.go b/object/grpc/service_grpc.pb.go index 3c71ec85b96cd8c032e75bc60f08506a82515cdc..ebf233bcd6155b6b6c623acbe0bed94093fc3150 100644 GIT binary patch delta 1946 zcmaF9f@$SarU|tyhDLfO8ykJt8MP)~U{{&!q9rtWUY6Ws!$6P8%vyqAQIW~@%Hlv7 z^U2NG5|ddt(ceAUd(MenMv1nvZJoTa-86d6jUJV)!|kz)G@|k*&cTtg#`a{U_5!cBmkKKiIq9|i76h5#Tf|- ziNGj@iTI@ErI!H3^3#CAu%zM}8XN*jCB>;FlMnJ)V@cwuX^$#NeDa+V?#VK4ahu~! zYDLkKI&HJ@GCw0aW#h?HLf@fz4K*YOO)lQt5?O&QvBC-*5_0h7l(-0dMiG;H%aTg4 o89~q7dn98%IZhxa_wr5VuX36ElZSV*ou2K`%gLMXlyu7j00L2`aR2}S delta 1998 zcmZ3vl zNQz9Jz#%?aD9duPl9truZyafpqd0>n7iuLjDol0^)0k|;r3qx+(>DZ?d>+;1-}HhF%63e@F=3dr&CR$)0V zl&?)QnY=zt2kIi!6k?%%ivkz9qPS+h zwk?Wl@Yp-qOLxy?7e56S-_YQY$+^7Z${>b9QmR6JQb}TFUTO-Eot9ses*n&68ln*F z>F4g_I(fdI+GNHkwaI(W2%sp8}LSnO(@nKOcDSJS&_-tRJ0n6f( zqeI?d2?zAZASs7$J`_=fD@DSJ4Qk}<<*~+utRW$1PkyVwzPT|m7nhL(l)ERTQ&Qeg UlDqjP*XQ;Pxg5S(uDDws0K}JMssI20 diff --git a/object/grpc/types.pb.go b/object/grpc/types.pb.go index 5c79080517863a2fc92f817c9395fc7c73b3a415..39cd2ed654d23516cde61a982a61b52de291b17c 100644 GIT binary patch delta 17 ZcmdmRh-t$irU|($hDLfO8w>X@002Q+2QUBt delta 17 ZcmdmRh-t$irU|($MuvKp8w>X@002RB2Q>fy diff --git a/object/grpc/types_frostfs.pb.go b/object/grpc/types_frostfs.pb.go new file mode 100644 index 0000000000000000000000000000000000000000..708fd57c9b78b519df1c0a4d3c545d64d023ab89 GIT binary patch literal 8771 zcmeHMTW{Mo6n?gT1<@yaOYA1SY%7q5Ee()hSrg1&UxHwuEz0I1lLkfE@rwTU9+ILZ zQdBArO`!os0_5UzJ{?Nu`_4t95jy8FL36^0z>>shxE>(fy#X*$wZd=W*X5gJQ8P05)4OOPNk7c4_^K~Sdt!4vd|C^G?0^8_VaEU_Gd zpK%rW3|vTtHdHQ*A6^oaP?E-Ijnf=HTHrM)Kblg8#a6=)qaptCc?XsZ6~nTXNLsP{SQY0DqaOtixfB!k;KmPLr_fc=vr z^f>%TL`FFq_zr(vG5PkjwmVgJ=Yn7fh8HV7Thy#W@UN8H%?6(ARa|qpVEIymzdnLn zDqo%U!B#)Z$#z8sHTz09Zxrq=-liPK*M!YwyKvrC+%9p}&gm!Rbjg?SB~}YMD;$d( zt!{Djxso@3V393wik9YQ=H*NAv`yNWB*}EX6)D06JaL;&R|$d~ONcr{=g#AwEstCUERZWSoH0a}O+&B&2MlpmQ8 zh*Y^9^@`t{$Y>)4KEeg=jP<*FgLH_<# zNa9!2?_^uk>xzvoA0Jiq1FM5_c1$^&lEl&)a=L5sX>!X3 z7*I`<-*bwSe@Oms)A1-Gg0>f`Ee()!%d zdkCb~JpTsGL#C~D6R978?r9Hd)=f2YNMePegG%P{$wnHGv>hRRRcn9<$XkV@EkOdk zV4b!tv1;w%o=k3enLq22?Qpl_`4y_1#U*=s^Mi+o*Gbx}CyOkx_I|Gl); z;`-#mpt1naWxyYA+?XoX&$TYtZ7^U$2#-2$NTCz|99}Pc-SHPac)~USHZl|bK-B)G zRta~Ff7Y@Vp1f4BrCUQe44vdePXb1F4_$ue_9N~x(Q4iQx+0cxy1DW^mWV+!UYJFH-8iA12o)?K%Fa)8ulaAT~BQ(5*EOgp@0fPCOUhs z`ii9`76_w{HQrAqTV6a<)Yaw0xeJ!o|9@Tr$i0XKy;pWdbh{ytLL0gzh@_ z8!2_qu^T4c!ds4g#o(!5IY6a7jC~y&``l!-f)9-8+Um;7S{rGA{guRTsUd;-R^>uV zlt6Xc(Zh#u2B$!6D+)@4J59R$; z`sEafBEb$XB)|I$NwucEs-%{sdIv?xp>aTp%Ke8g01a{$P@+m^w*(0Yk(=yBOuhgI CMyo;q literal 0 HcmV?d00001 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 f16583be011e0011556868b8ec61a9fbff9f637f..7db06b0535a875a52372c3b31ce1063a3892451c 100644 GIT binary patch delta 43 tcmaESh4Jwf#tFf4#s+!@T>AP7oCQVsCHct;P*7&9XK18nva#?}CIC1$4Rini delta 43 tcmaESh4Jwf#tFf4MizR8T>AP7oCQVsCHct;P*7&9XJn{nxv}t5CIC5B4S@gv diff --git a/refs/grpc/types_frostfs.pb.go b/refs/grpc/types_frostfs.pb.go new file mode 100644 index 0000000000000000000000000000000000000000..89de41487dbed778e39f3d8ceac15b54703035bf GIT binary patch literal 7706 zcmeI1-*4J55XYa%UvcUaY(TbF+SEyX*k~uAtwk!VFI68*asju&Mz#ZGRsZ*$orE8O zZk@!oOpSyDA$QJk_xajqg8X2_cyVgjyA|LOd^P+nlRHQztmMF0lA=tIXC0f zk4+FFj&TSx7AJIT%x1W{HROV+g&V%@MTrQYeh;rch9Qlj8*9wf8#wqdLu<;zHL+jKV z-eO>!NA^tnH1BaOedkQ+F^gf6zUxBTvLBshFU^&9Y0okxRfsCjYBvH(b%Y9H6eCJ2 z*Yru-vM@p6tO{0dG(q4zHzzw5$1<=`<%3;jC1qj(sFYNIB9MtNsEEAzmSqviF}5lo~z|Mf4)dtn(UY?vg5dhxOFbGO=C+B8ePlOp#t9 zjfNCsyju48DJJts2}^pwb!z?LW*gFHjzgpt$JyqVEH<#U!q}*ylhI#OeHP&9zGVN2 z>aAB|zq0cW6{iwy$wXVMd#(kmw34aTA(h9sL#qYGN+z(?a#v~Wg)NLbN}pp~$!yQv zYj18l%1UA{Ok#zySMvHpo5L$qnoF^-F7aDen4`m0n|RJ{rP|sJu35QF;5ir0s%j=n z)=U=YD6tAtr1AiFG?O`r#Vy~a5$MvmEES zAe1Q`YsX1Xf?d{0;_`Fn-SPY5e?C`K3w_BJ`lbF0gyiVIv}qs%v}8K&j4`;=$z)&p zT`tnpFXeODU@>(|v^%X{9gRf)%iEVD0coYYr(Y|bfovN%Xe z!;8cnxfexA0wcr51&;Vn1cjzlLW7yoIrayc!wR_Y8IH>wa;av_^vTb=sxl=P)Uf1c z>iyUZA?H|RuwX?=m!@oi50}PVFjcwm{U|R*3h@eF9V?`2T;LCKFyD`4R(01Bi@OlJ ze7G=OxQ#m8=5=@of*1B{$0rVNqRw5^ah9(SebW7N3W(Xr)S24*jNk6Vsy|#(3kF%Y z>F{+R%!l{R?!eleuI8LtMKveW`XGBmbhlQ%Gp6*E6)^Mfx>2_JrhWB%t+Xq9T`8$D zRH3Sa9H`VeDkxA)sH|MmCvDrp1SRy)u(-Pq0++#@>{wCA)N&PqUDPdQq5@P(DnOCS zQW#VO-*U>+DP%kYA&qlh!cuX=#l&?iV}?O0XY&FL7L^SOL!v`1xyJnsUh0$y79Z3y zUvxm?AGspAjliu5=HbP%B=GmXYMOC`37Te zX#rX92O&a^3#Mpva*c+D$3&g_^J7egObJUm;L2NnyxxSg8N*{5T#3}CYa6#@vw^Lp ze4~pN?Ef_N&pz-@RhrY@CJ%1x&(N?>$Y?HqQ;0U7ceY#KQ1QIF_u7fYHj72zEsT(z z?H8*PHQP;*XpkCiwM8v9aDQSLV!kOl?Gv!2vZLoxX#A(!#u5F^Xtz7K9iwHvc(8CX zGxF=)XRLPH#rAF&Eu@55+CtfIh=u%GmI_B@bH+EES_GmE)UBTDpzm%PpW^{yw@>UI aKKxUwmxlmcn7l1ihDY{+7L9lb3&k(-`Q$bL literal 0 HcmV?d00001 diff --git a/session/grpc/service_grpc.pb.go b/session/grpc/service_grpc.pb.go index 32793fe612f549ab23a1141b45a32904c5e57496..a39bf63bd03183c6ee52a4ade7e280d522b14c73 100644 GIT binary patch delta 15 WcmeBC=uwzZ%VKDxXR@)en;!ruKLq;# delta 15 WcmeBC=uwzZ%VK1xXSuPln;!ruSp@(9 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 25e07157a6b6621d094cce2e596a10d6f6855494..fba44f1902a0695ba62e31257a9b668cef19f210 100644 GIT binary patch delta 43 tcmZqJ$K0@wc|x$9v4Nfem%hFNXF*YZNq({d6qFh385-%CY%J`*2LKUu4441_ delta 43 tcmZqJ$K0@wc|x$9k%gWim%hFNXF*YZNq({d6qFh385!zXZY=D-2LKY345a`7 diff --git a/session/grpc/types_frostfs.pb.go b/session/grpc/types_frostfs.pb.go new file mode 100644 index 0000000000000000000000000000000000000000..9ff4f5dedd371d2cc65de13075d9965a434f5e80 GIT binary patch literal 14095 zcmeHOQE%He5Ppt+1<@zFOXMx-x}if}k_K3?CI%9(8xRBmEmJlZne-?swp;YS??{Ta zMA5O_WSbfY2oT5S9Z$UP`*=q>y&gK{BZ9_+5rHKcq2UtE1eZKIfcFl@{2&%Qm2n!P z_kDEPAE2}M=Yuc^W;nXXV}eqWrj)ZFpwk%_61^Hz8Co04V%{5wjGQJs8-2jTUjE4e zo>6e#dpPW6k|sSp<*Oj*_0YA%!-QPZPXq}fGr>|MCoqqCgU4urC^Hcbvlzu(OtB2X z&X|fU0uz#=Ih7M*ho=O^lq4hcfRhY9n&1br{%A-U7EA3u4C0JMsIx$?`@_FTB(Kf0 zopL70Lf#Fq7!%noMA+$~jt-16c>i;-M^%8w$B5BH{kdnJ0DT|qeF^sT$nTC#^x-8* zVZEu;dq5q!XN=srj8cOPw#2S#h(zsZLeCx?GHiu$efI5u_(30wsivAr&-*SE))R zW)Ral$(`;#Vq|WI!#JEIJW^P+&aQG8V75d=2v`!rBA!7~1ORqEq0t15=m;?`wecLy z1(lSIb(Tk1VifV|EFqF4OXU>x0a0R3Q?g&eSROI}%s5rJ)8-JBaw!S3F|G2pJJc*@ zcL7_Tn~uW#&Fye0NjLxf2zutsn8!12;Cb%)9-`(y6?3z;my4@)@U>$~)psvVP%Dkr1|Eey}B`aqvo2tiC zS_1hxI_xaMk3(*!*e!J)xecPy7?klQrA_pvfr0VpK~Xj!HUyu8i7pqG9F47MxikzBHXs zsJ74MsSFA*ucR1ye+R!(=8`mjS;g?Cyk*mUsH)2O1Mer%*Q*OT4ddUw%Jl z^6eWfBf4ujTg)m7QW&EPi_2mB*cdG?=UBF)(!3s}CaNp}8z?RYj5feZ8L|isf?aVa zn|XxAfckMWkCc>f-gF6hF3~uF#x-4QhE~y3^S%U6BmrNNv@3c3xL0V7krjFKVzl?b-e)KdPn-{O5-J(tFPn znrtUy>#a-`+LhYYH(D3M*L2LVx~OPN-Da1%7B^O&0OCzMTysEXBlYNTj?tRb_b9Ok zwhiO_pT80e*HAWXPo+ED^1wCHn&oB_NJ|xKVT|VXM|I2C^16AvcCcZI(m+ZZNZ9~A zOg1=liCi}G@YjK6!?=4z{)X#$c|jz8UKTqFxu!GRi>dD}RQ7H6-0Ez`qltIa(V_OH z8_t1DU`*x4K8Ic1D|_9OTAS6KeOYpR4+KRc+}@gARv-9P;`LcUeYXft2o^-tH~L8# z^#vW%N0;trHS7Y9X>^%Qhx+Rb?Oj2`?g}@x%E`fQr>5H zbZF=FbeeTkz;(Lei9F3{MHp(js8kXUlPk-8ik+oeY#8G^X%XR_HPQqmD)$@f1&KwhN^`vrwDTZf3gU zF`3-WQ1>@02(-f7IAPub-4~(HE=_7Gk>^OoWll{`p2nd{rkcJyZGy|M#_6Nk{ab 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<AP7oCQVsCHct;P*7&9XK18nvazr}1OP4A46pzI delta 43 tcmeyclJUbz#tFf4MizR8T>AP7oCQVsCHct;P*7&9XJn{nxv{W51OP7g47~sV diff --git a/status/grpc/types_frostfs.pb.go b/status/grpc/types_frostfs.pb.go new file mode 100644 index 0000000000000000000000000000000000000000..89f5e6ebd564d41fb067b4c3ed2f1bf17d6bc225 GIT binary patch literal 2253 zcmeH{O>5gg5QfjzuNZQY+gNIyTfmnlJs6q<8aEdc%1Rp9OV+z)cjS+T{P)i8N{OSk zp%hwLC>Uf(^N!w~d1mq)&P;`{K#f)qR#5C=Z4H@n#Lq?xGpem|RJ#n$ui)}(2Jg?O zvn)y0qP!Ce1V@4zmn3qvHkROMAt~!5Qr9M**#^&)X{ryR$lEs~v6h@W-;DEyq{_n= zkCG(M;hIFD@LGOBut<&74rs}r@efQ5JCHgWESef>V^@MQ)V5B2#RNk}z3@RSZA4OXP4A>1be=`Bqr zpr!J+gXkIFB!h=!5F%esqTlS(RMW}WpDcZQ47+Sv4f`SQ_Jl4(jD5t7cg#U;QlBn) zIH=Nvux=?7tm4)6s?(k=7Acm5yT#RQ3u0`AwkzJW2Cit078L3QS5G?r=X~{rW-m{D zNr%UvaodG+oKVV?o}Mn*$F_4q?*Xkf7EqU_(S()}+b(6fgi2PR4F&NQwpNnVi_n-# zkbu&x)(Q#L-Y11ChQMy6!{cXIw3eBPnAD>Zq*b-afL}R|Oh75d+y5_3-4^&*=0VKWmof_fOC8?;2jeHNP2OMvNJLn%@haAKsB1 z#{_|d(+OCid1>ylxLRD;8KEwZy}Crllk`Yy$adm;)Jo>^Ha7kLR`@HoLPuOTIDUlx lwROz5-`KQGQ8&vH}#88S5Du>6vUS%wre#O)SbzO;JcJR!B)L cC`wIEECKQ|^Cs5FZGOoRE0q%wy+r$ydnBFHtBhPTefR NF^v_Of1fu<6aWp673cr} diff --git a/storagegroup/grpc/types_frostfs.pb.go b/storagegroup/grpc/types_frostfs.pb.go new file mode 100644 index 0000000000000000000000000000000000000000..2b0356b3056877c66a6bbd3880e9cb1b41a7b0ef GIT binary patch literal 1482 zcmb7DO;6iE6gf61%0S2c(<;wMYe|ChY}rSliF`ip{RI`<#y={yT5Ic1hfV zgcQlK{bqKaXC_VI+!P2EYP5o|fNTeiHDvM`Kbuu%R$AkzbO~JC!p-dxE-$W@Nfb3A ze-IUdBV+kmS<^OABv*~G1V@#mWB^KCnsjMfJXfYIeuymX-^@fK`Gj91ri3j>9b{&038k?sK?&mm)V4W8(7{Gh9dKfWP)bw< ztc7a%RV~)|@+y;B*j-1TL}jaUh_~=z5mx)=SDWrhil-2FN~ESKJVq1g70u_MrSi9v zAQ?VIlc#9XO@5pQxyi39OO?8zba zyKwbCxV@vk`0>kaBiUm<>asDppXUz;63*seg=QZ_vq+p&&z9JT`d%>!qtsD>>UVJ2IE|pf!;P_3$%m9S0%9TC0bCZEB07A{^xu~ zgl0`I>4~Supm8&d^PEu1zroc7l@;v5Da*<=23z5-`KQGQ8&vH}#88S5Du>6vUS{4Nau1ceLx delta 41 rcmaE1@xo$4u$+;Fo*|dMz5-`KQGQ8&vH}#88S5Dt>RE0q{4Nau1*8lJ diff --git a/tombstone/grpc/types_frostfs.pb.go b/tombstone/grpc/types_frostfs.pb.go new file mode 100644 index 0000000000000000000000000000000000000000..bc9086bce8080d49fe65bb7d11e155b088a01097 GIT binary patch literal 1318 zcmb7@%Wm5+5JlJ4R}8X}+gR!gT?Fu^Nfrj01gPCrkOd`;EFu&skRv}DH%?TjTj+e*sDE~#siZ)}g3%JkKDQRKs)h3F*9=etjNPg3P!(X%AU zb6Aro6t3kj1dG&L?SL8t=RcSl4j^^(SoAg2#?Jj^PqYZNL{-5~ zsGff{V#mh4r2kb&E$lJKXGz`b64C>_+l>2~pZH1VkOmu4(;S|Xne=v+OVCpJ*ID!n zAClQ~G7FXOm(gqXbEWC)7r(3Y<2f9%>q94b>nL2XM%4ur1KKVBqzdx9B+2H4Q@vYM;H@&~h&ySdgs_zI}J{d=kQqu&xmb z+IV-9;SZyW8N`XZ5Z*9vV=J^{Hme#quo^8W)LRZmI(~9KT%r9AUt&+^=b&*vmUEp@ z%9NhZQS8S6hR{bqYk4H7OVevY%MkAySvF9~3bdinyobG&B=t7rUI`LVnzmC&sE%F~ z?idKWmk!TgQ8!p-)ywri-$j>K9vZt ej|$BDRN)`#pUO`79~a;wFkRq{1Hol{9)1JVIlU7A literal 0 HcmV?d00001 diff --git a/tombstone/json.go b/tombstone/json.go deleted file mode 100644 index 05d959e..0000000 --- a/tombstone/json.go +++ /dev/null @@ -1,14 +0,0 @@ -package tombstone - -import ( - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message" - tombstone "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/tombstone/grpc" -) - -func (s *Tombstone) MarshalJSON() ([]byte, error) { - return message.MarshalJSON(s) -} - -func (s *Tombstone) UnmarshalJSON(data []byte) error { - return message.UnmarshalJSON(s, data, new(tombstone.Tombstone)) -} diff --git a/tombstone/marshal.go b/tombstone/marshal.go deleted file mode 100644 index ae4405c..0000000 --- a/tombstone/marshal.go +++ /dev/null @@ -1,56 +0,0 @@ -package tombstone - -import ( - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message" - tombstone "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/tombstone/grpc" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/util/proto" -) - -const ( - expFNum = 1 - splitIDFNum = 2 - membersFNum = 3 -) - -// StableMarshal marshals unified tombstone message in a protobuf -// compatible way without field order shuffle. -func (s *Tombstone) StableMarshal(buf []byte) []byte { - if s == nil { - return []byte{} - } - - if buf == nil { - buf = make([]byte, s.StableSize()) - } - - var offset int - - offset += proto.UInt64Marshal(expFNum, buf[offset:], s.exp) - offset += proto.BytesMarshal(splitIDFNum, buf[offset:], s.splitID) - - for i := range s.members { - offset += proto.NestedStructureMarshal(membersFNum, buf[offset:], &s.members[i]) - } - - return buf -} - -// StableSize returns size of tombstone message marshalled by StableMarshal function. -func (s *Tombstone) StableSize() (size int) { - if s == nil { - return 0 - } - - size += proto.UInt64Size(expFNum, s.exp) - size += proto.BytesSize(splitIDFNum, s.splitID) - for i := range s.members { - size += proto.NestedStructureSize(membersFNum, &s.members[i]) - } - - return size -} - -// Unmarshal unmarshal tombstone message from its binary representation. -func (s *Tombstone) Unmarshal(data []byte) error { - return message.Unmarshal(s, data, new(tombstone.Tombstone)) -} diff --git a/tombstone/message_test.go b/tombstone/message_test.go index 7528c73..1d37e81 100644 --- a/tombstone/message_test.go +++ b/tombstone/message_test.go @@ -3,13 +3,13 @@ package tombstone_test import ( "testing" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message" messagetest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message/test" tombstonetest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/tombstone/test" + "google.golang.org/protobuf/proto" ) func TestMessageConvert(t *testing.T) { messagetest.TestRPCMessage(t, - func(empty bool) message.Message { return tombstonetest.GenerateTombstone(empty) }, + func(empty bool) proto.Message { return tombstonetest.GenerateTombstone(empty) }, ) } diff --git a/tombstone/test/generate.go b/tombstone/test/generate.go index 3caf528..00764ea 100644 --- a/tombstone/test/generate.go +++ b/tombstone/test/generate.go @@ -2,7 +2,7 @@ package tombstonetest import ( refstest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs/test" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/tombstone" + tombstone "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/tombstone/grpc" ) func GenerateTombstone(empty bool) *tombstone.Tombstone { @@ -10,7 +10,7 @@ func GenerateTombstone(empty bool) *tombstone.Tombstone { if !empty { m.SetExpirationEpoch(89) - m.SetSplitID([]byte{3, 2, 1}) + m.SetSplitId([]byte{3, 2, 1}) m.SetMembers(refstest.GenerateObjectIDs(false)) } diff --git a/tombstone/types.go b/tombstone/types.go deleted file mode 100644 index edcd934..0000000 --- a/tombstone/types.go +++ /dev/null @@ -1,57 +0,0 @@ -package tombstone - -import ( - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs" -) - -// Tombstone is a unified structure of Tombstone -// message from proto definition. -type Tombstone struct { - exp uint64 - - splitID []byte - - members []refs.ObjectID -} - -// GetExpirationEpoch returns number of tombstone expiration epoch. -func (s *Tombstone) GetExpirationEpoch() uint64 { - if s != nil { - return s.exp - } - - return 0 -} - -// SetExpirationEpoch sets number of tombstone expiration epoch. -func (s *Tombstone) SetExpirationEpoch(v uint64) { - s.exp = v -} - -// GetSplitID returns identifier of split object hierarchy. -func (s *Tombstone) GetSplitID() []byte { - if s != nil { - return s.splitID - } - - return nil -} - -// SetSplitID sets identifier of split object hierarchy. -func (s *Tombstone) SetSplitID(v []byte) { - s.splitID = v -} - -// GetMembers returns list of objects to be deleted. -func (s *Tombstone) GetMembers() []refs.ObjectID { - if s != nil { - return s.members - } - - return nil -} - -// SetMembers sets list of objects to be deleted. -func (s *Tombstone) SetMembers(v []refs.ObjectID) { - s.members = v -} diff --git a/util/proto/marshal.go b/util/proto/marshal.go index a82478b..2ac14f2 100644 --- a/util/proto/marshal.go +++ b/util/proto/marshal.go @@ -14,7 +14,7 @@ import ( ) type ( - stableMarshaller interface { + StableMarshaller interface { StableMarshal([]byte) []byte StableSize() int } @@ -302,7 +302,7 @@ func NestedStructurePrefix(field int64) (prefix uint64, ln int) { return prefix, VarUIntSize(prefix) } -func NestedStructureMarshal(field int64, buf []byte, v stableMarshaller) int { +func NestedStructureMarshal(field int64, buf []byte, v StableMarshaller) int { if v == nil || reflect.ValueOf(v).IsNil() { return 0 } @@ -317,7 +317,7 @@ func NestedStructureMarshal(field int64, buf []byte, v stableMarshaller) int { return offset + n } -func NestedStructureSize(field int64, v stableMarshaller) (size int) { +func NestedStructureSize(field int64, v StableMarshaller) (size int) { if v == nil || reflect.ValueOf(v).IsNil() { return 0 } diff --git a/util/proto/test/test.pb.go b/util/proto/test/test.pb.go index 0dfa4dc28064e4b471d35a3d873fabaf5bacb9ce..1d17e190d4fb238bab2ea88bac2fcbae0428b691 100644 GIT binary patch delta 41 rcmbQ8GdpKOu$-}ho&lG>z5-`KQGQ8&vH}#88S5Du>6vUSTxALX`@Rd7 delta 41 rcmbQ8GdpKOu$+;Fo*|dMz5-`KQGQ8&vH}#88S5Dt>RE0qTxALX{M`$q diff --git a/util/protogen/main.go b/util/protogen/main.go index 99f5b7b..7cb54ad 100644 --- a/util/protogen/main.go +++ b/util/protogen/main.go @@ -8,14 +8,18 @@ import ( "google.golang.org/protobuf/reflect/protoreflect" ) +type MethodMask int + +const ( + Signature MethodMask = 1 << iota +) + func main() { protogen.Options{}.Run(func(gen *protogen.Plugin) error { for _, f := range gen.Files { - //if !f.Generate { - // continue - //} - imp := string(f.GoImportPath) - if strings.HasSuffix(imp, "/tree") || strings.HasSuffix(imp, "/control") { + impPath := f.GoImportPath.String() + if strings.HasSuffix(impPath, "/tree") || strings.HasSuffix(impPath, "/control") || + strings.Contains(impPath, "/grpc") { generateFile(gen, f) } } @@ -25,6 +29,11 @@ func main() { // generateFile generates a *.pb.go file enforcing field-order serialization. func generateFile(gen *protogen.Plugin, file *protogen.File) *protogen.GeneratedFile { + emitMask := MethodMask(0) + if imp := string(file.GoImportPath); strings.HasSuffix(imp, "/tree") || strings.HasSuffix(imp, "/control") { + emitMask |= Signature + } + filename := file.GeneratedFilenamePrefix + "_frostfs.pb.go" g := gen.NewGeneratedFile(filename, file.GoImportPath) g.P("// Code generated by protoc-gen-go-frostfs. DO NOT EDIT.") @@ -33,32 +42,19 @@ func generateFile(gen *protogen.Plugin, file *protogen.File) *protogen.Generated g.P() g.P(`import "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/util/proto"`) - //for _, e := range file.Enums { - // g.P("type " + e.GoIdent.GoName + " int32") - // g.P("const (") - // for _, ev := range e.Values { - // g.P(ev.GoIdent.GoName, " = ", ev.Desc.Number()) - // } - // g.P(")") - //} for _, msg := range file.Messages { - emitMessage(g, msg) + emitMessage(g, msg, emitMask) } return g } -func emitMessage(g *protogen.GeneratedFile, msg *protogen.Message) { - for _, inner := range msg.Messages { - emitMessage(g, inner) - } - +func genStableSizeFunc(g *protogen.GeneratedFile, msg *protogen.Message) { fs := sortFields(msg.Fields) - - // StableSize implementation. g.P("// StableSize returns the size of x in protobuf format.") g.P("//") g.P("// Structures with the same field values have the same binary size.") g.P("func (x *", msg.GoIdent.GoName, ") StableSize() (size int) {") + g.P("if x == nil { return 0 }") if len(fs) != 0 { for _, f := range fs { if f.Desc.IsList() && marshalers[f.Desc.Kind()].RepeatedDouble { @@ -72,8 +68,10 @@ func emitMessage(g *protogen.GeneratedFile, msg *protogen.Message) { } g.P("return size") g.P("}\n") +} - // StableMarshal implementation. +func genStableMarshalFunc(g *protogen.GeneratedFile, msg *protogen.Message) { + fs := sortFields(msg.Fields) g.P("// StableMarshal marshals x in protobuf binary format with stable field order.") g.P("//") g.P("// If buffer length is less than x.StableSize(), new buffer is allocated.") @@ -93,32 +91,53 @@ func emitMessage(g *protogen.GeneratedFile, msg *protogen.Message) { } g.P("return buf") g.P("}\n") +} + +func genReadSignedDataFunc(g *protogen.GeneratedFile, msg *protogen.Message) { + g.P("// ReadSignedData fills buf with signed data of x.") + g.P("// If buffer length is less than x.SignedDataSize(), new buffer is allocated.") + g.P("//") + g.P("// Returns any error encountered which did not allow writing the data completely.") + g.P("// Otherwise, returns the buffer in which the data is written.") + g.P("//") + + g.P("func (x *", msg.GoIdent.GoName, ") ReadSignedData(buf []byte) ([]byte, error) {") + g.P("return x.GetBody().StableMarshal(buf), nil") + g.P("}\n") +} + +func genSignedDataSizeFunc(g *protogen.GeneratedFile, msg *protogen.Message) { + g.P("// SignedDataSize returns size of the request signed data in bytes.") + g.P("//") + g.P("// Structures with the same field values have the same signed data size.") + + g.P("// Structures with the same field values have the same signed data.") + g.P("func (x *", msg.GoIdent.GoName, ") SignedDataSize() int {") + g.P("return x.GetBody().StableSize()") + g.P("}\n") +} + +func genSetSignatureFunc(g *protogen.GeneratedFile, msg *protogen.Message) { + g.P("func (x *", msg.GoIdent.GoName, ") SetSignature(sig *Signature) {") + g.P("x.Signature = sig") + g.P("}\n") +} + +func emitMessage(g *protogen.GeneratedFile, msg *protogen.Message, mask MethodMask) { + for _, inner := range msg.Messages { + emitMessage(g, inner, mask) + } + + genStableSizeFunc(g, msg) + + genStableMarshalFunc(g, msg) if strings.HasSuffix(msg.GoIdent.GoName, "Request") || strings.HasSuffix(msg.GoIdent.GoName, "Response") { - // SignedDataSize implementation (only for requests and responses). - g.P("// ReadSignedData fills buf with signed data of x.") - g.P("// If buffer length is less than x.SignedDataSize(), new buffer is allocated.") - g.P("//") - g.P("// Returns any error encountered which did not allow writing the data completely.") - g.P("// Otherwise, returns the buffer in which the data is written.") - g.P("//") - g.P("// Structures with the same field values have the same signed data.") - g.P("func (x *", msg.GoIdent.GoName, ") SignedDataSize() int {") - g.P("return x.GetBody().StableSize()") - g.P("}\n") - - // ReadSignedData implementation (only for requests and responses). - g.P("// SignedDataSize returns size of the request signed data in bytes.") - g.P("//") - g.P("// Structures with the same field values have the same signed data size.") - g.P("func (x *", msg.GoIdent.GoName, ") ReadSignedData(buf []byte) ([]byte, error) {") - g.P("return x.GetBody().StableMarshal(buf), nil") - g.P("}\n") - - // Signature setters and getters. - g.P("func (x *", msg.GoIdent.GoName, ") SetSignature(sig *Signature) {") - g.P("x.Signature = sig") - g.P("}\n") + if mask&Signature != 0 { + genReadSignedDataFunc(g, msg) + genSignedDataSizeFunc(g, msg) + genSetSignatureFunc(g, msg) + } } } diff --git a/util/signature/data.go b/util/signature/data.go index 1db46dc..7f01541 100644 --- a/util/signature/data.go +++ b/util/signature/data.go @@ -3,7 +3,7 @@ package signature import ( "crypto/ecdsa" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs" + refs "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs/grpc" crypto "git.frostfs.info/TrueCloudLab/frostfs-crypto" ) diff --git a/util/signature/options.go b/util/signature/options.go index b9bf68d..471fcf0 100644 --- a/util/signature/options.go +++ b/util/signature/options.go @@ -5,7 +5,7 @@ import ( "encoding/base64" "fmt" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs" + refs "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs/grpc" "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/util/signature/walletconnect" crypto "git.frostfs.info/TrueCloudLab/frostfs-crypto" ) @@ -30,11 +30,11 @@ func verify(cfg *cfg, data []byte, sig *refs.Signature) error { } switch cfg.scheme { - case refs.ECDSA_SHA512: + case refs.SignatureScheme_ECDSA_SHA512: return crypto.Verify(pub, data, sig.GetSign()) - case refs.ECDSA_RFC6979_SHA256: + case refs.SignatureScheme_ECDSA_RFC6979_SHA256: return crypto.VerifyRFC6979(pub, data, sig.GetSign()) - case refs.ECDSA_RFC6979_SHA256_WALLET_CONNECT: + case refs.SignatureScheme_ECDSA_RFC6979_SHA256_WALLET_CONNECT: buffer := newBufferFromPool(base64.StdEncoding.EncodedLen(len(data))) defer returnBufferToPool(buffer) base64.StdEncoding.Encode(buffer.data, data) @@ -49,11 +49,11 @@ func verify(cfg *cfg, data []byte, sig *refs.Signature) error { func sign(cfg *cfg, key *ecdsa.PrivateKey, data []byte) ([]byte, error) { switch cfg.scheme { - case refs.ECDSA_SHA512: + case refs.SignatureScheme_ECDSA_SHA512: return crypto.Sign(key, data) - case refs.ECDSA_RFC6979_SHA256: + case refs.SignatureScheme_ECDSA_RFC6979_SHA256: return crypto.SignRFC6979(key, data) - case refs.ECDSA_RFC6979_SHA256_WALLET_CONNECT: + case refs.SignatureScheme_ECDSA_RFC6979_SHA256_WALLET_CONNECT: buffer := newBufferFromPool(base64.StdEncoding.EncodedLen(len(data))) defer returnBufferToPool(buffer) base64.StdEncoding.Encode(buffer.data, data) @@ -66,12 +66,12 @@ func sign(cfg *cfg, key *ecdsa.PrivateKey, data []byte) ([]byte, error) { func SignWithRFC6979() SignOption { return func(c *cfg) { c.schemeFixed = true - c.scheme = refs.ECDSA_RFC6979_SHA256 + c.scheme = refs.SignatureScheme_ECDSA_RFC6979_SHA256 } } func SignWithWalletConnect() SignOption { return func(c *cfg) { - c.scheme = refs.ECDSA_RFC6979_SHA256_WALLET_CONNECT + c.scheme = refs.SignatureScheme_ECDSA_RFC6979_SHA256_WALLET_CONNECT } } diff --git a/util/signature/sign_test.go b/util/signature/sign_test.go index 1fe2a4a..928490f 100644 --- a/util/signature/sign_test.go +++ b/util/signature/sign_test.go @@ -6,7 +6,7 @@ import ( "crypto/rand" "testing" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs" + refs "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs/grpc" "github.com/stretchr/testify/require" ) @@ -38,7 +38,7 @@ func TestWalletConnect(t *testing.T) { for _, tc := range testCases { td := &testData{data: tc} require.NoError(t, SignData(pk, td, SignWithWalletConnect())) - require.Equal(t, refs.ECDSA_RFC6979_SHA256_WALLET_CONNECT, td.sig.GetScheme()) + require.Equal(t, refs.SignatureScheme_ECDSA_RFC6979_SHA256_WALLET_CONNECT, td.sig.GetScheme()) require.NoError(t, VerifyData(td)) } }