From d94b9c6d0d6030e551a58ae260d943290fd8e38e Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Tue, 1 Oct 2024 13:50:27 +0300 Subject: [PATCH] [#120] protogen: Unmarshal stringified integers from JSON Signed-off-by: Evgenii Stratonikov --- accounting/grpc/types_frostfs.pb.go | Bin 3973 -> 4309 bytes acl/grpc/types_frostfs.pb.go | Bin 48216 -> 48693 bytes container/grpc/types_frostfs.pb.go | Bin 12283 -> 12461 bytes netmap/grpc/types_frostfs.pb.go | Bin 56876 -> 58306 bytes object/grpc/service_frostfs.pb.go | Bin 226570 -> 227381 bytes object/grpc/types_frostfs.pb.go | Bin 64878 -> 66309 bytes refs/grpc/types_frostfs.pb.go | Bin 30313 -> 30631 bytes session/grpc/service_frostfs.pb.go | Bin 20196 -> 20374 bytes session/grpc/types_frostfs.pb.go | Bin 70412 -> 71684 bytes status/grpc/types_frostfs.pb.go | Bin 13952 -> 14270 bytes tombstone/grpc/types_frostfs.pb.go | Bin 5574 -> 5752 bytes util/proto/test/custom/test_frostfs.pb.go | Bin 32782 -> 35044 bytes util/protogen/internalgengo/json.go | 23 ++++++++++++++++++---- 13 files changed, 19 insertions(+), 4 deletions(-) diff --git a/accounting/grpc/types_frostfs.pb.go b/accounting/grpc/types_frostfs.pb.go index 0ae770b37d72a6476ae6f378af8393a028dbcafe..438cd038580beadac973ef8c79f742ff18326f14 100644 GIT binary patch delta 388 zcmZpbzpA+57Na0%aY<2feqNb^5|pv|2IEtn`XU7@TZPO#J+I>YJipT1q|_n}O)gF# z$OB0f=>?Y*W#*+r#maOPQj5Skpl0X=Bo-B?dghgAbxv-GXePqR#zrJLSsxTQIGkJxG}hP%&CPQB=>Se8XQ%)G delta 51 zcmcbr*ebu_7USl(jE{Nv(iChJGV}C2^GeK2G&CpI@VoFsg+ep)N{o$wVtE4T0NET6 Axc~qF diff --git a/acl/grpc/types_frostfs.pb.go b/acl/grpc/types_frostfs.pb.go index 57e16821c84ecf5831facd520b8f3fea7738deba..6ebaf63fc62a34634ab97105560d85b33344f77e 100644 GIT binary patch delta 379 zcmccdgK6s@rVWQ`bc+}9Gp|G=Pe;MfKu5vMM3ZZ>Ly+WTQA;uHqSTVoqCBwXS}<8q1~Q`*sNT#(qYPqf bnu4uDLD}SsH8ulfwM^|mS-m;E_M;sDF%D$Q delta 70 wcmdn`hv~)-rVWQ`_|p_@6*BYmLNoJ9%uF;iCl}P(V2DN4VTf&ZssCsP0F-_hasU7T diff --git a/container/grpc/types_frostfs.pb.go b/container/grpc/types_frostfs.pb.go index 9db07ed31ffc3cb9833f87889ed18460fc1c0bf1..e5da35ff24fbfbb2531b1a307b5cb5cf7482c61c 100644 GIT binary patch delta 211 zcmewzzcz700+S$TaY<2feqNb^5|ptyjww;QzDU8!Rv|M_&#O2;&#yE$DYZyLlZz7w z@<0+rdch?{nR)3@u`(Tn)FQABs2O?ziABY!p_zFl8hJVjh6Xwc#zqkBnQ369ina=Q znK=s8U?Vw!_Bf`bxE2-V7ij0@LPVrg&}sGzD9Q%sjo&%)Am~BMr^X4SKpv0MuU#3IG5A diff --git a/netmap/grpc/types_frostfs.pb.go b/netmap/grpc/types_frostfs.pb.go index d082910e76e58f64b08586b52d2269176f1f3bb0..24b75753820cf9868d14ff0da7e3d2f4d478be02 100644 GIT binary patch delta 1141 zcmZ3phxyQP<_(|Cb&C|NY!x!|^t_7m^ZZJ4lTwQ`G`To|AP*!_q!(OLl$nl~LeO(@PCno)y4lxHSca-@ASL=Y=V#rv zr_gpY6JisenF(s*+Z?${&S=1FpWJrGci=34bjOQi%cXgt`5iULwQwXlV0K3j@yS+q GKLG%FG$7po delta 218 zcmX?foO#V2<_(|C`O_3^6*BYmLNoJ9jEyujH!rl16Ga!C3>2K)?N^H-zRllH5X}HC z&dKpEqMJ_!2+LrR+88and1dY%dod(kW+ob%T%15qp*Q*M1M$U%>x_^s0!dH4|G*bR U?AAjsKBzICc_mYJipT1q|_n}O)gFl$OFj~=>?Y*W#*;B1j}?3 zQj5TPic5-;^YhB|0uqagQ$sWJN;LAOe`sV1kSYV|D+LM|8)=k5%}P_SRVXN%uGqk2 zJAJ`5rpCz&N_eL4k!R+f{vm*wt+~8+dwDNovtbBM*I;uDUbpBd7#ip(7#nGFO+T=j zNpiYq6O)*BQEEwPQ6AWPwP3OUi(?^f-Ojn6vE7^M4l*+#)^2r?FTzxuLgly8b67j_o10 Im>$jr0E#X&DF6Tf diff --git a/object/grpc/types_frostfs.pb.go b/object/grpc/types_frostfs.pb.go index 5b1eb2c343566f6f6f6b3ab271e24a32d515ea17..bc246cf97cc32aa4b87c4681ab895a1930d0aba1 100644 GIT binary patch delta 1319 zcmaF&i@CLpWy2ixup$L3TZPO#J+I>YJipT1q|_n}O)gF#$OB0f=>?Y*W#*+r#maOP zQj5Skic5-;^YhB|0uqagQ$sWJN;L9x6bub?6wFLO+9xMEiB2xol+Z3pEh#O^0~=Ti zCJV|y=9U6=n3-slL99wsuvI81o7}KLZSv{$HJg1kIG6^LyY6pTvsplUYXH^VWNbui zSQ#6kh1Jye4ui=#$~EpZc8)Hdl!P8ST%3~y(nU7+*E}+&x~nKk-_%b+F3!pM!lIL}ZWWmPd{g!2HyRvF{Afxh zTWnpk*-vL{0J4O!k%s2vjkOLKV)N_V(Zx1TssCY&(_;R~30t&~wSb(p*<$N*J7hsT Q_DM|EdK|v_)mLd=0E>D~od5s; diff --git a/refs/grpc/types_frostfs.pb.go b/refs/grpc/types_frostfs.pb.go index 869620f80dfc680da4b0743aef32f8752403ba36..3ed647c1b9a094e3b13cf746fbac347f5e92e40c 100644 GIT binary patch delta 292 zcmaF)hH?3O#tm~_Ly8ovY!x!|^t_7m^ZZJ4lTwQ`G`To|AP*!_q!(OLl$nE78c)Q7|;nQ7|^r_&j0`b diff --git a/session/grpc/service_frostfs.pb.go b/session/grpc/service_frostfs.pb.go index a3f0111267d18e10511223d1ba5f972f29206161..71a6a4125b125d1cd216dbe46b442334bc2c0205 100644 GIT binary patch delta 196 zcmaDdmvP#B#to88f}F)AMalVjWeQ4A#%6IQMgFiN1uI*H%sf4>;`}_n(%hufA`MM0 zP9VqwNfhY?mlS2@r9;KabQDsHz&fC2=mjJe6{m(~=9OsV=_nW)=qQ+(fV59u&o1iB z$q6*qF(t*ds3^Zk1E>*VFlSL}Noi3Y*pgZ>Sx^SDs}yL8nTbXjL{*xCtwKTBW_Q84 Fwg4YaHWB~; delta 41 xcmbO>pYh3D#to88jGB`ZghVzwGI8YJipT1q|_n}O)gF#$OB0f=>?Y*W#*+r#U@YC z78eT5%q!8z(@`)q&`~fm0V$r$*d#jnytagPQEEwPQ65-(Eto7Q1DR3^)L~|#Q3f$M zO~F>7pltG*aGQa%{5zE`HzmR6;DD*n^Gqz6ocJSlvaY+}=3NmJk_Rp@BKO!)Xt}Ww uvB|*L2sIgOR=gw2IQeY_`{q-7cQR7w4DwUs=1KdFWd_Xl$pah%ugw4)rVjG} delta 187 zcmZqKz|ymfWy9QX{xk(!h0Hv?(9FCNGZPKX$=(q*7-FW87-E~{qc~D96zV>(Ll!eO s($L&|aQ|HQEn|%%&%b*KR#;#kIak{2BqvGV#m$)`3K3Z%F0B?glF#rGn diff --git a/status/grpc/types_frostfs.pb.go b/status/grpc/types_frostfs.pb.go index 7581dbe90dcf52e8fdbc4201001e36cb1ae3c06d..609fc0348f2635087ef0a765fea94e223be2cff6 100644 GIT binary patch delta 335 zcmZq3-Iu>XK{>2Q!OB)4Gf&T}I6u#?G&d==NJEp06A1D^5=DB!B}JKe=}@sU9fi~) zu#V!AqU8L%GQEJrqTorB4IXQvmI;Nz!78T_eX#h1s x4CX9KEh#O^16xuHCJV|yc9jB6F*edDgQ!YVuvI81+pMo#BRJUIxXa`iBLF9#S)Kp@ delta 49 pcmdm&-;ldOL76{I!B!zNPcJkxuf*6$Lv!;vy^xo?mHhQfiTgCKo3V zSyr zGIJEF!A5cd?Qu*=aV;v!FVX-S1XQUHvZ^Sxq_ijxtfUr97Ly^xo?mHhQfiTgCKo3V7plq{(K(Z0ZwoCJ3wO9*>#aQf}JkiOCWNYzx+5(5&*gOpmlL|ez%+#C|*U1|l z#V5b55jF?9(#!-bMQUWggTu@OIUeu?hnWd#G)y*hrZhNE?Zy`z=$0b~hdVepmO0B& z7&+8&jVIVO-<=C7bPWahquhm!dEjjCasR+OV75holnF3kxo*UU^NA9VGA ryB?8aVCEmJa+-Xgrk@Nu#QBg*Ziqz)pJ2CXLG1+k*tEH^u9p!2DP_8O delta 310 zcmaDdk*TkNX@j5uf0}}=LS~*`Xl7oCv5|)6WQFLw&ANhL4f&uFo>1{~&Q2I=_qjMC zDKj$xYG3V&q6{oH+YM8!+kGm!ahuP1urXr@Hu-$u#Sm18)=)*V8SL=hR;S5!js56q iCxgU~HuWMY2RjNR?9qav94dYZ*$AkZ^X7>59!3C?kz&mN diff --git a/util/protogen/internalgengo/json.go b/util/protogen/internalgengo/json.go index ec70155..4d7f4be 100644 --- a/util/protogen/internalgengo/json.go +++ b/util/protogen/internalgengo/json.go @@ -59,6 +59,17 @@ func emitJSONUnmarshal(g *protogen.GeneratedFile, msg *protogen.Message) { g.P("}") } +func emitJSONParseInteger(g *protogen.GeneratedFile, ident string, method string, bitSize int, typ string) { + g.P("r := in.JsonNumber()") + g.P("n := r.String()") + g.P("v, err := ", strconvPackage.Ident(method), "(n, 10, ", bitSize, ")") + g.P("if err != nil {") + g.P(" in.AddError(err)") + g.P(" return") + g.P("}") + g.P(ident, " := ", typ, "(v)") +} + func emitJSONFieldRead(g *protogen.GeneratedFile, f *protogen.Field, name string) { g.P("{") defer g.P("}") @@ -100,13 +111,17 @@ func emitJSONFieldRead(g *protogen.GeneratedFile, f *protogen.Field, name string }`) template = "%s = parsedValue" case protoreflect.Int32Kind, protoreflect.Sint32Kind, protoreflect.Sfixed32Kind: - template = "%s = in.Int32()" + emitJSONParseInteger(g, "pv", "ParseInt", 32, "int32") + template = "%s = pv" case protoreflect.Uint32Kind, protoreflect.Fixed32Kind: - template = "%s = in.Uint32()" + emitJSONParseInteger(g, "pv", "ParseUint", 32, "uint32") + template = "%s = pv" case protoreflect.Int64Kind, protoreflect.Sint64Kind, protoreflect.Sfixed64Kind: - template = "%s = in.Int64()" + emitJSONParseInteger(g, "pv", "ParseInt", 64, "int64") + template = "%s = pv" case protoreflect.Uint64Kind, protoreflect.Fixed64Kind: - template = "%s = in.Uint64()" + emitJSONParseInteger(g, "pv", "ParseUint", 64, "uint64") + template = "%s = pv" case protoreflect.FloatKind: template = "%s = in.Float32()" case protoreflect.DoubleKind: