@@ -844,6 +844,21 @@ func TestCreateFromJsonLine(t *testing.T) {
844844 },
845845 },
846846 }
847+ mapInt32ToBytes := & api.Message {
848+ Name : "$Int32ToBytes" ,
849+ ID : "..$Int32ToBytes" ,
850+ IsMap : true ,
851+ Fields : []* api.Field {
852+ {
853+ Name : "key" ,
854+ Typez : api .INT32_TYPE ,
855+ },
856+ {
857+ Name : "value" ,
858+ Typez : api .BYTES_TYPE ,
859+ },
860+ },
861+ }
847862
848863 for _ , test := range []struct {
849864 field * api.Field
@@ -993,11 +1008,18 @@ func TestCreateFromJsonLine(t *testing.T) {
9931008 & api.Field {Name : "message" , JSONName : "message" , Typez : api .MESSAGE_TYPE , TypezID : ".google.protobuf.Duration" },
9941009 "switch (json['message']) { null => null, Object $1 => Duration.fromJson($1)}" ,
9951010 },
1011+
1012+ // maps
9961013 {
997- // Map of bytes.
1014+ // string -> bytes
9981015 & api.Field {Name : "message" , JSONName : "message" , Map : true , Typez : api .MESSAGE_TYPE , TypezID : mapStringToBytes .ID },
9991016 "switch (json['message']) { null => {}, Map<String, Object?> $1 => {for (final e in $1.entries) decodeString(e.key): decodeBytes(e.value)}, _ => throw const FormatException('\" message\" is not an object') }" ,
10001017 },
1018+ {
1019+ // int32 -> bytes
1020+ & api.Field {Name : "message" , JSONName : "message" , Map : true , Typez : api .MESSAGE_TYPE , TypezID : mapInt32ToBytes .ID },
1021+ "switch (json['message']) { null => {}, Map<String, Object?> $1 => {for (final e in $1.entries) decodeIntKey(e.key): decodeBytes(e.value)}, _ => throw const FormatException('\" message\" is not an object') }" ,
1022+ },
10011023 } {
10021024 t .Run (test .field .Name , func (t * testing.T ) {
10031025 message := & api.Message {
@@ -1006,7 +1028,10 @@ func TestCreateFromJsonLine(t *testing.T) {
10061028 Package : sample .Package ,
10071029 Fields : []* api.Field {test .field },
10081030 }
1009- model := api .NewTestAPI ([]* api.Message {message , secret , foreignMessage , mapStringToBytes }, []* api.Enum {enumState , foreignEnumState }, []* api.Service {})
1031+ model := api .NewTestAPI ([]* api.Message {message ,
1032+ secret , foreignMessage , mapStringToBytes , mapInt32ToBytes },
1033+ []* api.Enum {enumState , foreignEnumState },
1034+ []* api.Service {})
10101035 annotate := newAnnotateModel (model )
10111036 annotate .annotateModel (map [string ]string {
10121037 "prefix:google.cloud.foo" : "foo" ,
0 commit comments