From 29f215756383cf58cd1de326dd1c2961b06ea201 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Fri, 11 Oct 2024 10:17:42 +0300 Subject: [PATCH] [#123] protogen: Treat bytes field as non-nullable In protobuf 3.12 they have added an support for `optional` keyword, which has made it into the main branch in 3.15. https://github.com/protocolbuffers/protobuf/blob/main/docs/implementing_proto3_presence.md https://github.com/protocolbuffers/protobuf/blob/v3.12.0/docs/field_presence.md#presence-in-proto3-apis This means that without an explicit `optional` keyword field presence for scalars is not tracked, thus empty string in JSON should be unmarshaled to a nil byte slice. Relevant decoding code and tests from protojson: https://github.com/protocolbuffers/protobuf-go/blob/fb995f184a1719ec42b247a3771d1036d92adf67/internal/impl/message_reflect_field.go#L327 https://github.com/protocolbuffers/protobuf-go/blob/fb995f184a1719ec42b247a3771d1036d92adf67/encoding/protojson/decode_test.go#L134 https://github.com/protocolbuffers/protobuf-go/blob/fb995f184a1719ec42b247a3771d1036d92adf67/encoding/protojson/decode_test.go#L156 We do not support `optional` keyword and the generator will fail if it sees on. So only implement the default behaviour. Refs #122 Signed-off-by: Evgenii Stratonikov --- acl/grpc/types_frostfs.pb.go | Bin 48047 -> 48129 bytes ape/grpc/types_frostfs.pb.go | Bin 8592 -> 8668 bytes apemanager/grpc/service_frostfs.pb.go | Bin 57148 -> 57300 bytes container/grpc/types_frostfs.pb.go | Bin 12208 -> 12284 bytes netmap/grpc/types_frostfs.pb.go | Bin 57422 -> 57650 bytes object/grpc/service_frostfs.pb.go | Bin 223720 -> 224182 bytes object/grpc/types_frostfs.pb.go | Bin 65148 -> 65528 bytes refs/grpc/types_frostfs.pb.go | Bin 30568 -> 31176 bytes session/grpc/service_frostfs.pb.go | Bin 20196 -> 20348 bytes session/grpc/types_frostfs.pb.go | Bin 70734 -> 70886 bytes status/grpc/types_frostfs.pb.go | Bin 14144 -> 14220 bytes tombstone/grpc/types_frostfs.pb.go | Bin 5766 -> 5842 bytes util/proto/marshal_test.go | 10 +--------- util/proto/test/custom/test_frostfs.pb.go | Bin 34803 -> 35037 bytes util/protogen/internalgengo/json.go | 12 +++++++++++- 15 files changed, 12 insertions(+), 10 deletions(-) diff --git a/acl/grpc/types_frostfs.pb.go b/acl/grpc/types_frostfs.pb.go index e5a6f32c25a89a77a238be5194e7f155542e87de..bc90cb77608035d512ef50ab7773ac6c17306b99 100644 GIT binary patch delta 111 zcmZ4govHB$(}p6;glaBMFeu3_P_VL9$jsAosw_z@*3g8CXQnCSq~>V=r8O07Z50d@ gU>Z0e8+jiVuh$`E=~|A$t_T@vQ@~;({rjUNiEjUga~J*DdeQ)X#iz46>M!43>2Ws d!Rl=l@-lNE>S`fWnu4tYP%W5KJ9(qReE>~#7{LGl delta 26 icmccPJi&RxVgQPo_WAW)K9pkQUIkeR3FR9TW*tf2`J&P-FtNzKy$%4#au+A0_* wK$U~l+bZN`=0McdLZ~zaTLqw6FsF92ovEQZ4b7iyXPP~ELJ9BYuQBdT0FNaxxc~qF delta 53 wcmcbzpLx$d<_!j>d}#`{3YmF&PL(C8#TuHMyG#w$(ZnWqnPzWphz)510Qu(P4d delta 27 icmewpzaf4@iw<9!f~`Vko}N=>Noui%=H`1ka?AjlX$kiL diff --git a/netmap/grpc/types_frostfs.pb.go b/netmap/grpc/types_frostfs.pb.go index 032853121cfcd121428f38beab724a28bcaf8ef6..24003c6e6eefb18cf886df8e12d44977e00d99da 100644 GIT binary patch delta 307 zcmX?ifO*p)<_+A_qpG<$L7*hJK*7pZAu~_Usj?)sSVI#coSCMOlbWXil+{$QwN)@s zfGP*8w^hi?%z>z@g-~eD;um;lF~!WZl^zn-g}u GQw0F+r%49@ delta 70 zcmdmVi22+B<_+A_`O*|@6*BYmoGMFFi#0Sir%rEFLKBj3R0Ut>~c~A E0Dij}o&W#< diff --git a/object/grpc/service_frostfs.pb.go b/object/grpc/service_frostfs.pb.go index 9ee5a3daeb4e63982e93f5f36e52224ac772978a..a55a41b0d7faaacf642369cef942b9c726f3c47f 100644 GIT binary patch delta 620 zcmaEHnRnZD-VLqcQPo_WAW)K9pkQUIkeR3FR9TW*tf2`J&P-FtNzKy$%4#au+A0_* zK$U~l+bZN`=0McdLZ~zaTLqw6FsF9ErxBbmL z#yQJr=%?*KKbacQ(t?{6Oh>h00fsADIB~`cdc<%-V}=tsYB+1BJ5(^)ZhyIi>0$vb LJ##{oSs?@fRdSGI delta 173 zcmdmXo%h9M-VLqcd}#`{3YmF&PL(C8#TuHM?}tBhLlc{PKU{M9I&tQ}=9c-}Tjn#) zS&pf|W_p1KlhE{dQzowMm)x1|8loxL&RNBDRGSyYvgwKX%y!$emoZ%|5Jr*E diff --git a/object/grpc/types_frostfs.pb.go b/object/grpc/types_frostfs.pb.go index e4a916fd1789ec371552e5fa40c0fd87ef518a4b..a6d4f016d1d4929c2d66d4899396de81a78a765b 100644 GIT binary patch delta 498 zcmezKhxx~U<_(RJQPo_WAW)K9pkQUIkeR3FR9TW*tf2`J&P-FtNzKy$%4#au+A0_* zK$U~l+bZN`=0McdLZ~zaTLqw6FsF8Nf25!a4b7jtuGTY#cFyPGoXnpgx>=^~kRJ^_ WvH8szML`;xKe<0rYP0D*cLe}J?sC5X delta 119 zcmezIpZU)p<_(RJd}#`{3YmF&PL(C8#TuHMZ$}EM@S=!Kt~;wVIlWE;UFFNVn||nG YGUpTp(ZnX-j+B}_zn*RL_WOHq)$ diff --git a/refs/grpc/types_frostfs.pb.go b/refs/grpc/types_frostfs.pb.go index 5a16f8e46fb89b57c4f311094b9d162b09c1f51d..f2a2663ad151c4c1ec537e82d17f22e24f96dc80 100644 GIT binary patch delta 788 zcmaFyj`752#ti{VQPo_WAW)K9pkQUIkeR3FR9TW*tf2`J&P-FtNzKy$%4#au+A0_* zK$U~l+bZN`=0McdLZ~zaTLqw6FsF8NoRShZEzR%KeZ)me^Xn`Y%F)pL$-3cAG&Fv5 nZTLQZ8k$dI=TEK;7vH=g-IG6sb}1B`PAl|+OLHfGbPERn<>|08 delta 178 zcmX@{neoLt#ti{Vd}#`{3YmF&PL(C8#TuHMS1BoRqlrykrIfk3U$2r2oA_x<3psRg f!AvJ~p|zRfn*}15^P`JnD&4#`GXXfBB#Q$8pi&RZ diff --git a/session/grpc/types_frostfs.pb.go b/session/grpc/types_frostfs.pb.go index e9f3b424f06ee9769ba81ac145f695d6ebcdda41..542a02b0c622031964a5bd42c5c8f8cd6a03c5f0 100644 GIT binary patch delta 215 zcmX@Ng5}vtmJKT_lB>BmL7*hJK*7pZAu~_Usj?)sSVI#coSCMOlbWXil+{$QwN)@s zfGP*8w^hi?%z>z@g-~e^X8reLc8R14^X8reLc8R145!B!zNPtU2cB(+#Wb90Pn86yCBZwO-m diff --git a/util/proto/marshal_test.go b/util/proto/marshal_test.go index 5498cf9..29af711 100644 --- a/util/proto/marshal_test.go +++ b/util/proto/marshal_test.go @@ -50,9 +50,6 @@ func TestStableMarshalSingle(t *testing.T) { var actualFrostfs generated.Primitives require.NoError(t, actualFrostfs.UnmarshalJSON(r)) - if len(actualFrostfs.FieldA) == 0 { - actualFrostfs.FieldA = nil - } require.Equal(t, input, &actualFrostfs) primitivesEqual(t, input, &actual) @@ -110,9 +107,6 @@ func TestStableMarshalSingle(t *testing.T) { var actualFrostfs generated.Primitives require.NoError(t, actualFrostfs.UnmarshalJSON(r)) - if len(actualFrostfs.FieldA) == 0 { - actualFrostfs.FieldA = nil - } require.Equal(t, tc.input, &actualFrostfs) primitivesEqual(t, tc.input, &actual) @@ -124,9 +118,7 @@ func TestStableMarshalSingle(t *testing.T) { func primitivesEqual(t *testing.T, a *generated.Primitives, b *test.Primitives) { // Compare each field directly, because proto-generated code has private fields. require.Equal(t, len(a.FieldA), len(b.FieldA)) - if len(a.FieldA) != 0 { - require.Equal(t, a.FieldA, b.FieldA) - } + require.Equal(t, a.FieldA, b.FieldA) require.Equal(t, a.FieldB, b.FieldB) require.Equal(t, a.FieldC, b.FieldC) require.Equal(t, a.FieldD, b.FieldD) diff --git a/util/proto/test/custom/test_frostfs.pb.go b/util/proto/test/custom/test_frostfs.pb.go index f979038b001687ad4d8f19cff3409197253f7038..5ef95a6c1d4ed711000a03af021d64afa0f513ae 100644 GIT binary patch delta 324 zcmey|&vbVp(}t;z>D64EAW)K9pkQUIkeR3FR9TW*tf2`J&P-FtNzKy$%4#au+A0_* zK$U~l+bZN`=0McdLZ~zaTLqw6Fb5)3q34#Fnv>!