Skip to content

Commit db2be83

Browse files
authored
fix(dart): Use BigInt for unsigned 64-bit integer types (#3173)
1 parent 8a9ec23 commit db2be83

File tree

3 files changed

+20
-17
lines changed

3 files changed

+20
-17
lines changed

internal/sidekick/dart/annotate.go

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ var defaultValues = map[api.Typez]struct {
4242
api.BYTES_TYPE: {"Uint8List(0)", false},
4343
api.DOUBLE_TYPE: {"0", true},
4444
api.FIXED32_TYPE: {"0", true},
45-
api.FIXED64_TYPE: {"0", true},
45+
api.FIXED64_TYPE: {"BigInt.zero", false},
4646
api.FLOAT_TYPE: {"0", true},
4747
api.INT32_TYPE: {"0", true},
4848
api.INT64_TYPE: {"0", true},
@@ -52,7 +52,7 @@ var defaultValues = map[api.Typez]struct {
5252
api.SINT64_TYPE: {"0", true},
5353
api.STRING_TYPE: {"''", true},
5454
api.UINT32_TYPE: {"0", true},
55-
api.UINT64_TYPE: {"0", true},
55+
api.UINT64_TYPE: {"BigInt.zero", false},
5656
}
5757

5858
type modelAnnotations struct {
@@ -805,11 +805,12 @@ func (annotate *annotateModel) annotateField(field *api.Field) {
805805
func (annotate *annotateModel) decoder(typez api.Typez, typeid string, state *api.APIState) string {
806806
switch typez {
807807
case api.INT64_TYPE,
808-
api.UINT64_TYPE,
809808
api.SINT64_TYPE,
810-
api.FIXED64_TYPE,
811809
api.SFIXED64_TYPE:
812810
return "decodeInt64"
811+
case api.FIXED64_TYPE,
812+
api.UINT64_TYPE:
813+
return "decodeUint64"
813814
case api.FLOAT_TYPE,
814815
api.DOUBLE_TYPE:
815816
return "decodeDouble"
@@ -922,10 +923,11 @@ func createToJsonLine(field *api.Field, state *api.APIState, required bool) stri
922923
return fmt.Sprintf("%s%s.toJson()", name, bang)
923924
case field.Typez == api.BYTES_TYPE:
924925
return fmt.Sprintf("encodeBytes(%s)", name)
925-
case field.Typez == api.INT64_TYPE ||
926-
field.Typez == api.UINT64_TYPE || field.Typez == api.SINT64_TYPE ||
927-
field.Typez == api.FIXED64_TYPE || field.Typez == api.SFIXED64_TYPE:
926+
case field.Typez == api.INT64_TYPE || field.Typez == api.SINT64_TYPE ||
927+
field.Typez == api.SFIXED64_TYPE:
928928
return fmt.Sprintf("encodeInt64(%s)", name)
929+
case field.Typez == api.FIXED64_TYPE || field.Typez == api.UINT64_TYPE:
930+
return fmt.Sprintf("encodeUint64(%s)", name)
929931
case field.Typez == api.FLOAT_TYPE || field.Typez == api.DOUBLE_TYPE:
930932
return fmt.Sprintf("encodeDouble(%s)", name)
931933
default:
@@ -1064,9 +1066,10 @@ func (annotate *annotateModel) fieldType(f *api.Field) string {
10641066
case api.INT32_TYPE, api.UINT32_TYPE, api.SINT32_TYPE,
10651067
api.FIXED32_TYPE, api.SFIXED32_TYPE:
10661068
out = "int"
1067-
case api.INT64_TYPE, api.UINT64_TYPE, api.SINT64_TYPE,
1068-
api.FIXED64_TYPE, api.SFIXED64_TYPE:
1069+
case api.INT64_TYPE, api.SINT64_TYPE, api.SFIXED64_TYPE:
10691070
out = "int"
1071+
case api.FIXED64_TYPE, api.UINT64_TYPE:
1072+
out = "BigInt"
10701073
case api.FLOAT_TYPE, api.DOUBLE_TYPE:
10711074
out = "double"
10721075
case api.STRING_TYPE:

internal/sidekick/dart/annotate_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -864,7 +864,7 @@ func TestCreateFromJsonLine(t *testing.T) {
864864
"switch (json['fixed32']) { null => 0, Object $1 => decodeInt($1)}",
865865
}, {
866866
&api.Field{Name: "fixed64", JSONName: "fixed64", Typez: api.FIXED64_TYPE},
867-
"switch (json['fixed64']) { null => 0, Object $1 => decodeInt64($1)}",
867+
"switch (json['fixed64']) { null => BigInt.zero, Object $1 => decodeUint64($1)}",
868868
}, {
869869
&api.Field{Name: "float", JSONName: "float", Typez: api.FLOAT_TYPE},
870870
"switch (json['float']) { null => 0, Object $1 => decodeDouble($1)}",
@@ -891,7 +891,7 @@ func TestCreateFromJsonLine(t *testing.T) {
891891
"switch (json['uint32']) { null => 0, Object $1 => decodeInt($1)}",
892892
}, {
893893
&api.Field{Name: "uint64", JSONName: "uint64", Typez: api.UINT64_TYPE},
894-
"switch (json['uint64']) { null => 0, Object $1 => decodeInt64($1)}",
894+
"switch (json['uint64']) { null => BigInt.zero, Object $1 => decodeUint64($1)}",
895895
},
896896

897897
// optional primitives
@@ -906,7 +906,7 @@ func TestCreateFromJsonLine(t *testing.T) {
906906
"switch (json['double']) { null => null, Object $1 => decodeDouble($1)}",
907907
}, {
908908
&api.Field{Name: "fixed64_opt", JSONName: "fixed64", Typez: api.FIXED64_TYPE, Optional: true},
909-
"switch (json['fixed64']) { null => null, Object $1 => decodeInt64($1)}",
909+
"switch (json['fixed64']) { null => null, Object $1 => decodeUint64($1)}",
910910
}, {
911911
&api.Field{Name: "float_opt", JSONName: "float", Typez: api.FLOAT_TYPE, Optional: true},
912912
"switch (json['float']) { null => null, Object $1 => decodeDouble($1)}",
@@ -933,7 +933,7 @@ func TestCreateFromJsonLine(t *testing.T) {
933933
"switch (json['uint32']) { null => null, Object $1 => decodeInt($1)}",
934934
}, {
935935
&api.Field{Name: "uint64_opt", JSONName: "uint64", Typez: api.UINT64_TYPE, Optional: true},
936-
"switch (json['uint64']) { null => null, Object $1 => decodeInt64($1)}",
936+
"switch (json['uint64']) { null => null, Object $1 => decodeUint64($1)}",
937937
},
938938

939939
// one ofs

internal/sidekick/dart/dart_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -310,8 +310,8 @@ func TestFieldType(t *testing.T) {
310310
{api.FIXED32_TYPE, "int"},
311311
{api.SFIXED32_TYPE, "int"},
312312
{api.INT64_TYPE, "int"},
313-
{api.UINT64_TYPE, "int"},
314-
{api.FIXED64_TYPE, "int"},
313+
{api.UINT64_TYPE, "BigInt"},
314+
{api.FIXED64_TYPE, "BigInt"},
315315
{api.SFIXED64_TYPE, "int"},
316316
{api.FLOAT_TYPE, "double"},
317317
{api.DOUBLE_TYPE, "double"},
@@ -455,8 +455,8 @@ func TestFieldType_Repeated(t *testing.T) {
455455
{api.FIXED32_TYPE, "List<int>"},
456456
{api.SFIXED32_TYPE, "List<int>"},
457457
{api.INT64_TYPE, "List<int>"},
458-
{api.UINT64_TYPE, "List<int>"},
459-
{api.FIXED64_TYPE, "List<int>"},
458+
{api.UINT64_TYPE, "List<BigInt>"},
459+
{api.FIXED64_TYPE, "List<BigInt>"},
460460
{api.SFIXED64_TYPE, "List<int>"},
461461
{api.FLOAT_TYPE, "List<double>"},
462462
{api.DOUBLE_TYPE, "List<double>"},

0 commit comments

Comments
 (0)