From 2511f4ca709b9be348fccad58a3a15bf570873e8 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.go | 4 +- accounting/grpc/service.pb.go | Bin 18993 -> 18985 bytes accounting/grpc/service_frostfs.pb.go | Bin 0 -> 4258 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 -> 1108 bytes accounting/json.go | 14 - accounting/marshal.go | 104 -- accounting/message_test.go | 16 +- accounting/test/generate.go | 21 +- acl/bench_test.go | 43 +- acl/convert.go | 535 ------ acl/grpc/types.go | 2 +- acl/grpc/types.pb.go | Bin 39444 -> 39440 bytes acl/grpc/types_frostfs.pb.go | Bin 0 -> 8269 bytes acl/json.go | 62 - acl/marshal.go | 308 ---- acl/message_test.go | 20 +- acl/string.go | 110 -- acl/test/generate.go | 68 +- acl/types.go | 379 ----- audit/convert.go | 94 -- audit/grpc/types.go | 2 +- audit/grpc/types.pb.go | Bin 12413 -> 12409 bytes audit/grpc/types_frostfs.pb.go | Bin 0 -> 2557 bytes audit/json.go | 14 - audit/marshal.go | 88 - audit/message_test.go | 8 +- audit/test/generate.go | 10 +- audit/types.go | 243 --- container/attributes_test.go | 8 +- container/convert.go | 1280 --------------- container/{ => grpc}/attributes.go | 23 +- container/grpc/service.go | 6 +- container/grpc/service.pb.go | Bin 112809 -> 112797 bytes container/grpc/service_frostfs.pb.go | Bin 0 -> 30605 bytes container/grpc/service_grpc.pb.go | Bin 18225 -> 18117 bytes container/grpc/types.go | 4 +- container/grpc/types.pb.go | Bin 13484 -> 13476 bytes container/grpc/types_frostfs.pb.go | Bin 0 -> 2655 bytes container/json.go | 22 - container/marshal.go | 546 ------- container/message_test.go | 72 +- container/status.go | 4 +- container/status_test.go | 4 +- container/test/generate.go | 150 +- container/types.go | 717 -------- go.mod | 2 +- lock/grpc/lock_test.go | 28 + lock/grpc/types.go | 56 +- lock/grpc/types.pb.go | Bin 5767 -> 5763 bytes lock/grpc/types_frostfs.pb.go | Bin 0 -> 1087 bytes lock/test/generate.go | 20 + netmap/convert.go | 919 ----------- netmap/grpc/service.go | 4 +- netmap/grpc/service.pb.go | Bin 46017 -> 46009 bytes netmap/grpc/service_frostfs.pb.go | Bin 0 -> 12069 bytes netmap/grpc/service_grpc.pb.go | Bin 9124 -> 9124 bytes netmap/grpc/types.go | 51 + netmap/grpc/types_frostfs.pb.go | Bin 0 -> 11905 bytes netmap/json.go | 62 - netmap/marshal.go | 554 ------- netmap/message_test.go | 42 +- netmap/string.go | 68 - netmap/test/generate.go | 118 +- netmap/types.go | 751 --------- object/attributes.go | 14 +- object/attributes_test.go | 19 +- object/bench_test.go | 45 - object/benchmark_test.go | 16 + object/convert.go | 2171 ------------------------- object/grpc/service.go | 18 +- object/grpc/service.pb.go | Bin 145650 -> 145642 bytes object/grpc/service_frostfs.pb.go | Bin 0 -> 41860 bytes object/grpc/service_grpc.pb.go | Bin 37991 -> 37545 bytes object/grpc/status.pb.go | Bin 8502 -> 8498 bytes object/grpc/types.go | 4 +- object/grpc/types.pb.go | Bin 41264 -> 41256 bytes object/grpc/types_frostfs.pb.go | Bin 0 -> 8767 bytes object/json.go | 78 - object/lock.go | 160 -- object/lock_test.go | 26 - object/marshal.go | 1120 ------------- object/message_test.go | 98 +- object/status.go | 22 +- object/status_test.go | 12 +- object/string.go | 55 - object/test/generate.go | 241 +-- 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 -> 7702 bytes refs/json.go | 62 - refs/marshal.go | 263 --- refs/message_test.go | 20 +- refs/string.go | 47 - refs/test/generate.go | 35 +- refs/types.go | 194 --- rpc/accounting.go | 6 +- rpc/client/flows.go | 16 +- rpc/client/init.go | 8 +- rpc/client/stream_wrapper.go | 20 +- rpc/client/util.go | 2 +- rpc/common/call_test.go | 2 +- rpc/container.go | 6 +- rpc/message/encoding.go | 2 +- rpc/message/message.go | 2 +- rpc/message/test/message.go | 67 +- rpc/netmap.go | 12 +- rpc/object.go | 10 +- rpc/session.go | 6 +- session/convert.go | 893 ---------- session/grpc/service.go | 2 +- session/grpc/service.pb.go | Bin 18263 -> 18259 bytes session/grpc/service_frostfs.pb.go | Bin 0 -> 4425 bytes session/grpc/service_grpc.pb.go | Bin 4108 -> 4108 bytes session/grpc/types.go | 23 +- session/grpc/types.pb.go | Bin 57088 -> 57076 bytes session/grpc/types_frostfs.pb.go | Bin 0 -> 14091 bytes session/json.go | 129 -- session/marshal.go | 582 ------- session/message_test.go | 32 +- session/status.go | 4 +- session/status_test.go | 4 +- session/string.go | 47 - session/test/generate.go | 66 +- session/types.go | 834 ---------- session/util.go | 163 -- signature/body.go | 14 +- signature/sign.go | 22 +- signature/sign_test.go | 22 +- signature/verify.go | 10 +- 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 -> 2249 bytes status/marshal.go | 84 - status/message_test.go | 16 - status/test/codes.go | 2 +- status/test/generate.go | 16 +- status/types.go | 117 +- storagegroup/convert.go | 59 - storagegroup/grpc/types.go | 2 +- storagegroup/grpc/types.pb.go | Bin 8923 -> 9005 bytes storagegroup/grpc/types_frostfs.pb.go | Bin 0 -> 1478 bytes storagegroup/json.go | 14 - storagegroup/marshal.go | 54 - storagegroup/message_test.go | 8 +- storagegroup/test/generate.go | 4 +- storagegroup/types.go | 79 - tombstone/convert.go | 41 - tombstone/grpc/types.go | 2 +- tombstone/grpc/types.pb.go | Bin 7272 -> 7268 bytes tombstone/grpc/types_frostfs.pb.go | Bin 0 -> 1314 bytes tombstone/json.go | 14 - tombstone/marshal.go | 56 - tombstone/message_test.go | 8 +- tombstone/test/generate.go | 6 +- tombstone/types.go | 57 - util/proto/marshal.go | 6 +- util/proto/marshal_test.go | 4 +- util/proto/test/test.pb.go | Bin 13851 -> 13851 bytes util/protogen/main.go | 113 +- util/signature/data.go | 2 +- util/signature/options.go | 20 +- util/signature/sign_test.go | 4 +- 173 files changed, 1212 insertions(+), 17297 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 create mode 100644 object/benchmark_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.go b/accounting/grpc/service.go index fa292bf..4d1432a 100644 --- a/accounting/grpc/service.go +++ b/accounting/grpc/service.go @@ -1,8 +1,8 @@ package accounting import ( - refs "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs/grpc" - session "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/session/grpc" + refs "git.frostfs.info/TrueCloudLab/aarifullin/v2/refs/grpc" + session "git.frostfs.info/TrueCloudLab/aarifullin/v2/session/grpc" ) // SetOwnerId sets identifier of the account owner. diff --git a/accounting/grpc/service.pb.go b/accounting/grpc/service.pb.go index 9699622c290ee7cc4515ab0a56c1f05ed3ff5473..e184d2a11d385c73ae6e6aba26cb18bed1cf29f9 100644 GIT binary patch delta 72 zcmdlug>mH+#tFf4#s+!@T>AP7oCQVsCHct;P*7&9XK18nGO;j^D>1PsGp#fyCo^y2 NTN5PSW_?B`PXH5x7QFxf delta 80 zcmZ2Eg>mB)#tFf4MizR8T>AP7oCQVsCHct;P*7&9XJn{nIk7O0FRduQxFoGuH?bg7 RH$8viOA|Da&FYLyo&eTG8Cn1U diff --git a/accounting/grpc/service_frostfs.pb.go b/accounting/grpc/service_frostfs.pb.go new file mode 100644 index 0000000000000000000000000000000000000000..6217f752357c9cfb7014c16f748244a5d7dc6618 GIT binary patch literal 4258 zcmeH~QBT`25XYbEPjTWY-DtA0w@JJJlU8X^iB@|-XmXQFYvJ0R?KEVF@4mC0K#O4N z9vBQ&s?;>OyIk&m|LY~o;8+(3GgN4}!vdxaERA+LAJDnMOb<$-3BQVlj4Ys{TQfkNa?)j%sSbu;{bS z+xxNGwW6GIW9MALB7WNk#b_TT)+AQIhGMqQuT6obtJSasDqx8QB&rz|OISLxzSvw* zHur5v`um`;?##)KOQ~}YOBd|CZ4_4xpfTD2sz3!ABC4K?d=7;uKxr48Yp9Lz$b>!= z+;PbDVkyy~Y~ zE~kyde*66gE~4QLu|XeV$2+gl6Mj;cuP}+09*^~g5F_Nc;)WDaT6Cld$9nDYQ>1m7 z5^QvXi)j7%@=^52V1qnQ=|&?0(=Q~)XIEm7`!>2g@Wnet$G;*cZBbi7U7qTIuVV7a z`+P?lfz6#)J1)HQM%j0QClLLNdRf7Dz;z1p`uuOT-om}*upq)84vP)mw+utjKMeD@ z1juSb0bVk%Ver_cRu=!wBG4`$yG7s?F9MJ7@HVDHTzv1@d)lRZK&P9*KYmd@G`r=Z(o+J7XSbN 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..b4e23821a4117d344bde28013bef29899c2149ee GIT binary patch literal 1108 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)%!{0JD@CW2)cJ9lcV4P|_{ST@ z@*H-a7YcXs7lK9KS?$0#2rk?(0!|=x3|Mpmgt0C68Tq2sb|qQRK`(t1eY`~w5>*99 zt~z?u@FPAyDx~K2JdDqn=yVCm30|$Slr2~3MVcgqWC$U(PvMcxWC*ibftD&<&SF}4 z!)8xxHYi`OV$y7*{fGDAm6Eq}IAuRWkn~#ggH-R9gK8O6-zKR`ywiG*YL%m}o##U&j_BH~jQh^o}>YD14j?P@DpKHqVyqF}NgT{W6 zla4E8%7D)_?EAPnuFrth8VjfgPS6r#eIv^TDp`RxelYjYTNxl4HdArWp)~D5p+|KN zLt#r4*j_rEzu;nwOi;w3ftA5dslrH)ddjr(|Bc7Q+1~&e_mBi8@9vAU$8nm^;6y=xXCo4cfnX#Usk)FxK!dR}v#G=f!(wv;kyp4A( GW&!}AP7oCQVsCHct;P*7&9XJn{nIk7O7FRduQxFoGuH?bg7 LH$8vj4U3roDdQ7d diff --git a/acl/grpc/types_frostfs.pb.go b/acl/grpc/types_frostfs.pb.go new file mode 100644 index 0000000000000000000000000000000000000000..08b2232c3c2d26cabdf2183acef741ef9fbc80f3 GIT binary patch literal 8269 zcmeHMQE%Ev5Ppt-#i&nkmzcY>x`#@6NK#IRE)7z`^(Bg;#U8^dW*4p30b2FH-|Vh8 zU}LD;Yjlo;goKS}X2(0<_j$(jdT=RYgb4~%Ok)h=70i{?GCHB(PA2jsQ8Lp>7Q%-i zTn|Uk|1cPZK`>|0Bby+wC=CKWn@gqP&4laF+jEh~-bm$mnaVuAV&fiTiYIxRa?yJ_ z?d6)MJ-gJKAn5hrR2RUD@Fh6nCatqG5Ii-fM=o#pEjaob99hd>&s@%7U*t1$Z=K(d=|=S1)6O#d z3t5b6w3=hLyVL%3ZU2$!Xj*T6s}&a$yTIFHScZS&YAfW1%{ycB$!rT*6VkRh;b@4mh zV-UFT=48jxR7M7yKG;nG4<=TCN=XGMBAE*+7Xf%N<Rr7Ncs?Bjq?U(?J3px5j)P(Kx4BUgb;FkVv1OpWT*{%gQMcOgm0f7 zL7bxAIg|JIYXFx4zb^!#zCJ{W1Jwu);XVx_LOF(~#eO&9M%Ast6uMj@ilJQzH-<|8 zi)M|OnjmS@X8nGyX5GlNMy+mej)tKZ1j)>*5EamFcXkk%RtroSF`hbv@K-4?9-UQ& zm+ zBe8gXWLm+nZA;;D$M4-!XDgDC0eiTs9Y zvZam7@H@!RaFH5i+`*5QN!A52MemN}BZ`L$8LuAf;T2C%^Vv_+v3~|a|M6}uU;X8L zOS(2}tYTe{lYKT;g9c2K&7l)(Str&ERG#E5lp}{lpJ0s&IRID1q3l*8JPyz5-`KQGQ8&vH}#88S5Du>6uI{Oyo*TEXqtP&B@8k+xTFv FJ^RC=KOyo-|$}cWSE7nac$ka{G J-*{)PJ^(Ni6NLZ( diff --git a/audit/grpc/types_frostfs.pb.go b/audit/grpc/types_frostfs.pb.go new file mode 100644 index 0000000000000000000000000000000000000000..a7684cdcd6d61d378f1e9825300d86724b5b9f8a GIT binary patch literal 2557 zcmb7^Pfr^$5XH~gPch<@w2&o0X^X_6<&TP5pbE4X#KGB}O)MNcwY`KC@!dPNcOmhH zkV=t~-OPI)d;ETB3P&nO7@|bYEaotn!9**ovMqYIHB?)LR>l^l3&)pmad{0V$7k2w zB$=@6jtvo5nRA;Yd^}Ow!p4x>Zmr<5Q0cWU@kppL|G@?+W11JG5L~ABJ85aTNd00P zNs^{;W!XUB75|H%(Uw{oupbU~`ij3j7a%IzrV*chSU zC~~-GqNKk@>>gkK8gR+<%-eU9qLdl5AK=|Fv+Rr8Qy)z!Y-g^kb_d$N87}GlW76WT zsl!8%T)4+p=o+?@)>G2*mG2Kj$K4Awbh=lzYSV49-P?qR?r+qFE7^$!r~Co){XJi} z;|hIKCli&88nw&Jcb(=)Ny|8m_AGCRzRoNfZ@=eCf0hHmv+p=-7Ahrt-G^W~o(Qzq zDEoCL?e2~*+;@e2{6lAM&8otWq0nlMu8w9391adaGf7vAnqtOW4gJ{~cMDb?=O@1n zuejm2WJg12IG!>t)^_~t9E0N7aj}oNP4~84^*3%;ZMf%We$LIxW9j*UyM-HGeVm}n z>C5zbe$wuwE-1-O-z5q^aA#jDs*CIPmORa6@tkQhVgknD+e8_x5)`5sf@ge&tJo=> zqpl-*RsiL;Kn()rkTS{*{W31&Ow!4{q`%$S1c}qSoa&emDs$Ve&H5D|n4AG>P4@<6 zrb=m16T_w>o{b>qIY?!_cnVX^Etf+d|C}-onF<$K%$zA)5^D668{AxgPt`J!Czv`Q zc{z3EEG^2qr{{40KZ9zRy+xsF9&HD}o7({;xKn+vz)>iCq%_cnkmba4(DIKo;X7=H zN_UOthY^x=&on`}FlY(GHfdGAUrS`&DcyHk;3iZb+&b?U;>8{n^J*=nAl5EGFqTIc ztZgVCvCSeEV;`TbT1{Dr)$^!qXbG0Jlz16SkE%;YXBsO5N@^`3G}g`mb+wkL+SIPY z*x2@!10~SL{sGj_kX(h`H5VcF#*0KGj*S)%(BU{X2ylKwx8%lFynaKtAP7oCQVsCHct;P*7&9XK18nGO;j+D>1PsGp#fyCo^y2 WYZD~iWL-vNZgW24_IyT0tL*?sT^?-! delta 103 zcmbRHk!|Hiwh6&AP7oCQVsCHct;P*7&9XJn{nIk7N@FRduQxFoGuH?bg7 bH$8via}zX?$*PR#Le0sH+mjg?t+oRI$GRdw diff --git a/container/grpc/service_frostfs.pb.go b/container/grpc/service_frostfs.pb.go new file mode 100644 index 0000000000000000000000000000000000000000..6cc376ecc353aa498b8db8e1fcc71e8c1f8c1eab GIT binary patch literal 30605 zcmeHQ-*4MC5PpvS3ZhT;me^Z2?4dv&x+K^Fw9QbbdkKPqwkVs3Ol1-s$1D23??{P` zl?oDyndeyBprrq!2e|=W^xvbgvbdaiTXzrkVnErI=xMx^sd ze)wx9KeK<}YWel|$X|4Gqv~`?M-PSz*(Kk+Bd!K@dP)Qj)yJcB)Z{1c=(~5Mul(^e z9dYjybjbXH%!a8Rvh(vXdF-8;IqcSH@>Vq&@UfukVWCNOOLa5vdu|p#(m0vWkWACx z$;#|y&z??VI%SET{cOUb*k`es+{=K#j0Y?xAroVmU7o;SiINT#YCKE1b-Kqyu(`P$ zuA^ZXjTE>{XP-04Qn4T`j-!|`F^XnFvKSCJpYYLy_}nKVlDhGn%wsOO7;C}#R8oN5 z^gd*gg$vawxdM>HbDpr{0&KD&17^}r6_j*y7?tW$GGWHF6iajT7#LRJCzD4Sh#2@)njfuwho{k;yF zW~6{lxWP?&^}E|utk&!W0K3|Y1-@`e0li8+3c}RN^a>oXbM@C8Q(N;tGD-hr6m+u| zTl}Jg_BR90T`XH6VK_?|25d$Hm3|*AS7gB6oF)obuh|U%ewA(P@OP1LlKV&`Y|mE5 zrH@90qeg@U53OK^rNx`ap1TTZSXrCwyYK+e1VEnwe9lze4cc0v>1YEq2t1rK<_IcJ_OaG^g_`{^`rvx>VLgaiK`2Gjp{7%CkRgbIAkCtHCP*5x#jxc|gWk`=mR7vA zf-}$v*}w>~_@2$l2SbgHg&K{LTclgA>X{@RbJB~CgNr2W+=7G%?(OYrZ_f_6a@AS0 zN9@|x9?ouE9D5}Bc{q-FKn7-IK(ageQ)`%fkP{Jq3ChDX$L&bKiU9j1E}nz z9p?8u2U{!j9M}J*>%YZ`YVIPdMVyqz+_#Y=SbZ0rDKvnbJ|2nd=#B}@3UDtgKvRze zcC8?wrJ(`H+fHD=W-peUA-f_t7X8Sf0nHvXd-h@Wq}*fB)(YA|yQhKO^MNP(4SZb9 zp|}Kt9xm27tiwVpSm7D&99#QylW*8~XTC?qkkvkf&JHSMZCAI!3Wc;L$?1|N3))(t z<+%1YUi&THXLI6#QrKMO(Xwb@SqzxG zc!X+vpZV|4KJ2vs;)0Gsuo|if3o9R7uY9ORQ7f1wLu^fII>^!ot0c|xfYu0>KKkBj#Q`Ka)c{{B7-_2;2sO7MEY8cJ zlvos;7fg&Oyn-KJG_k7}P1woESmdqXA+(GdSVr%KfFlw{>`MY?NWkeEh1W!WHQ!E| zI+r4U8pG!2ReZS=^0!~Lxs}>S_t9ulKUJdW^%hN}T-Vw%T0RtXkNYEz?T;92ErpcN z&#@xUVRlN9X9j3V)x5}1Uem6zq*oMyzuHf602Z@oIn7VH;8?7v6cC%U&$9$vb00-& zjgrC(4KXX+)pK%;n3jmo6N|x-QB?;bz%>B6s_iRhKADHH@Q#@b4fa*c9tZ&#nQ5B= z-;Sm&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.go b/container/grpc/types.go index 7308f9e..88e7396 100644 --- a/container/grpc/types.go +++ b/container/grpc/types.go @@ -1,8 +1,8 @@ package container import ( - netmap "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/netmap/grpc" - refs "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs/grpc" + netmap "git.frostfs.info/TrueCloudLab/aarifullin/v2/netmap/grpc" + refs "git.frostfs.info/TrueCloudLab/aarifullin/v2/refs/grpc" ) // SetKey sets key to the container attribute. diff --git a/container/grpc/types.pb.go b/container/grpc/types.pb.go index 0cd53eb0f167fe4e103aefa3271e1b3717f66bb1..eb54dd9232d36cbeb1b76b5d9825bb787039f180 100644 GIT binary patch delta 70 zcmZ3Jxg>K!u$-}ho&lG>z5-`KQGQ8&vH}#88S5Du>6uI{%;HK+EXqtP&B@8koA}ZU LiMLsovECQ}_0kr) delta 78 zcmZ3Ixh8W$u$+;Fo*|dMz5-`KQGQ8&vH}#88S5Dt>RC=K%;HNc$}cWSE7nac$ka{G PpZL@aO=PnwW4$o|wR0I) diff --git a/container/grpc/types_frostfs.pb.go b/container/grpc/types_frostfs.pb.go new file mode 100644 index 0000000000000000000000000000000000000000..7016647d7e5584aa41c2a3dfb5cdda7d21bb02a8 GIT binary patch literal 2655 zcmeHHO;6iE5Ix7gV#LX5!ET}L0VxNdJw$B@DwGRC)!H5>D>l2)?m8bu{P)i8+Bh)* z(W zi`0K`CyLS(&MnIXp7Wmw8f~Se0Xso3?tv;{30#K$vZ{nq=_#`b;Q~}wIYH3Cg4;>J zu_;2yQ4}y|qM}z5Hpli=#wF7$PoG3(C3A?E@am*F(~l!-HP0%G{k6{GKE%EuE^Qxf zqaJsS4F({&aJRkCIlPH_cTvw*z8-|GlXK#eV|Tvz?Jg{n&$#M8QM2!AE?wtTRnt1c z=x%LVUzs)&CSV$_rZc7bjA2+|G{#T49*oij>Sl<;5@@m|Y7i*LG(~RcpK)7Yl6q

h_7zwir>&TQ|Z>ZF1eq(9g82{eWf6K|IXh`b!a%wGoiP~@_AJ}>u z!25f&p!ggX4*`{kPA*KH>X3K?< 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..6d1f6e8 100644 --- a/container/message_test.go +++ b/container/message_test.go @@ -3,45 +3,45 @@ package container_test 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" + containertest "git.frostfs.info/TrueCloudLab/aarifullin/v2/container/test" + messagetest "git.frostfs.info/TrueCloudLab/aarifullin/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/status.go b/container/status.go index f44fce9..0ce5395 100644 --- a/container/status.go +++ b/container/status.go @@ -1,8 +1,8 @@ package container import ( - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/status" - statusgrpc "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/status/grpc" + "git.frostfs.info/TrueCloudLab/aarifullin/v2/status" + statusgrpc "git.frostfs.info/TrueCloudLab/aarifullin/v2/status/grpc" ) // LocalizeFailStatus checks if passed global status.Code is related to container failure and: diff --git a/container/status_test.go b/container/status_test.go index 57787b1..7dd4636 100644 --- a/container/status_test.go +++ b/container/status_test.go @@ -3,8 +3,8 @@ package container_test import ( "testing" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/container" - statustest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/status/test" + "git.frostfs.info/TrueCloudLab/aarifullin/v2/container" + statustest "git.frostfs.info/TrueCloudLab/aarifullin/v2/status/test" ) func TestStatusCodes(t *testing.T) { diff --git a/container/test/generate.go b/container/test/generate.go index 2b2afdf..0c2d921 100644 --- a/container/test/generate.go +++ b/container/test/generate.go @@ -1,15 +1,15 @@ package containertest import ( - acltest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/acl/test" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/container" - 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" + acltest "git.frostfs.info/TrueCloudLab/aarifullin/v2/acl/test" + container "git.frostfs.info/TrueCloudLab/aarifullin/v2/container/grpc" + netmaptest "git.frostfs.info/TrueCloudLab/aarifullin/v2/netmap/test" + refstest "git.frostfs.info/TrueCloudLab/aarifullin/v2/refs/test" + sessiontest "git.frostfs.info/TrueCloudLab/aarifullin/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/go.mod b/go.mod index f7eedf6..8c9f7c5 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module git.frostfs.info/TrueCloudLab/frostfs-api-go/v2 +module git.frostfs.info/TrueCloudLab/aarifullin/v2 go 1.19 diff --git a/lock/grpc/lock_test.go b/lock/grpc/lock_test.go new file mode 100644 index 0000000..4d2acff --- /dev/null +++ b/lock/grpc/lock_test.go @@ -0,0 +1,28 @@ +package lock_test + +import ( + "testing" + + lock "git.frostfs.info/TrueCloudLab/aarifullin/v2/lock/grpc" + locktest "git.frostfs.info/TrueCloudLab/aarifullin/v2/lock/test" + object "git.frostfs.info/TrueCloudLab/aarifullin/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..55d2565 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/aarifullin/v2/object/grpc" + refs "git.frostfs.info/TrueCloudLab/aarifullin/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..10ef695f14ddee34d019681983768bba41d0e794 100644 GIT binary patch delta 55 zcmZqIZPuL-EN5(>XTYVeufSPQlwXpctN;aN#(IWEdL|PK2g3ZX`WBs^A7oZ&#$+j7azmbG06+f|RE$b}#!JFS(;k6-f6E1eH#-6Tn#!^Vq3 z<3@c)AoLv>2fjgY;enNK0%fALqLUykwZdnti&E-JmY{=P`6lW_iy#&13XVc|{HhU0 zyu2!u5p*8fXNl}g3F!$wJn}g6D=X<7(!qf;eh#n6Oa&*a6&R(%?JQb_Ps!{pnXxNS zaJvE$hO;?kPuLbnZm1mEd|bsDvS)N0_r{OL!`SKP#YM7HFY}@2ctB7mZ&yJ*3383l z(8jC#Eue9{m{Ux}4FQjtSgMew{2nB5s1gY@nwkStj{mu^0AbkEWi{!10S5c2oa=;U z1Ohr!vv1?_ggFBeaU^I;+Zm6mzT#`;0rLr=;pQxChTgcnfS_Mp+DK8L2T zW)7%V4i~?WF 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.go b/netmap/grpc/service.go index 882db6b..1499d31 100644 --- a/netmap/grpc/service.go +++ b/netmap/grpc/service.go @@ -1,8 +1,8 @@ package netmap import ( - refs "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs/grpc" - session "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/session/grpc" + refs "git.frostfs.info/TrueCloudLab/aarifullin/v2/refs/grpc" + session "git.frostfs.info/TrueCloudLab/aarifullin/v2/session/grpc" ) // SetBody sets body of the request. diff --git a/netmap/grpc/service.pb.go b/netmap/grpc/service.pb.go index acfe43c41c18da00dda38033bfff90758005e225..0fdcddbf077e1bf932c065b5a10d6d46005ed2dc 100644 GIT binary patch delta 72 zcmX^3oN4ECrU}7v#s+!@T>AP7oCQVsCHct;P*7&9XK18nGO;j?D>1PsGp#fyCo^y2 NQxhcKW_89{n*d4P7;XRn delta 80 zcmdn_oax|mrU}7vMizR8T>AP7oCQVsCHct;P*7&9XJn{nIk7N}FRduQxFoGuH?bg7 SH$8viLlZQS&GL-1HUR( z!=sCK5R6#wn)ML`>LD8i0UwT}(y-I#y6r@`h-G-8GCW9R79F#0$e7}BmLyz+<1b;R zc@pMN+X;d&gmcZh37+%62nuzkL<)L=x=nIcRAoI9!4xK3 z53C#;BE%e%2*xbQ=&u1ADxh^i5@g>;KQ-(v7|#rIU?=P@DIu9-`{04 zZI$$EwxF4-#f5IcZP4IGz5RUuH0}cT#Rvp*Ie{-<3>y~=*i(IL5<1OObVyu zNHyUp?p9n|s7!vflNxvD;-ro$D8S*g<7^9~Yi!8lYWXb*CCz#k=ut;avK& z;?6Y$?#nToqx<8&jkk7(f&im?7nqecKkpK(^1uihPmlg$MxUT&Kamk^Tg%9NH8Q`D zC}VmrRoLDAe@penRNiP~>Vz9)l`B$RMYi!z)1|(&6BWRJ} zm?_E`af+Ie13uo>X)2`pg%uNeIU@NN*tKb ztWazon*S?%rXwj*d}aE4np|=!BKxFVilvw(XCs&7Ny4+rdS~bw9Jz?40H{gP8^SF! z%r40bHT3cj#+$$iE=3r=dfsk&NjmU56Ti!^RC1O>9PYM)J_?M#oIBpr)}(`aBGt7o z>tS2V`X@ZRIONx}sDHR5M_@j2+T%NaJoefH&mIyy)AEdn(#&AE{8pslKdwg7co5&3?P z@Vq?&-2pfkY?Kb9_C52h?3q)ixV{IUV@;YWy&TZlO9FIc8mV|E=kc6 zDcW(eEFcC00i49V6sdd8;kj4p_tAil37QZ_1eRosMk_QIT=Mh?{&zItN15P-%!(fR zc!`FWH|Xr+`AsiL<~Y5_6M`6#GdxccI-7GL(VGdCJsUz<#``y-B!irn<3I7JkFlUx zndg-CACCK_q&L3t0{gU^;aXxuvqEodr4NZ6m^#9r%yDOM06XA z>2y&?uYoezMc4Y+F_k^+zb6PY`zulk#ss|vZLcQ7Grwc59ePJT2pc!5PR#W|Xp&%(=Gb>B?_ zO}Yx5`6^jljES&`JiP;Dps zT%iiH6(T~wEg>xBC4+Gk!vZi0lQTiI*Ki~ccYag-Rg4-h|R$7 zkX`rzpsU~p)b*c`*n843BNZ;1IWWk0zycVX6+|kqCI{8;9xdzwff+FGtr_(GPEA?y zWP2Qt#g8-8@xv5(?8SgTZjj3+Kh*Ha1_Pzs;2jC(&+1XkP7f^er{BOi80Jt;k<>w; zru3_c<~7MlD*5Zm=9hD&gIb=nYz`EYTY?x8&OwgLf;=vsA0){4s089{k?e*v!mzz2 zMy82AG%eSFLH`$3G(@l)3#g)HhA%@q>0(V5Km1W`Z1QJ&@J8jUDHWOIeJ1mqrue0d zVnfWdQM4)3I_{mDwdAeAy%(P7%$NrdOV0>($JLL38?#{C&f$RYwDB1ki?4E=k{Mz0 ziUXTh&u4S1zN*r{Yk{RnZ)4UKmdpNzMpTA}Nlc+~KZRnvoPWaFf(2?ln}%H%10ES% zedXzj^=evsd|C~u>rvm&x;s4OJlE=`P1P4h|JKFp-c&_qsy5IjB8_Wd)pAQWJbWSB zP>%(q&`z@^g+G-mrU6YH@Mp2szs`mwx60cm6M4rA1xjI`+x|?7-4-GN!{^gIvZG=M zjnZ@IXnw6-?SIrH4E6tv*RGwP?d!Sv3FsuM;nf(ewfqVTIOB@iOsg=bfl%dT-?Mw| zp510xS*k?n7~RS*Ad}%foEsL?vtm++_1)h)CtXajjw zj=;u-^uxV_IzoHM592XBG%1MEhSr(6R=Ot{$2w|#NVxjcwvpY5N0kl`7okX5ROXzE)}x+i^nq~C@VOR@-6 z;4z;PuAZEz0J}Y)#?0&IANZ{rWvvjqp68}evbs`txA**xnco&M5wZF)DDHSp2TVYX zY2R|jNov&=wF!D@4?ie{>Rno2oPDn%!d`_*P!o?435G8Sj}`+S_P56e9Dz#*KU@>S-kv}& X)nSMq>~X|S)9OROtDIrd7$y4$JgKL! 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..66df29c 100644 --- a/netmap/message_test.go +++ b/netmap/message_test.go @@ -3,30 +3,30 @@ package netmap_test 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" + netmaptest "git.frostfs.info/TrueCloudLab/aarifullin/v2/netmap/test" + messagetest "git.frostfs.info/TrueCloudLab/aarifullin/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..6483668 100644 --- a/netmap/test/generate.go +++ b/netmap/test/generate.go @@ -1,9 +1,9 @@ package netmaptest import ( - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/netmap" - refstest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs/test" - sessiontest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/session/test" + netmap "git.frostfs.info/TrueCloudLab/aarifullin/v2/netmap/grpc" + refstest "git.frostfs.info/TrueCloudLab/aarifullin/v2/refs/test" + sessiontest "git.frostfs.info/TrueCloudLab/aarifullin/v2/session/test" ) func GenerateFilter(empty bool) *netmap.Filter { @@ -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..16fea81 100644 --- a/object/attributes.go +++ b/object/attributes.go @@ -4,6 +4,8 @@ import ( "errors" "fmt" "strconv" + + object "git.frostfs.info/TrueCloudLab/aarifullin/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..a117b4f 100644 --- a/object/attributes_test.go +++ b/object/attributes_test.go @@ -4,11 +4,12 @@ import ( "strconv" "testing" + object "git.frostfs.info/TrueCloudLab/aarifullin/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/benchmark_test.go b/object/benchmark_test.go new file mode 100644 index 0000000..0364842 --- /dev/null +++ b/object/benchmark_test.go @@ -0,0 +1,16 @@ +package object + +import ( + "testing" + + objecttest "git.frostfs.info/TrueCloudLab/aarifullin/v2/object/test" +) + +func BenchmarkObjectMarshal(b *testing.B) { + obj := objecttest.GenerateObject(false) + + b.Run("marshal", func(b *testing.B) { + b.ReportAllocs() + obj.StableMarshal(nil) + }) +} 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..279df9c 100644 --- a/object/grpc/service.go +++ b/object/grpc/service.go @@ -1,10 +1,16 @@ package object import ( - refs "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs/grpc" - session "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/session/grpc" + refs "git.frostfs.info/TrueCloudLab/aarifullin/v2/refs/grpc" + session "git.frostfs.info/TrueCloudLab/aarifullin/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..6c60fe76bf02f071b9607aa286ae91300134777f 100644 GIT binary patch delta 54 zcmezLk>k}zjtRLehDLfO6ARP05)+Fu(@Jx4GV>-rH9_Jvt24H%Gcs;hXJk5U4ghBZ B6h{C6 delta 62 zcmaF$k>k@xjtRLeMuvKp6ARP$(u(qnOVWyU6ALnR)AJ`jG(i(-mS=32XJp(i&&YJz F8~_*37R&$u diff --git a/object/grpc/service_frostfs.pb.go b/object/grpc/service_frostfs.pb.go new file mode 100644 index 0000000000000000000000000000000000000000..75f35d722ba87085a780104e0f7678501facc451 GIT binary patch literal 41860 zcmeHQU31&G6@9jT1!kY*){)v|rw`llL*s0_o+j~*<+cx*jE9mSi!}|ZBos@V+5g@P zfLA0wD3P|9Kr&`L<1d1Mh;t9my}-Q~4#`D2rR0t>nnj#W$#_i`S<2JNEBM>1yY$s8 zOLIQU2jtxq`FM3hetvg(GwAge(d0h5qa+>wmri)E7e6f0jFTVkVm`noF`K2sn`}uh zl5{zJAB~4ml*O}UlEiHI<@IpM<76m%`=Qqx4#|i|ZEXvmM z_JiJR$tI+~B7gV?<=6Coa5cYun@-oKl~MIiNnZ{oX8e?V?VZG8Q0M1_#fkX!M2(vK zsdw^w??hht$8$B}!AH0uosM`hOz|Q6e?B9t!QZA+7))Wy?DvnkE+NnXwfJl+}2NJ7~iJjytS zpK>u35rdJGlhi*wBaA-c<#1h;B>Ok>2>gl1Wq5y~d%l5v^=)*k2aWKO2> zl(3Y`#*gGNi+RlM7?rps zrwqrmnS=IFLCoy}OEDjPfzwZ)$7@bci|<=dqb~dk$bm0FmS|kTmi!fF_@4IFl>!#k z$pCyn!!J<=wld2p2W#QIlj7$(9O6g;iqOF)b@fl5bzqwJ5YWVifKIcahE@2d22}xR zZRP}+zlU{qZrGANOsjU$fHd$Alt;hN2n^9;0#}$ z?Xe-_S)SpZP1GEQG*W!Z7HM~3wdM#6yT!3s)W6M;{e1}_kR=^;5zq>LZ-|OP2vu<> zq79AcphahJd|SlPe_d*E^k@3LBCN?kIzdD;7XiavIuf<%w{n5m8M!4G>%XQ8Dx%>3 zx@7##Ye}>}ig?{cx`=81arrRTqI@g__Pq=2Z$s}WJ9tgVU*@H^tKjYTA=sL$w#2&X?|VmIj7k^N6BM^KMEqt3mKN+xnc2plxTg zQ&G`DxcDes9AG#KTCjoVqqn2S06Vk7@bV8Y{}6Fb`qpaMYVeY_TD_xUpYV6uyd7Tu zp1uC-(Qp(3piCR^)A!dNKYC+j(TZvYi%Vc(ymPIS>r=`&rXbu_Q-#X*F4pc`$FJ(}{T(I1c z@?F97wwBfwdZVy`XUe5A*Fm-f*&-@obXZHmfwrR{m7rN#Y8IOP2TItK$*El@iwods z8`5P-9%scGSYd*qBb8L~5by9T-k~Pb38153lMPr+ol&!;%CRQuz^|9W!x6G-AH%da z$BHKi>DuBOW@)L)6vd-`O2YPLR#fRCnHgE8iP!cxnnTU7_T9pq7P*&|_BA=&^?ir* zZK$tytcAJ6v}@=_0q+qBKEpH{l3&fH^}^y>TTI2;HYCw-Bo+;KV!#atW4WORl*wHM zHe$N{TS1Rc8Lv)xJAlq+^YQMhr7qO=8trZ)qg?J9PNH!LcWGtvK%t15jNd2RrSIeP zh(a40yv2hXXg9opMPDy#XWfWK*<@agrQiNNPN0bAz8L6dwtPU^fh6xYulw+TBR-km ztQYjuij+eMPpA;_xhzaRS*S90gOn zhl6JnwzoI41P#;%)#2`$gKN+EzL=y|%Uq<4!^#`Y93>$tg&HKEfGWx3lmT17J~I-F zVrN;zpxX6npm;BDSkX)}PtoL4{26Wt4swW@c@{IPME|tY@rXRO0kNTwu-vWHz>Q5$b%Y*Mld+6Yjk7q_C!A4(=LGHH zj2fL0f|5}DqRzO{mMj_)kHdp;uVQ#cJl7(Efz$t7z7byIUw*`pEmYf-M-Ewm+R9}z zu<~9WDHWoy{zYLmbah23@onCrnjqm& z2wFCe-^9{6r-az%OOI_DuQEg&n%zN@Oo(o_h;EiZ*h_rV-cc#(x^h63dcRdVGYj$R zGN(K-3Y4bWCAjs(sNLO_=RR$=Q0iS8uOcbM;61c$i=wze*e>V8cDb#1_K4p0U?`RV z5{IkdN3{I1u58B~g<(B79!tn=GbeB5SqK@6{jV}RO-O`LL8Ge*8YYbefu?xo~OI>sF<&Zmktck=1kuUKy0iH;dM~;3_qq+^si?5^lw@H~W*}@EP3J ziCdGyc0SLx^Xpw1Pk2OMDWas{ z5+f5k3&Tpke=GgEJaVANV?wFw2Sv?4>Rfel`-B}j-0g{Tl!+Y7oa zQ05{IeB+=w9kfpsL`Vw}0_W|GAPGC!(|)9<9`FqcW7pZ+Qjr)(1fz-xXK(u_P_`oL zD2PU#-UiUElPEirG7UHvF-XsJiaC+^vgj;m9O5J|Jx)>wxuc+spiiErPaHmOdkPB6 zJf1D{R7~A5!P^bq`}bvV>Vs4NO`Lkmicq9&Hz3$Rwj$@}gvE)>9xn{))8{d41N#a^ zZd4&y5e}$aC4Yr8EADAuT`9{+^JttceAUd(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/status.pb.go b/object/grpc/status.pb.go index 034fa1bada29d6d8bcc387976a865cabe0310ccf..5dca1b1c5ba474cfc0eb7083bd3cd11aa0a2fb45 100644 GIT binary patch delta 22 dcmdnyw8?40Pp-toqRh0?oSe+O&FqZ&3IKAQ2(bVF delta 26 hcmdnww9RS4PrkIG{Nj?dV%@}oOx^VS&CHDY3ILlH3Hty5 diff --git a/object/grpc/types.go b/object/grpc/types.go index 9a2cdea..1ad3253 100644 --- a/object/grpc/types.go +++ b/object/grpc/types.go @@ -1,8 +1,8 @@ package object import ( - refs "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs/grpc" - session "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/session/grpc" + refs "git.frostfs.info/TrueCloudLab/aarifullin/v2/refs/grpc" + session "git.frostfs.info/TrueCloudLab/aarifullin/v2/session/grpc" ) // SetKey sets key to the object attribute. diff --git a/object/grpc/types.pb.go b/object/grpc/types.pb.go index 5c79080517863a2fc92f817c9395fc7c73b3a415..12d5732686df22986602a63e4acbb159be9ac3c1 100644 GIT binary patch delta 46 tcmdmRh-t+krU|($hDLfO6AP2M5)+Fu(@Jx4GV>-rGDYHTR%PT~005)!5t;x1 delta 54 xcmZ2+h-t$irU|($MuvKp6AP31(u(qnOVWyU6ALnR)AJ|ZGer~GEX&Bf0021i6fXb( diff --git a/object/grpc/types_frostfs.pb.go b/object/grpc/types_frostfs.pb.go new file mode 100644 index 0000000000000000000000000000000000000000..cb3aa953334aaafb721c0c2bbba3575f7d701733 GIT binary patch literal 8767 zcmeHMU2oeq6n(aS1<@yaOYA27*j6A9TN)t2vL=|lz68NQTa?X3CJlza7u{aUysolWd6I z-=GgS6Lj(ZYBG$X6`nodIYE5-51Gj*qRSN*61|vHIkYa6C44jyIXO>x9$(|>2xCE$ zJWVMZtxrd}r0Gas?L`!gMrbVYG$mvDFF}IHT(Atu1wonm15eN+qRa$0%@dSxvBYu+ ze#TYgGjJgp+EBSLet1bxLP;8o{1Q}jC!A=p0@n)%tSl(GTahAMz!SIWbd?~;v4jYe>O&%$!KX~+ zBW4g)nW_E35n^Ox&A|?*DW54WS+GBgT*hpRh!9*L!e%^Yk_aH&22Qp>F^v)9Qaf+Z zMo>xFT&HS`B}Oy8T%|;kbgMwo4bVbtXhx14q7)$mOAM$Yk9LQs6r?1~#uYZ=jcQt`JQB3QzZe^o^xTkLrVfyamTK79bW$ zMx@H^s8@V$BBPBI_y`xcGuH3!6?Vx^AHxvBx&lRgSD&yxfJa%21g!OuN)G!NipACu zi0nFsY3)O}=KyZIAa$nu01f8=x;G#d9BzpN3gF{3>H!!!a-amxVTTfo?^i}l1^N3| zDFvP8D*vmg`rm5_5Eqm|tG6y8zmsiEuPZjXe0)^Z53CN#*)ip8N)k(J$my=hr^ziF zU_doZLiz-E-2#f~sO{9JVx~Dy;SvS?pA&C`=4l0?)CmU%%(sqRORjmOcAa50pwgd_E zf_2)q#HzK2dosD@WdaRkjodzzrnkNKfxfZE_fA%ZXRit6Eb?_#)kWc)Gl^+<{`b;W zi|dmMgUSLxmjQpgabv1jKi9fox50o3Aw251A%#x-b9lY*b;n=y;0fCR*vL%y15x{% zS|!{y{#nafc=A%gmTnE@Fm#d=JqZ}yJ#_h<+mE=*M5}fG>xx*)k+0`oe%jLpN}{V! zEpY->v3Wz{t~UZj(AP0P2p1qw-uz9d572No0(GuHYS@odcRjVGNLT<{h5{-Gndt1j z>MNF(SRjl()_6aeY*>~pS|fYmkGQ;@X}g05W4Hw zZ=}>c$8MN(3vW606@#aK~oXR3O+EVYpW|SYi*+f`X0U@d#NSHBO2sJK;eE908fOwF>~@PcEnU}?J(TxX z>6cR^iUd2nko@j1B-NVss*+lk>Kzm%hsFUZD)%4005r&1K#3}u-4Y}qL~gPhG5G?| C>Z$ku 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..1410b98 100644 --- a/object/message_test.go +++ b/object/message_test.go @@ -3,55 +3,59 @@ package object_test 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" + objecttest "git.frostfs.info/TrueCloudLab/aarifullin/v2/object/test" + messagetest "git.frostfs.info/TrueCloudLab/aarifullin/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..6cd7fba 100644 --- a/object/status.go +++ b/object/status.go @@ -1,8 +1,8 @@ package object import ( - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/status" - statusgrpc "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/status/grpc" + "git.frostfs.info/TrueCloudLab/aarifullin/v2/status" + statusgrpc "git.frostfs.info/TrueCloudLab/aarifullin/v2/status/grpc" ) // LocalizeFailStatus checks if passed global status.Code is related to object failure and: @@ -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..1a5e7b6 100644 --- a/object/status_test.go +++ b/object/status_test.go @@ -3,9 +3,9 @@ package object_test import ( "testing" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/object" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/status" - statustest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/status/test" + "git.frostfs.info/TrueCloudLab/aarifullin/v2/object" + statusgrpc "git.frostfs.info/TrueCloudLab/aarifullin/v2/status/grpc" + statustest "git.frostfs.info/TrueCloudLab/aarifullin/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..a7101c9 100644 --- a/object/test/generate.go +++ b/object/test/generate.go @@ -1,11 +1,10 @@ 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" - refstest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs/test" - sessiontest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/session/test" + "git.frostfs.info/TrueCloudLab/aarifullin/v2/internal/random" + object "git.frostfs.info/TrueCloudLab/aarifullin/v2/object/grpc" + refstest "git.frostfs.info/TrueCloudLab/aarifullin/v2/refs/test" + sessiontest "git.frostfs.info/TrueCloudLab/aarifullin/v2/session/test" ) func GenerateShortHeader(empty bool) *object.ShortHeader { @@ -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..9f62ff8 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/aarifullin/v2/refs/test" + "git.frostfs.info/TrueCloudLab/aarifullin/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..ab3a0e64d213ad8726975267ce4da6a80bf37df6 GIT binary patch literal 7702 zcmeI1-*4J55XYa%UvcUaY?N$N+SEyX*k~uAtwk!VFI68*asju&Mz#ZGRsZ*$orE8O zZk@!oOpSyTe%v{iyU*7?8{dbH3=u{sP%(oc3>Pp}(#YVDzB?Sr!$?VOBHe=19$fSW zaCX`qv^;Ohf;%=sP#9^?ejNP{AeX<3)w z$0q0RDR8nn)Ge#mH^YU&Mt1!PL8;*bQA97I%sQ`e<~~wo@35X)S|-+uKqQglj49Gf zq|uOKj91IvKgDDoDPc)BxK6D<+-yVo%yEd+;yByflEntLRu~&qbTayDs?P#E-Iwe? zQN8s_>{oXFq2g4cEtzPGb1y|9IGN9l8nE1B)N zd+p6_M_Ebig-NVX_DWuVXmfalN^>dp)g^xG3Ukz6wTb8KR;sPt;F^`&1fFx@tg2?R zWX)uOjuNXdMJf+)M>Cm|Slse$I_}u%72qsc7ux3|!R#^7z7$;8=Y7G&mV8$xPQ5mS zEt@luOx!eZ)U;dnqjsJ4^}!e?*r;}msq z1))soSUXO766~^05|^Jl?~dOe|MR(`TIfr*&@c60AS6fsrA-4Fpe56BXNCCouqpCUV)d@Ct6SZAk;USo{L8g`9nVz5 FKLFF99-9CF literal 0 HcmV?d00001 diff --git a/refs/json.go b/refs/json.go deleted file mode 100644 index 529723a..0000000 --- a/refs/json.go +++ /dev/null @@ -1,62 +0,0 @@ -package refs - -import ( - refs "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs/grpc" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message" -) - -func (a *Address) MarshalJSON() ([]byte, error) { - return message.MarshalJSON(a) -} - -func (a *Address) UnmarshalJSON(data []byte) error { - return message.UnmarshalJSON(a, data, new(refs.Address)) -} - -func (o *ObjectID) MarshalJSON() ([]byte, error) { - return message.MarshalJSON(o) -} - -func (o *ObjectID) UnmarshalJSON(data []byte) error { - return message.UnmarshalJSON(o, data, new(refs.ObjectID)) -} - -func (c *ContainerID) MarshalJSON() ([]byte, error) { - return message.MarshalJSON(c) -} - -func (c *ContainerID) UnmarshalJSON(data []byte) error { - return message.UnmarshalJSON(c, data, new(refs.ContainerID)) -} - -func (o *OwnerID) MarshalJSON() ([]byte, error) { - return message.MarshalJSON(o) -} - -func (o *OwnerID) UnmarshalJSON(data []byte) error { - return message.UnmarshalJSON(o, data, new(refs.OwnerID)) -} - -func (v *Version) MarshalJSON() ([]byte, error) { - return message.MarshalJSON(v) -} - -func (v *Version) UnmarshalJSON(data []byte) error { - return message.UnmarshalJSON(v, data, new(refs.Version)) -} - -func (s *Signature) MarshalJSON() ([]byte, error) { - return message.MarshalJSON(s) -} - -func (s *Signature) UnmarshalJSON(data []byte) error { - return message.UnmarshalJSON(s, data, new(refs.Signature)) -} - -func (c *Checksum) MarshalJSON() ([]byte, error) { - return message.MarshalJSON(c) -} - -func (c *Checksum) UnmarshalJSON(data []byte) error { - return message.UnmarshalJSON(c, data, new(refs.Checksum)) -} diff --git a/refs/marshal.go b/refs/marshal.go deleted file mode 100644 index 0382190..0000000 --- a/refs/marshal.go +++ /dev/null @@ -1,263 +0,0 @@ -package refs - -import ( - "encoding/binary" - - refs "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs/grpc" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/util/proto" -) - -const ( - ownerIDValField = 1 - - containerIDValField = 1 - - objectIDValField = 1 - - addressContainerField = 1 - addressObjectField = 2 - - checksumTypeField = 1 - checksumValueField = 2 - - signatureKeyField = 1 - signatureValueField = 2 - signatureSchemeField = 3 - - versionMajorField = 1 - versionMinorField = 2 -) - -func (o *OwnerID) StableMarshal(buf []byte) []byte { - if o == nil { - return []byte{} - } - - if buf == nil { - buf = make([]byte, o.StableSize()) - } - - proto.BytesMarshal(ownerIDValField, buf, o.val) - - return buf -} - -func (o *OwnerID) StableSize() int { - if o == nil { - return 0 - } - - return proto.BytesSize(ownerIDValField, o.val) -} - -func (o *OwnerID) Unmarshal(data []byte) error { - return message.Unmarshal(o, data, new(refs.OwnerID)) -} - -func (c *ContainerID) StableMarshal(buf []byte) []byte { - if c == nil { - return []byte{} - } - - if buf == nil { - buf = make([]byte, c.StableSize()) - } - - proto.BytesMarshal(containerIDValField, buf, c.val) - - return buf -} - -func (c *ContainerID) StableSize() int { - if c == nil { - return 0 - } - - return proto.BytesSize(containerIDValField, c.val) -} - -func (c *ContainerID) Unmarshal(data []byte) error { - return message.Unmarshal(c, data, new(refs.ContainerID)) -} - -func (o *ObjectID) StableMarshal(buf []byte) []byte { - if o == nil { - return []byte{} - } - - if buf == nil { - buf = make([]byte, o.StableSize()) - } - - proto.BytesMarshal(objectIDValField, buf, o.val) - - return buf -} - -// ObjectIDNestedListSize returns byte length of nested -// repeated ObjectID field with fNum number. -func ObjectIDNestedListSize(fNum int64, ids []ObjectID) (sz int) { - for i := range ids { - sz += proto.NestedStructureSize(fNum, &ids[i]) - } - - return -} - -func (o *ObjectID) StableSize() int { - if o == nil { - return 0 - } - - return proto.BytesSize(objectIDValField, o.val) -} - -// ObjectIDNestedListMarshal writes protobuf repeated ObjectID field -// with fNum number to buf. -func ObjectIDNestedListMarshal(fNum int64, buf []byte, ids []ObjectID) (off int) { - prefix, _ := proto.NestedStructurePrefix(fNum) - for i := range ids { - off += binary.PutUvarint(buf[off:], prefix) - - n := ids[i].StableSize() - off += binary.PutUvarint(buf[off:], uint64(n)) - off += proto.BytesMarshal(objectIDValField, buf[off:], ids[i].val) - } - - return -} - -func (o *ObjectID) Unmarshal(data []byte) error { - return message.Unmarshal(o, data, new(refs.ObjectID)) -} - -func (a *Address) StableMarshal(buf []byte) []byte { - if a == nil { - return []byte{} - } - - if buf == nil { - buf = make([]byte, a.StableSize()) - } - - var offset int - - offset += proto.NestedStructureMarshal(addressContainerField, buf[offset:], a.cid) - proto.NestedStructureMarshal(addressObjectField, buf[offset:], a.oid) - - return buf -} - -func (a *Address) StableSize() (size int) { - if a == nil { - return 0 - } - - size += proto.NestedStructureSize(addressContainerField, a.cid) - size += proto.NestedStructureSize(addressObjectField, a.oid) - - return size -} - -func (a *Address) Unmarshal(data []byte) error { - return message.Unmarshal(a, data, new(refs.Address)) -} - -func (c *Checksum) StableMarshal(buf []byte) []byte { - if c == nil { - return []byte{} - } - - if buf == nil { - buf = make([]byte, c.StableSize()) - } - - var offset int - - offset += proto.EnumMarshal(checksumTypeField, buf[offset:], int32(c.typ)) - proto.BytesMarshal(checksumValueField, buf[offset:], c.sum) - - return buf -} - -func (c *Checksum) StableSize() (size int) { - if c == nil { - return 0 - } - - size += proto.EnumSize(checksumTypeField, int32(c.typ)) - size += proto.BytesSize(checksumValueField, c.sum) - - return size -} - -func (c *Checksum) Unmarshal(data []byte) error { - return message.Unmarshal(c, data, new(refs.Checksum)) -} - -func (s *Signature) StableMarshal(buf []byte) []byte { - if s == nil { - return []byte{} - } - - if buf == nil { - buf = make([]byte, s.StableSize()) - } - - var offset int - - offset += proto.BytesMarshal(signatureKeyField, buf[offset:], s.key) - offset += proto.BytesMarshal(signatureValueField, buf[offset:], s.sign) - proto.EnumMarshal(signatureSchemeField, buf[offset:], int32(s.scheme)) - - return buf -} - -func (s *Signature) StableSize() (size int) { - if s == nil { - return 0 - } - - size += proto.BytesSize(signatureKeyField, s.key) - size += proto.BytesSize(signatureValueField, s.sign) - size += proto.EnumSize(signatureSchemeField, int32(s.scheme)) - - return size -} - -func (s *Signature) Unmarshal(data []byte) error { - return message.Unmarshal(s, data, new(refs.Signature)) -} - -func (v *Version) StableMarshal(buf []byte) []byte { - if v == nil { - return []byte{} - } - - if buf == nil { - buf = make([]byte, v.StableSize()) - } - - var offset int - - offset += proto.UInt32Marshal(versionMajorField, buf[offset:], v.major) - proto.UInt32Marshal(versionMinorField, buf[offset:], v.minor) - - return buf -} - -func (v *Version) StableSize() (size int) { - if v == nil { - return 0 - } - - size += proto.UInt32Size(versionMajorField, v.major) - size += proto.UInt32Size(versionMinorField, v.minor) - - return size -} - -func (v *Version) Unmarshal(data []byte) error { - return message.Unmarshal(v, data, new(refs.Version)) -} diff --git a/refs/message_test.go b/refs/message_test.go index 69f2242..67eea13 100644 --- a/refs/message_test.go +++ b/refs/message_test.go @@ -3,19 +3,19 @@ package refs_test import ( "testing" - refstest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs/test" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message" - messagetest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message/test" + refstest "git.frostfs.info/TrueCloudLab/aarifullin/v2/refs/test" + messagetest "git.frostfs.info/TrueCloudLab/aarifullin/v2/rpc/message/test" + "google.golang.org/protobuf/proto" ) func TestMessageConvert(t *testing.T) { messagetest.TestRPCMessage(t, - func(empty bool) message.Message { return refstest.GenerateOwnerID(empty) }, - func(empty bool) message.Message { return refstest.GenerateObjectID(empty) }, - func(empty bool) message.Message { return refstest.GenerateContainerID(empty) }, - func(empty bool) message.Message { return refstest.GenerateAddress(empty) }, - func(empty bool) message.Message { return refstest.GenerateChecksum(empty) }, - func(empty bool) message.Message { return refstest.GenerateSignature(empty) }, - func(empty bool) message.Message { return refstest.GenerateVersion(empty) }, + func(empty bool) proto.Message { return refstest.GenerateOwnerID(empty) }, + func(empty bool) proto.Message { return refstest.GenerateObjectID(empty) }, + func(empty bool) proto.Message { return refstest.GenerateContainerID(empty) }, + func(empty bool) proto.Message { return refstest.GenerateAddress(empty) }, + func(empty bool) proto.Message { return refstest.GenerateChecksum(empty) }, + func(empty bool) proto.Message { return refstest.GenerateSignature(empty) }, + func(empty bool) proto.Message { return refstest.GenerateVersion(empty) }, ) } diff --git a/refs/string.go b/refs/string.go deleted file mode 100644 index 5389aa3..0000000 --- a/refs/string.go +++ /dev/null @@ -1,47 +0,0 @@ -package refs - -import ( - refs "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs/grpc" -) - -// String returns string representation of ChecksumType. -func (t ChecksumType) String() string { - return ChecksumTypeToGRPC(t).String() -} - -// FromString parses ChecksumType from a string representation. -// It is a reverse action to String(). -// -// Returns true if s was parsed successfully. -func (t *ChecksumType) FromString(s string) bool { - var g refs.ChecksumType - - ok := g.FromString(s) - - if ok { - *t = ChecksumTypeFromGRPC(g) - } - - return ok -} - -// String returns string representation of SignatureScheme. -func (t SignatureScheme) String() string { - return refs.SignatureScheme(t).String() -} - -// FromString parses SignatureScheme from a string representation. -// It is a reverse action to String(). -// -// Returns true if s was parsed successfully. -func (t *SignatureScheme) FromString(s string) bool { - var g refs.SignatureScheme - - ok := g.FromString(s) - - if ok { - *t = SignatureScheme(g) - } - - return ok -} diff --git a/refs/test/generate.go b/refs/test/generate.go index 6217a96..6ebcc42 100644 --- a/refs/test/generate.go +++ b/refs/test/generate.go @@ -3,7 +3,7 @@ package refstest import ( "math/rand" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs" + refs "git.frostfs.info/TrueCloudLab/aarifullin/v2/refs/grpc" ) func GenerateVersion(empty bool) *refs.Version { @@ -31,8 +31,8 @@ func GenerateAddress(empty bool) *refs.Address { m := new(refs.Address) if !empty { - m.SetObjectID(GenerateObjectID(false)) - m.SetContainerID(GenerateContainerID(false)) + m.SetObjectId(GenerateObjectID(false)) + m.SetContainerId(GenerateContainerID(false)) } return m @@ -48,13 +48,13 @@ func GenerateObjectID(empty bool) *refs.ObjectID { return m } -func GenerateObjectIDs(empty bool) []refs.ObjectID { - var ids []refs.ObjectID +func GenerateObjectIDs(empty bool) []*refs.ObjectID { + var ids []*refs.ObjectID if !empty { ids = append(ids, - *GenerateObjectID(false), - *GenerateObjectID(false), + GenerateObjectID(false), + GenerateObjectID(false), ) } @@ -71,13 +71,13 @@ func GenerateContainerID(empty bool) *refs.ContainerID { return m } -func GenerateContainerIDs(empty bool) []refs.ContainerID { - var res []refs.ContainerID +func GenerateContainerIDs(empty bool) []*refs.ContainerID { + var res []*refs.ContainerID if !empty { res = append(res, - *GenerateContainerID(false), - *GenerateContainerID(false), + GenerateContainerID(false), + GenerateContainerID(false), ) } @@ -96,11 +96,22 @@ func GenerateSignature(empty bool) *refs.Signature { return m } +func GenerateSignatureRFC6979(empty bool) *refs.SignatureRFC6979 { + m := new(refs.SignatureRFC6979) + + if !empty { + m.SetKey([]byte{1}) + m.SetSign([]byte{2}) + } + + return m +} + func GenerateChecksum(empty bool) *refs.Checksum { m := new(refs.Checksum) if !empty { - m.SetType(1) + m.SetChecksumType(1) m.SetSum([]byte{1, 2, 3}) } diff --git a/refs/types.go b/refs/types.go deleted file mode 100644 index d8f0d9b..0000000 --- a/refs/types.go +++ /dev/null @@ -1,194 +0,0 @@ -package refs - -type OwnerID struct { - val []byte -} - -type ContainerID struct { - val []byte -} - -type ObjectID struct { - val []byte -} - -type Address struct { - cid *ContainerID - - oid *ObjectID -} - -type Checksum struct { - typ ChecksumType - - sum []byte -} - -type ChecksumType uint32 - -type SignatureScheme uint32 - -//nolint:revive -const ( - ECDSA_SHA512 SignatureScheme = iota - ECDSA_RFC6979_SHA256 - ECDSA_RFC6979_SHA256_WALLET_CONNECT -) - -type Signature struct { - key, sign []byte - scheme SignatureScheme -} - -type Version struct { - major, minor uint32 -} - -const ( - UnknownChecksum ChecksumType = iota - TillichZemor - SHA256 -) - -func (o *OwnerID) GetValue() []byte { - if o != nil { - return o.val - } - - return nil -} - -func (o *OwnerID) SetValue(v []byte) { - o.val = v -} - -func (c *ContainerID) GetValue() []byte { - if c != nil { - return c.val - } - - return nil -} - -func (c *ContainerID) SetValue(v []byte) { - c.val = v -} - -func (o *ObjectID) GetValue() []byte { - if o != nil { - return o.val - } - - return nil -} - -func (o *ObjectID) SetValue(v []byte) { - o.val = v -} - -func (a *Address) GetContainerID() *ContainerID { - if a != nil { - return a.cid - } - - return nil -} - -func (a *Address) SetContainerID(v *ContainerID) { - a.cid = v -} - -func (a *Address) GetObjectID() *ObjectID { - if a != nil { - return a.oid - } - - return nil -} - -func (a *Address) SetObjectID(v *ObjectID) { - a.oid = v -} - -func (c *Checksum) GetType() ChecksumType { - if c != nil { - return c.typ - } - - return UnknownChecksum -} - -func (c *Checksum) SetType(v ChecksumType) { - c.typ = v -} - -func (c *Checksum) GetSum() []byte { - if c != nil { - return c.sum - } - - return nil -} - -func (c *Checksum) SetSum(v []byte) { - c.sum = v -} - -func (s *Signature) GetKey() []byte { - if s != nil { - return s.key - } - - return nil -} - -func (s *Signature) SetKey(v []byte) { - s.key = v -} - -func (s *Signature) GetSign() []byte { - if s != nil { - return s.sign - } - - return nil -} - -func (s *Signature) SetSign(v []byte) { - s.sign = v -} - -func (s *Signature) GetScheme() SignatureScheme { - if s != nil { - return s.scheme - } - return 0 -} - -func (s *Signature) SetScheme(scheme SignatureScheme) { - s.scheme = scheme -} - -func (v *Version) GetMajor() uint32 { - if v != nil { - return v.major - } - - return 0 -} - -func (v *Version) SetMajor(val uint32) { - v.major = val -} - -func (v *Version) GetMinor() uint32 { - if v != nil { - return v.minor - } - - return 0 -} - -func (v *Version) SetMinor(val uint32) { - v.minor = val -} diff --git a/rpc/accounting.go b/rpc/accounting.go index 4f324c9..6fcafb4 100644 --- a/rpc/accounting.go +++ b/rpc/accounting.go @@ -1,9 +1,9 @@ package rpc import ( - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/accounting" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/client" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/common" + accounting "git.frostfs.info/TrueCloudLab/aarifullin/v2/accounting/grpc" + "git.frostfs.info/TrueCloudLab/aarifullin/v2/rpc/client" + "git.frostfs.info/TrueCloudLab/aarifullin/v2/rpc/common" ) const serviceAccounting = serviceNamePrefix + "accounting.AccountingService" diff --git a/rpc/client/flows.go b/rpc/client/flows.go index a3da1e2..1c561d1 100644 --- a/rpc/client/flows.go +++ b/rpc/client/flows.go @@ -5,13 +5,13 @@ import ( "io" "sync" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/common" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message" + "git.frostfs.info/TrueCloudLab/aarifullin/v2/rpc/common" + "google.golang.org/protobuf/proto" ) // SendUnary initializes communication session by RPC info, performs unary RPC // and closes the session. -func SendUnary(cli *Client, info common.CallMethodInfo, req, resp message.Message, opts ...CallOption) error { +func SendUnary(cli *Client, info common.CallMethodInfo, req, resp proto.Message, opts ...CallOption) error { rw, err := cli.Init(info, opts...) if err != nil { return err @@ -40,7 +40,7 @@ type MessageWriterCloser interface { type clientStreamWriterCloser struct { MessageReadWriter - resp message.Message + resp proto.Message } func (c *clientStreamWriterCloser) Close() error { @@ -56,7 +56,7 @@ func (c *clientStreamWriterCloser) Close() error { // and returns its interface. // // All stream writes must be performed before the closing. Close must be called once. -func OpenClientStream(cli *Client, info common.CallMethodInfo, resp message.Message, opts ...CallOption) (MessageWriterCloser, error) { +func OpenClientStream(cli *Client, info common.CallMethodInfo, resp proto.Message, opts ...CallOption) (MessageWriterCloser, error) { rw, err := cli.Init(info, opts...) if err != nil { return nil, err @@ -80,10 +80,10 @@ type serverStreamReaderCloser struct { once sync.Once - req message.Message + req proto.Message } -func (s *serverStreamReaderCloser) ReadMessage(msg message.Message) error { +func (s *serverStreamReaderCloser) ReadMessage(msg proto.Message) error { var err error s.once.Do(func() { @@ -111,7 +111,7 @@ func (s *serverStreamReaderCloser) ReadMessage(msg message.Message) error { // and returns its interface. // // All stream reads must be performed before the closing. Close must be called once. -func OpenServerStream(cli *Client, info common.CallMethodInfo, req message.Message, opts ...CallOption) (MessageReader, error) { +func OpenServerStream(cli *Client, info common.CallMethodInfo, req proto.Message, opts ...CallOption) (MessageReader, error) { rw, err := cli.Init(info, opts...) if err != nil { return nil, err diff --git a/rpc/client/init.go b/rpc/client/init.go index 60ccda9..6ee4f11 100644 --- a/rpc/client/init.go +++ b/rpc/client/init.go @@ -4,9 +4,9 @@ import ( "context" "io" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/common" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message" + "git.frostfs.info/TrueCloudLab/aarifullin/v2/rpc/common" "google.golang.org/grpc" + "google.golang.org/protobuf/proto" ) // MessageReader is an interface of the Message reader. @@ -15,7 +15,7 @@ type MessageReader interface { // // Returns io.EOF if there are no more messages to read. // ReadMessage should not be called after io.EOF occasion. - ReadMessage(message.Message) error + ReadMessage(proto.Message) error } // MessageWriter is an interface of the Message writer. @@ -23,7 +23,7 @@ type MessageWriter interface { // WriteMessage writers the next Message. // // WriteMessage should not be called after any error. - WriteMessage(message.Message) error + WriteMessage(proto.Message) error } // MessageReadWriter is a component interface diff --git a/rpc/client/stream_wrapper.go b/rpc/client/stream_wrapper.go index 22033dd..3cc8d68 100644 --- a/rpc/client/stream_wrapper.go +++ b/rpc/client/stream_wrapper.go @@ -4,8 +4,8 @@ import ( "context" "time" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message" "google.golang.org/grpc" + "google.golang.org/protobuf/proto" ) type streamWrapper struct { @@ -14,23 +14,15 @@ type streamWrapper struct { cancel context.CancelFunc } -func (w streamWrapper) ReadMessage(m message.Message) error { - // Can be optimized: we can create blank message here. - gm := m.ToGRPCMessage() - - err := w.withTimeout(func() error { - return w.ClientStream.RecvMsg(gm) +func (w streamWrapper) ReadMessage(m proto.Message) error { + return w.withTimeout(func() error { + return w.ClientStream.RecvMsg(m) }) - if err != nil { - return err - } - - return m.FromGRPCMessage(gm) } -func (w streamWrapper) WriteMessage(m message.Message) error { +func (w streamWrapper) WriteMessage(m proto.Message) error { return w.withTimeout(func() error { - return w.ClientStream.SendMsg(m.ToGRPCMessage()) + return w.ClientStream.SendMsg(m) }) } diff --git a/rpc/client/util.go b/rpc/client/util.go index 95dc2b0..9313a1c 100644 --- a/rpc/client/util.go +++ b/rpc/client/util.go @@ -3,7 +3,7 @@ package client import ( "fmt" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/common" + "git.frostfs.info/TrueCloudLab/aarifullin/v2/rpc/common" ) const methodNameFmt = "/%s/%s" diff --git a/rpc/common/call_test.go b/rpc/common/call_test.go index 942ee02..51a1002 100644 --- a/rpc/common/call_test.go +++ b/rpc/common/call_test.go @@ -3,7 +3,7 @@ package common_test import ( "testing" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/common" + "git.frostfs.info/TrueCloudLab/aarifullin/v2/rpc/common" "github.com/stretchr/testify/require" ) diff --git a/rpc/container.go b/rpc/container.go index 1292c22..2856e52 100644 --- a/rpc/container.go +++ b/rpc/container.go @@ -1,9 +1,9 @@ package rpc import ( - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/container" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/client" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/common" + container "git.frostfs.info/TrueCloudLab/aarifullin/v2/container/grpc" + "git.frostfs.info/TrueCloudLab/aarifullin/v2/rpc/client" + "git.frostfs.info/TrueCloudLab/aarifullin/v2/rpc/common" ) const serviceContainer = serviceNamePrefix + "container.ContainerService" diff --git a/rpc/message/encoding.go b/rpc/message/encoding.go index 715f015..214f6a0 100644 --- a/rpc/message/encoding.go +++ b/rpc/message/encoding.go @@ -1,7 +1,7 @@ package message import ( - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/grpc" + "git.frostfs.info/TrueCloudLab/aarifullin/v2/rpc/grpc" "google.golang.org/protobuf/encoding/protojson" "google.golang.org/protobuf/proto" ) diff --git a/rpc/message/message.go b/rpc/message/message.go index 705270e..de68c6c 100644 --- a/rpc/message/message.go +++ b/rpc/message/message.go @@ -3,7 +3,7 @@ package message import ( "fmt" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/grpc" + "git.frostfs.info/TrueCloudLab/aarifullin/v2/rpc/grpc" ) // Message represents raw Protobuf message diff --git a/rpc/message/test/message.go b/rpc/message/test/message.go index df769d2..23e53e2 100644 --- a/rpc/message/test/message.go +++ b/rpc/message/test/message.go @@ -1,65 +1,44 @@ package messagetest import ( - "encoding/json" - "errors" "fmt" "testing" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message" + utilproto "git.frostfs.info/TrueCloudLab/aarifullin/v2/util/proto" "github.com/stretchr/testify/require" + "google.golang.org/protobuf/encoding/protojson" + "google.golang.org/protobuf/proto" ) -type jsonMessage interface { - json.Marshaler - json.Unmarshaler -} - -type binaryMessage interface { - StableMarshal([]byte) []byte - Unmarshal([]byte) error -} - -func TestRPCMessage(t *testing.T, msgGens ...func(empty bool) message.Message) { +func TestRPCMessage(t *testing.T, msgGens ...func(empty bool) proto.Message) { for _, msgGen := range msgGens { - msg := msgGen(false) - - t.Run(fmt.Sprintf("convert_%T", msg), func(t *testing.T) { - msg := msgGen(false) - - err := msg.FromGRPCMessage(100) - - require.True(t, errors.As(err, new(message.ErrUnexpectedMessageType))) - - msg2 := msgGen(true) - - err = msg2.FromGRPCMessage(msg.ToGRPCMessage()) - require.NoError(t, err) - - require.Equal(t, msg, msg2) - }) + msg1 := msgGen(false) t.Run("encoding", func(t *testing.T) { - if jm, ok := msg.(jsonMessage); ok { - t.Run(fmt.Sprintf("JSON_%T", msg), func(t *testing.T) { - data, err := jm.MarshalJSON() - require.NoError(t, err) + t.Run(fmt.Sprintf("JSON_%T", msg1), func(t *testing.T) { + data, err := protojson.MarshalOptions{ + EmitUnpopulated: true, + }.Marshal( + msg1, + ) + require.NoError(t, err) - jm2 := msgGen(true).(jsonMessage) - require.NoError(t, jm2.UnmarshalJSON(data)) + msg2 := msgGen(true) + require.NoError(t, protojson.Unmarshal(data, msg2)) - require.Equal(t, jm, jm2) - }) - } + require.True(t, proto.Equal(msg1, msg2)) + }) - if bm, ok := msg.(binaryMessage); ok { - t.Run(fmt.Sprintf("Binary_%T", msg), func(t *testing.T) { + if bm, ok := msg1.(utilproto.StableMarshaller); ok { + t.Run(fmt.Sprintf("Stable_%T", msg1), func(t *testing.T) { data := bm.StableMarshal(nil) - bm2 := msgGen(true).(binaryMessage) - require.NoError(t, bm2.Unmarshal(data)) + require.Len(t, data, bm.StableSize()) - require.Equal(t, bm, bm2) + msg2 := msgGen(true) + require.NoError(t, proto.Unmarshal(data, msg2)) + + require.True(t, proto.Equal(msg1, msg2)) }) } }) diff --git a/rpc/netmap.go b/rpc/netmap.go index 38bdd6d..a92d43f 100644 --- a/rpc/netmap.go +++ b/rpc/netmap.go @@ -1,9 +1,9 @@ package rpc import ( - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/netmap" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/client" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/common" + netmap "git.frostfs.info/TrueCloudLab/aarifullin/v2/netmap/grpc" + "git.frostfs.info/TrueCloudLab/aarifullin/v2/rpc/client" + "git.frostfs.info/TrueCloudLab/aarifullin/v2/rpc/common" ) const serviceNetmap = serviceNamePrefix + "netmap.NetmapService" @@ -49,10 +49,10 @@ func NetworkInfo( // NetMapSnapshot executes NetmapService.NetmapSnapshot RPC. func NetMapSnapshot( cli *client.Client, - req *netmap.SnapshotRequest, + req *netmap.NetmapSnapshotRequest, opts ...client.CallOption, -) (*netmap.SnapshotResponse, error) { - resp := new(netmap.SnapshotResponse) +) (*netmap.NetmapSnapshotResponse, error) { + resp := new(netmap.NetmapSnapshotResponse) err := client.SendUnary(cli, common.CallMethodInfoUnary(serviceNetmap, rpcNetmapSnapshot), req, resp, opts...) if err != nil { diff --git a/rpc/object.go b/rpc/object.go index 1eca922..0923169 100644 --- a/rpc/object.go +++ b/rpc/object.go @@ -1,10 +1,10 @@ package rpc import ( - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/object" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/client" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/common" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message" + object "git.frostfs.info/TrueCloudLab/aarifullin/v2/object/grpc" + "git.frostfs.info/TrueCloudLab/aarifullin/v2/rpc/client" + "git.frostfs.info/TrueCloudLab/aarifullin/v2/rpc/common" + "google.golang.org/protobuf/proto" ) const serviceObject = serviceNamePrefix + "object.ObjectService" @@ -25,7 +25,7 @@ const ( type PutRequestWriter struct { wc client.MessageWriterCloser - resp message.Message + resp proto.Message } // Write writes req to the stream. diff --git a/rpc/session.go b/rpc/session.go index f786734..1af0798 100644 --- a/rpc/session.go +++ b/rpc/session.go @@ -1,9 +1,9 @@ package rpc import ( - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/client" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/common" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/session" + "git.frostfs.info/TrueCloudLab/aarifullin/v2/rpc/client" + "git.frostfs.info/TrueCloudLab/aarifullin/v2/rpc/common" + session "git.frostfs.info/TrueCloudLab/aarifullin/v2/session/grpc" ) const serviceSession = serviceNamePrefix + "session.SessionService" diff --git a/session/convert.go b/session/convert.go deleted file mode 100644 index 870e208..0000000 --- a/session/convert.go +++ /dev/null @@ -1,893 +0,0 @@ -package session - -import ( - "fmt" - - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/acl" - aclGRPC "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/acl/grpc" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs" - refsGRPC "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs/grpc" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/grpc" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message" - session "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/session/grpc" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/status" - statusGRPC "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/status/grpc" -) - -func (c *CreateRequestBody) ToGRPCMessage() grpc.Message { - var m *session.CreateRequest_Body - - if c != nil { - m = new(session.CreateRequest_Body) - - m.SetOwnerId(c.ownerID.ToGRPCMessage().(*refsGRPC.OwnerID)) - m.SetExpiration(c.expiration) - } - - return m -} - -func (c *CreateRequestBody) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*session.CreateRequest_Body) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var err error - - ownerID := v.GetOwnerId() - if ownerID == nil { - c.ownerID = nil - } else { - if c.ownerID == nil { - c.ownerID = new(refs.OwnerID) - } - - err = c.ownerID.FromGRPCMessage(ownerID) - if err != nil { - return err - } - } - - c.expiration = v.GetExpiration() - - return nil -} - -func (c *CreateRequest) ToGRPCMessage() grpc.Message { - var m *session.CreateRequest - - if c != nil { - m = new(session.CreateRequest) - - m.SetBody(c.body.ToGRPCMessage().(*session.CreateRequest_Body)) - c.RequestHeaders.ToMessage(m) - } - - return m -} - -func (c *CreateRequest) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*session.CreateRequest) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var err error - - body := v.GetBody() - if body == nil { - c.body = nil - } else { - if c.body == nil { - c.body = new(CreateRequestBody) - } - - err = c.body.FromGRPCMessage(body) - if err != nil { - return err - } - } - - return c.RequestHeaders.FromMessage(v) -} - -func (c *CreateResponseBody) ToGRPCMessage() grpc.Message { - var m *session.CreateResponse_Body - - if c != nil { - m = new(session.CreateResponse_Body) - - m.SetSessionKey(c.sessionKey) - m.SetId(c.id) - } - - return m -} - -func (c *CreateResponseBody) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*session.CreateResponse_Body) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - c.sessionKey = v.GetSessionKey() - c.id = v.GetId() - - return nil -} - -func (c *CreateResponse) ToGRPCMessage() grpc.Message { - var m *session.CreateResponse - - if c != nil { - m = new(session.CreateResponse) - - m.SetBody(c.body.ToGRPCMessage().(*session.CreateResponse_Body)) - c.ResponseHeaders.ToMessage(m) - } - - return m -} - -func (c *CreateResponse) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*session.CreateResponse) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var err error - - body := v.GetBody() - if body == nil { - c.body = nil - } else { - if c.body == nil { - c.body = new(CreateResponseBody) - } - - err = c.body.FromGRPCMessage(body) - if err != nil { - return err - } - } - - return c.ResponseHeaders.FromMessage(v) -} - -func (l *TokenLifetime) ToGRPCMessage() grpc.Message { - var m *session.SessionToken_Body_TokenLifetime - - if l != nil { - m = new(session.SessionToken_Body_TokenLifetime) - - m.SetExp(l.exp) - m.SetIat(l.iat) - m.SetNbf(l.nbf) - } - - return m -} - -func (l *TokenLifetime) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*session.SessionToken_Body_TokenLifetime) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - l.exp = v.GetExp() - l.iat = v.GetIat() - l.nbf = v.GetNbf() - - return nil -} - -func (x *XHeader) ToGRPCMessage() grpc.Message { - var m *session.XHeader - - if x != nil { - m = new(session.XHeader) - - m.SetKey(x.key) - m.SetValue(x.val) - } - - return m -} - -func (x *XHeader) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*session.XHeader) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - x.key = v.GetKey() - x.val = v.GetValue() - - return nil -} - -func XHeadersToGRPC(xs []XHeader) (res []*session.XHeader) { - if xs != nil { - res = make([]*session.XHeader, 0, len(xs)) - - for i := range xs { - res = append(res, xs[i].ToGRPCMessage().(*session.XHeader)) - } - } - - return -} - -func XHeadersFromGRPC(xs []*session.XHeader) (res []XHeader, err error) { - if xs != nil { - res = make([]XHeader, len(xs)) - - for i := range xs { - if xs[i] != nil { - err = res[i].FromGRPCMessage(xs[i]) - if err != nil { - return - } - } - } - } - - return -} - -func (t *Token) ToGRPCMessage() grpc.Message { - var m *session.SessionToken - - if t != nil { - m = new(session.SessionToken) - - m.SetBody(t.body.ToGRPCMessage().(*session.SessionToken_Body)) - m.SetSignature(t.sig.ToGRPCMessage().(*refsGRPC.Signature)) - } - - return m -} - -func (t *Token) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*session.SessionToken) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var err error - - body := v.GetBody() - if body == nil { - t.body = nil - } else { - if t.body == nil { - t.body = new(TokenBody) - } - - err = t.body.FromGRPCMessage(body) - if err != nil { - return err - } - } - - sig := v.GetSignature() - if sig == nil { - t.sig = nil - } else { - if t.sig == nil { - t.sig = new(refs.Signature) - } - - err = t.sig.FromGRPCMessage(sig) - if err != nil { - return err - } - } - - return nil -} - -func (r *RequestVerificationHeader) ToGRPCMessage() grpc.Message { - var m *session.RequestVerificationHeader - - if r != nil { - m = new(session.RequestVerificationHeader) - - m.SetBodySignature(r.bodySig.ToGRPCMessage().(*refsGRPC.Signature)) - m.SetMetaSignature(r.metaSig.ToGRPCMessage().(*refsGRPC.Signature)) - m.SetOriginSignature(r.originSig.ToGRPCMessage().(*refsGRPC.Signature)) - m.SetOrigin(r.origin.ToGRPCMessage().(*session.RequestVerificationHeader)) - } - - return m -} - -func (r *RequestVerificationHeader) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*session.RequestVerificationHeader) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var err error - - originSig := v.GetOriginSignature() - if originSig == nil { - r.originSig = nil - } else { - if r.originSig == nil { - r.originSig = new(refs.Signature) - } - - err = r.originSig.FromGRPCMessage(originSig) - if err != nil { - return err - } - } - - metaSig := v.GetMetaSignature() - if metaSig == nil { - r.metaSig = nil - } else { - if r.metaSig == nil { - r.metaSig = new(refs.Signature) - } - - err = r.metaSig.FromGRPCMessage(metaSig) - if err != nil { - return err - } - } - - bodySig := v.GetBodySignature() - if bodySig == nil { - r.bodySig = nil - } else { - if r.bodySig == nil { - r.bodySig = new(refs.Signature) - } - - err = r.bodySig.FromGRPCMessage(bodySig) - if err != nil { - return err - } - } - - origin := v.GetOrigin() - if origin == nil { - r.origin = nil - } else { - if r.origin == nil { - r.origin = new(RequestVerificationHeader) - } - - err = r.origin.FromGRPCMessage(origin) - if err != nil { - return err - } - } - - return nil -} - -func (r *RequestMetaHeader) ToGRPCMessage() grpc.Message { - var m *session.RequestMetaHeader - - if r != nil { - m = new(session.RequestMetaHeader) - - m.SetVersion(r.version.ToGRPCMessage().(*refsGRPC.Version)) - m.SetSessionToken(r.sessionToken.ToGRPCMessage().(*session.SessionToken)) - m.SetBearerToken(r.bearerToken.ToGRPCMessage().(*aclGRPC.BearerToken)) - m.SetXHeaders(XHeadersToGRPC(r.xHeaders)) - m.SetEpoch(r.epoch) - m.SetTtl(r.ttl) - m.SetOrigin(r.origin.ToGRPCMessage().(*session.RequestMetaHeader)) - m.SetNetworkMagic(r.netMagic) - } - - return m -} - -func (r *RequestMetaHeader) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*session.RequestMetaHeader) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var err error - - version := v.GetVersion() - if version == nil { - r.version = nil - } else { - if r.version == nil { - r.version = new(refs.Version) - } - - err = r.version.FromGRPCMessage(version) - if err != nil { - return err - } - } - - sessionToken := v.GetSessionToken() - if sessionToken == nil { - r.sessionToken = nil - } else { - if r.sessionToken == nil { - r.sessionToken = new(Token) - } - - err = r.sessionToken.FromGRPCMessage(sessionToken) - if err != nil { - return err - } - } - - bearerToken := v.GetBearerToken() - if bearerToken == nil { - r.bearerToken = nil - } else { - if r.bearerToken == nil { - r.bearerToken = new(acl.BearerToken) - } - - err = r.bearerToken.FromGRPCMessage(bearerToken) - if err != nil { - return err - } - } - - origin := v.GetOrigin() - if origin == nil { - r.origin = nil - } else { - if r.origin == nil { - r.origin = new(RequestMetaHeader) - } - - err = r.origin.FromGRPCMessage(origin) - if err != nil { - return err - } - } - - r.xHeaders, err = XHeadersFromGRPC(v.GetXHeaders()) - if err != nil { - return err - } - - r.epoch = v.GetEpoch() - r.ttl = v.GetTtl() - r.netMagic = v.GetNetworkMagic() - - return nil -} - -func (r *ResponseVerificationHeader) ToGRPCMessage() grpc.Message { - var m *session.ResponseVerificationHeader - - if r != nil { - m = new(session.ResponseVerificationHeader) - - m.SetBodySignature(r.bodySig.ToGRPCMessage().(*refsGRPC.Signature)) - m.SetMetaSignature(r.metaSig.ToGRPCMessage().(*refsGRPC.Signature)) - m.SetOriginSignature(r.originSig.ToGRPCMessage().(*refsGRPC.Signature)) - m.SetOrigin(r.origin.ToGRPCMessage().(*session.ResponseVerificationHeader)) - } - - return m -} - -func (r *ResponseVerificationHeader) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*session.ResponseVerificationHeader) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var err error - - originSig := v.GetOriginSignature() - if originSig == nil { - r.originSig = nil - } else { - if r.originSig == nil { - r.originSig = new(refs.Signature) - } - - err = r.originSig.FromGRPCMessage(originSig) - if err != nil { - return err - } - } - - metaSig := v.GetMetaSignature() - if metaSig == nil { - r.metaSig = nil - } else { - if r.metaSig == nil { - r.metaSig = new(refs.Signature) - } - - err = r.metaSig.FromGRPCMessage(metaSig) - if err != nil { - return err - } - } - - bodySig := v.GetBodySignature() - if bodySig == nil { - r.bodySig = nil - } else { - if r.bodySig == nil { - r.bodySig = new(refs.Signature) - } - - err = r.bodySig.FromGRPCMessage(bodySig) - if err != nil { - return err - } - } - - origin := v.GetOrigin() - if origin == nil { - r.origin = nil - } else { - if r.origin == nil { - r.origin = new(ResponseVerificationHeader) - } - - err = r.origin.FromGRPCMessage(origin) - if err != nil { - return err - } - } - - return nil -} - -func (r *ResponseMetaHeader) ToGRPCMessage() grpc.Message { - var m *session.ResponseMetaHeader - - if r != nil { - m = new(session.ResponseMetaHeader) - - m.SetVersion(r.version.ToGRPCMessage().(*refsGRPC.Version)) - m.SetXHeaders(XHeadersToGRPC(r.xHeaders)) - m.SetEpoch(r.epoch) - m.SetTtl(r.ttl) - m.SetOrigin(r.origin.ToGRPCMessage().(*session.ResponseMetaHeader)) - m.SetStatus(r.status.ToGRPCMessage().(*statusGRPC.Status)) - } - - return m -} - -func (r *ResponseMetaHeader) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*session.ResponseMetaHeader) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var err error - - version := v.GetVersion() - if version == nil { - r.version = nil - } else { - if r.version == nil { - r.version = new(refs.Version) - } - - err = r.version.FromGRPCMessage(version) - if err != nil { - return err - } - } - - origin := v.GetOrigin() - if origin == nil { - r.origin = nil - } else { - if r.origin == nil { - r.origin = new(ResponseMetaHeader) - } - - err = r.origin.FromGRPCMessage(origin) - if err != nil { - return err - } - } - - st := v.GetStatus() - if st == nil { - r.status = nil - } else { - if r.status == nil { - r.status = new(status.Status) - } - - err = r.status.FromGRPCMessage(st) - if err != nil { - return err - } - } - - r.xHeaders, err = XHeadersFromGRPC(v.GetXHeaders()) - if err != nil { - return err - } - - r.epoch = v.GetEpoch() - r.ttl = v.GetTtl() - - return nil -} - -func ObjectSessionVerbToGRPCField(v ObjectSessionVerb) session.ObjectSessionContext_Verb { - switch v { - case ObjectVerbPut: - return session.ObjectSessionContext_PUT - case ObjectVerbGet: - return session.ObjectSessionContext_GET - case ObjectVerbHead: - return session.ObjectSessionContext_HEAD - case ObjectVerbSearch: - return session.ObjectSessionContext_SEARCH - case ObjectVerbDelete: - return session.ObjectSessionContext_DELETE - case ObjectVerbRange: - return session.ObjectSessionContext_RANGE - case ObjectVerbRangeHash: - return session.ObjectSessionContext_RANGEHASH - default: - return session.ObjectSessionContext_VERB_UNSPECIFIED - } -} - -func ObjectSessionVerbFromGRPCField(v session.ObjectSessionContext_Verb) ObjectSessionVerb { - switch v { - case session.ObjectSessionContext_PUT: - return ObjectVerbPut - case session.ObjectSessionContext_GET: - return ObjectVerbGet - case session.ObjectSessionContext_HEAD: - return ObjectVerbHead - case session.ObjectSessionContext_SEARCH: - return ObjectVerbSearch - case session.ObjectSessionContext_DELETE: - return ObjectVerbDelete - case session.ObjectSessionContext_RANGE: - return ObjectVerbRange - case session.ObjectSessionContext_RANGEHASH: - return ObjectVerbRangeHash - default: - return ObjectVerbUnknown - } -} - -func (c *ObjectSessionContext) ToGRPCMessage() grpc.Message { - var m *session.ObjectSessionContext - - if c != nil { - m = new(session.ObjectSessionContext) - - m.SetVerb(ObjectSessionVerbToGRPCField(c.verb)) - m.SetTarget(c.cnr.ToGRPCMessage().(*refsGRPC.ContainerID), refs.ObjectIDListToGRPCMessage(c.objs)) - } - - return m -} - -func (c *ObjectSessionContext) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*session.ObjectSessionContext) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var err error - - cnr := v.GetTarget().GetContainer() - if cnr == nil { - c.cnr = nil - } else { - if c.cnr == nil { - c.cnr = new(refs.ContainerID) - } - - err = c.cnr.FromGRPCMessage(cnr) - if err != nil { - return err - } - } - - c.objs, err = refs.ObjectIDListFromGRPCMessage(v.GetTarget().GetObjects()) - if err != nil { - return err - } - - c.verb = ObjectSessionVerbFromGRPCField(v.GetVerb()) - - return nil -} - -func (t *TokenBody) ToGRPCMessage() grpc.Message { - var m *session.SessionToken_Body - - if t != nil { - m = new(session.SessionToken_Body) - - switch typ := t.ctx.(type) { - default: - panic(fmt.Sprintf("unknown session context %T", typ)) - case nil: - m.Context = nil - case *ObjectSessionContext: - m.SetObjectSessionContext(typ.ToGRPCMessage().(*session.ObjectSessionContext)) - case *ContainerSessionContext: - m.SetContainerSessionContext(typ.ToGRPCMessage().(*session.ContainerSessionContext)) - } - - m.SetOwnerId(t.ownerID.ToGRPCMessage().(*refsGRPC.OwnerID)) - m.SetId(t.id) - m.SetSessionKey(t.sessionKey) - m.SetLifetime(t.lifetime.ToGRPCMessage().(*session.SessionToken_Body_TokenLifetime)) - } - - return m -} - -func (t *TokenBody) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*session.SessionToken_Body) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var err error - - t.ctx = nil - - switch val := v.GetContext().(type) { - default: - err = fmt.Errorf("unknown session context %T", val) - case nil: - case *session.SessionToken_Body_Object: - ctx, ok := t.ctx.(*ObjectSessionContext) - if !ok { - ctx = new(ObjectSessionContext) - t.ctx = ctx - } - - err = ctx.FromGRPCMessage(val.Object) - case *session.SessionToken_Body_Container: - ctx, ok := t.ctx.(*ContainerSessionContext) - if !ok { - ctx = new(ContainerSessionContext) - t.ctx = ctx - } - - err = ctx.FromGRPCMessage(val.Container) - } - - if err != nil { - return err - } - - ownerID := v.GetOwnerId() - if ownerID == nil { - t.ownerID = nil - } else { - if t.ownerID == nil { - t.ownerID = new(refs.OwnerID) - } - - err = t.ownerID.FromGRPCMessage(ownerID) - if err != nil { - return err - } - } - - lifetime := v.GetLifetime() - if lifetime == nil { - t.lifetime = nil - } else { - if t.lifetime == nil { - t.lifetime = new(TokenLifetime) - } - - err = t.lifetime.FromGRPCMessage(lifetime) - if err != nil { - return err - } - } - - t.id = v.GetId() - t.sessionKey = v.GetSessionKey() - - return nil -} - -// ContainerSessionVerbToGRPCField converts ContainerSessionVerb -// to gRPC-generated session.ContainerSessionContext_Verb. -// -// If v is outside of the ContainerSessionVerb enum, -// session.ContainerSessionContext_VERB_UNSPECIFIED is returned. -func ContainerSessionVerbToGRPCField(v ContainerSessionVerb) session.ContainerSessionContext_Verb { - switch v { - default: - return session.ContainerSessionContext_VERB_UNSPECIFIED - case ContainerVerbPut: - return session.ContainerSessionContext_PUT - case ContainerVerbDelete: - return session.ContainerSessionContext_DELETE - case ContainerVerbSetEACL: - return session.ContainerSessionContext_SETEACL - } -} - -// ContainerSessionVerbFromGRPCField converts gRPC-generated -// session.ContainerSessionContext_Verb to ContainerSessionVerb. -// -// If v is outside of the session.ContainerSessionContext_Verb enum, -// ContainerVerbUnknown is returned. -func ContainerSessionVerbFromGRPCField(v session.ContainerSessionContext_Verb) ContainerSessionVerb { - switch v { - default: - return ContainerVerbUnknown - case session.ContainerSessionContext_PUT: - return ContainerVerbPut - case session.ContainerSessionContext_DELETE: - return ContainerVerbDelete - case session.ContainerSessionContext_SETEACL: - return ContainerVerbSetEACL - } -} - -// ToGRPCMessage converts ContainerSessionContext to gRPC-generated -// session.ContainerSessionContext message. -func (x *ContainerSessionContext) ToGRPCMessage() grpc.Message { - var m *session.ContainerSessionContext - - if x != nil { - m = new(session.ContainerSessionContext) - - m.SetVerb(ContainerSessionVerbToGRPCField(x.verb)) - m.SetWildcard(x.wildcard) - m.SetContainerId(x.cid.ToGRPCMessage().(*refsGRPC.ContainerID)) - } - - return m -} - -// FromGRPCMessage tries to restore ContainerSessionContext from grpc.Message. -// -// Returns message.ErrUnexpectedMessageType if m is not -// a gRPC-generated session.ContainerSessionContext message. -func (x *ContainerSessionContext) FromGRPCMessage(m grpc.Message) error { - v, ok := m.(*session.ContainerSessionContext) - if !ok { - return message.NewUnexpectedMessageType(m, v) - } - - var err error - - cid := v.GetContainerId() - if cid == nil { - x.cid = nil - } else { - if x.cid == nil { - x.cid = new(refs.ContainerID) - } - - err = x.cid.FromGRPCMessage(cid) - if err != nil { - return err - } - } - - x.verb = ContainerSessionVerbFromGRPCField(v.GetVerb()) - x.wildcard = v.GetWildcard() - - return nil -} diff --git a/session/grpc/service.go b/session/grpc/service.go index 6e02328..120bb8f 100644 --- a/session/grpc/service.go +++ b/session/grpc/service.go @@ -1,7 +1,7 @@ package session import ( - refs "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs/grpc" + refs "git.frostfs.info/TrueCloudLab/aarifullin/v2/refs/grpc" ) // SetOwnerId sets identifier of the session initiator. diff --git a/session/grpc/service.pb.go b/session/grpc/service.pb.go index 5ba114df5f8f6c5b0f406782c16cfca2eae69574..233eb3e473664f2bb1d2a439f8908abfbc912931 100644 GIT binary patch delta 57 zcmccK$9TDqaYC@1v4Nfem%hFNXF*YZNq({d6qFh385-%COe{?2N=z)uOe@XF$;{jM Htk4Yr?eP*f delta 61 zcmccI$9TPuaYC@1k%gWim%hFNXF*YZNq({d6qFh385!zXPAp94ODoDRE=eoaO)SXN LP0!!>sL%}nI6M=M diff --git a/session/grpc/service_frostfs.pb.go b/session/grpc/service_frostfs.pb.go new file mode 100644 index 0000000000000000000000000000000000000000..d1d71fc526a3b1608265602ae3e2c6aa89794345 GIT binary patch literal 4425 zcmeH~-)q}25XYb6zvAeVv$gTojXezd(jTy}wSgwvODRLK&xxobWs;o4EB)VhlB_oI z+|j|xQV0b6>rOh~eeRoclE8_~5GE*4F@qV5E0`;3WO_jN4kq#-S5li?_uzB@7lRR; zo%Tn)D4MhMhD{JOYR#pHB0if-Wngc@O)vOxk;`PHN<1lKnSEj7gfYeQvM9Jn7Kce` zc#*j6_M#|BU})I5z#;#MpwN^`XfRXS!`_fNtbhw2-MGvlmukjLkNmu=DpPVn4NGpO z-jB@?a*jm?3s#i$Xv!A&@Mz2hQoM@WNhpeBkgV>fA*gXZiZb2i?1%1u+|%I#TUw+Go$_O1reznUX3) z6|&mTfl{5Lf&#^a(#kcRXUe#oc`nxD4iG$BIIxmZ`AVWnEGxDnO;A0u-q% zg+WE&EvG!4LdG)?(m3ZOEEP9gOkBk>W*DS$HZRa%QQ1XdKy;`j*SNpIOC2)7;up0H zId_W6E@@DNnC^@5_t*sfo&Zi=lGtK>OcI)FG2=a!vL=pXnGV8p?nY*MS-(c)5 zEgrF_TYj{k9E0NlCZR3_~Hn6pn zZ&cBO{hzx2*&E)eO0(PBy&gK{BZ9_+5rHKcq2UtE1eZKIfX@!b{2&%Qm2n!P z_kDEPAE2}M=Yuc^W;nXXV}eqWrj)ZFpwk%_61^Hz8Co04V%{5wjGQJs8-2jT9>#*k zS&~rJdpPW6k|sSp-K!wz_0YA%!-QPZPXq}fGr>|MCoqTlfX8ToC^OLwvlzu(OtB2X z&X|fU0uz#=Ih7M*ho=O^lq4hcfRhaVG{FyK{ih*iSS+>sFo-i2q0R!m?hpSWk-Rp~ zb;_9}3wbxdVoYSW5Mif_Iyx}Q;PcPH9#sJzA0tK+^>)uZ0s21J`x5Nwk>4Gg=)+5r z!dhR;JY@C2ogenmB2?313c2V8d+>aSqIbtgU$ruTqst z%pj(9k~`gf#K_zZhjBPbc%*P>on7THz-)<#5U?bKMLdI~2mtGRLZb;9(Gg-?YU4SY z3o0oa>nxA3#3k|m~pCbr_CWM@1l5YO{5!9K1pCRS&1ISdy1#IfKknMZYF(VaNiit6BdB6gA7pFu5 z^JK7>zutsn8!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..2aca9aac90adab203cf01eab2b38dc61d3dd0584 GIT binary patch literal 2249 zcmeH{O>5gg5QfjzuNZQYTSsc0TfmnlJs6r8YB!e<%32!POV+z)cjS+T{P)i8N{*wp zp%hwLC>Uf(^N!w~d1mq)E=-BAK#f)qmN4JL+8Q#&DL*@1nA6G{N0rOqast_F;hZeCYV8M_jcu`Wt&U9bclY$YwDPOK0r ziK>K+P&L0=iVZ%!noBM0KBUi*s@4UhJ9xz=_&}d8k%UzJBTs1`(qKhu>cd0Qlit#3 z1X?P8+l!vzP11WzdLi=lDEiGljWwMO{mIg|1K4HbvfmAPwfQ=R5)u}HBb+$pYZQxIcIv~BUm6>vo>w4hKgxO&p@Kj*72G<$jK zOWGfR#%&wUaY89mcyiigADhkzy$7_`SU_EvS`%8vYrB-i5=vQuHWb8L*jh`Z1S}P<}d!H0041wKBhl6KWG?tl(nAD>ZvIB?(aROG16mk+zO_Hg&SdcI4Xz4<3UNU`QJgWHOTaF z-rE>-es^H8s|qx>A_lT6>fp(*pV8?#e%36{@1LIG-!;5`V}3Kfj2JWgG{09oKfE6~ zjtK$@=OeH}^TOO^akaRxGeTVsy}CxnlXRdpWIOXcY9zPvE;jxDR`@HoLQ7mbIDUlx lwROz5-`KQGQ8&vH}#88S5Du>6uI{%;!o>EXqtP&B@8k+xYGy qo49XcQFdyILSnH(N@_t-YI0%;ke8V^u|{t5OZI83_~bizgG2!?Who>8 delta 96 zcmZ4McH4DAu$+;Fo*|dMz5-`KQGQ8&vH}#88S5Dt>RC=K%;!rh$}cWSE7nac$ka{G m-}vey8<$JILSBA}LTPd8W&w_AtlS8`-ef~AiOpYlEkyyXvmV?4 diff --git a/storagegroup/grpc/types_frostfs.pb.go b/storagegroup/grpc/types_frostfs.pb.go new file mode 100644 index 0000000000000000000000000000000000000000..e6461b7718abae0d4801f2528fae8bc2e24b9eaa GIT binary patch literal 1478 zcmb7DO;6iE6gf61%0S2c(<`YLN;^4ebSSSliF`6PsOYcb$(S{yT5Ic1hfV zgcQlK{bqKaXC_VITo(uxDm21j0oe{3qn*xY{A^a~S!uL&rA=UQ1J^gVaIv_&O`@m~ z`GcqstkZ_CmCP7=WmxN*Uu(K2DV{>yDIw*i@EA?VE1J(ik@UBd zAQ?VIlc#9XO@5pQxyi3f<-VT!#p2J$uuXmoNriBv)j~MopHIh-YqV_2()DX~*pox- zcVX*)aC=96@#7cUhS*;|>Y~xPpXUz;1ZQ(FLa~k8XJhS7B3AUPD0zDD67%1~!Hq zsj7<)dnX{*t45+jx$~rO!%;OGvUq$D-d-{%H<0>3cW_qaDIKao(_gdSpW&elZ>G36 zBlhjNyU%tGr~UPfIETSU_LzShc@N$TeRs?DK42UseLD7?2>DnG!woJiI_|KGCjI|W zK?Z@`5$3%MLudDgso!hNm}L~#fsSkQI$d9)F;%G1z`#u!GrY4`WBym9a=FF_y;3zE Hz5-`KQGQ8&vH}#88S5Du>6uI{%;ZW;EXqtP&B@8k+xVhE F8UW1#5t9G_ delta 59 zcmaE2@xo$4u$+;Fo*|dMz5-`KQGQ8&vH}#88S5Dt>RC=K%;ZZe$}cWSE7nac$ka{G J-}t0K8UPh366yc| diff --git a/tombstone/grpc/types_frostfs.pb.go b/tombstone/grpc/types_frostfs.pb.go new file mode 100644 index 0000000000000000000000000000000000000000..89dd98c4d21b4e97922869b35a2c5350511b091b GIT binary patch literal 1314 zcmb7@O;6k~5Qfj2Uoqm8Z6RrC)dSLA3LI7{Aa$1$;@~8cjfG=J_GCYb`0pLt30k63 zwNj*f&Afg+@8dj&OH(0iP@@%u6%+^PtRYjL@wc;$IjgO4RJ#nW?%?)r4cAx8b(SQZ zD4)azflOOCG8&UawwpQklN`A&OiGE9+h=P|QEm2jl z6{_c7jo7kjFX?|3QVV+s@>x>%x`cEOAJ*fZ=0|?gIi$gc)HH|ZWG20x#R9Zc{&g1p z!lz{RlFUNo$3^s--7htL`|5XDUXDVz5!N+A zK^yOGGW=n5F@rd97s4CnZES^h%w|~w2Uep6g?hu`NXJjkhby$-;cM*a{1i0q#&WI` zN}1BLIg0%pz!3TXXf2Nfb!mD{Xc^#LBg+OVS%Eebns>0XlBC{*+$%u>O4D`<3Dv=i z!W{!)chceM8|ntjj9e7;*o1a=Yk1{spD>M;0koqSA{<*``P|hGiBBFSv*CF{_GpmdX5EKabn*CS)Ta^w e_ECX(pDO$#{ZrWq|KkFD1f~nTb0D~k&%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..f4a592d 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,40 +29,32 @@ 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.") g.P() g.P("package ", file.GoPackageName) g.P() - g.P(`import "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/util/proto"`) + g.P(`import "git.frostfs.info/TrueCloudLab/aarifullin/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..4ef72a3 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/aarifullin/v2/refs/grpc" crypto "git.frostfs.info/TrueCloudLab/frostfs-crypto" ) diff --git a/util/signature/options.go b/util/signature/options.go index b9bf68d..34217b7 100644 --- a/util/signature/options.go +++ b/util/signature/options.go @@ -5,8 +5,8 @@ import ( "encoding/base64" "fmt" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs" - "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/util/signature/walletconnect" + refs "git.frostfs.info/TrueCloudLab/aarifullin/v2/refs/grpc" + "git.frostfs.info/TrueCloudLab/aarifullin/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..fa46253 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/aarifullin/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)) } } -- 2.45.2