@@ -17,8 +17,7 @@ export interface SimpleWithWrappers {
17
17
export interface SimpleWithMap {
18
18
nameLookup : { [ key : string ] : string } ;
19
19
intLookup : { [ key : number ] : number } ;
20
- /** Ideally we'd test map<int64, int64> but we present maps as JS objects and `Long` cannot be used as a keys. */
21
- longLookup : { [ key : string ] : Long } ;
20
+ longLookup : Map < Long , Long > ;
22
21
}
23
22
24
23
export interface SimpleWithMap_NameLookupEntry {
@@ -32,7 +31,7 @@ export interface SimpleWithMap_IntLookupEntry {
32
31
}
33
32
34
33
export interface SimpleWithMap_LongLookupEntry {
35
- key : string ;
34
+ key : Long ;
36
35
value : Long ;
37
36
}
38
37
@@ -190,7 +189,7 @@ export const SimpleWithWrappers = {
190
189
} ;
191
190
192
191
function createBaseSimpleWithMap ( ) : SimpleWithMap {
193
- return { nameLookup : { } , intLookup : { } , longLookup : { } } ;
192
+ return { nameLookup : { } , intLookup : { } , longLookup : new Map ( ) } ;
194
193
}
195
194
196
195
export const SimpleWithMap = {
@@ -201,7 +200,7 @@ export const SimpleWithMap = {
201
200
Object . entries ( message . intLookup ) . forEach ( ( [ key , value ] ) => {
202
201
SimpleWithMap_IntLookupEntry . encode ( { key : key as any , value } , writer . uint32 ( 26 ) . fork ( ) ) . ldelim ( ) ;
203
202
} ) ;
204
- Object . entries ( message . longLookup ) . forEach ( ( [ key , value ] ) => {
203
+ ( message . longLookup ) . forEach ( ( value , key ) => {
205
204
SimpleWithMap_LongLookupEntry . encode ( { key : key as any , value } , writer . uint32 ( 34 ) . fork ( ) ) . ldelim ( ) ;
206
205
} ) ;
207
206
return writer ;
@@ -241,7 +240,7 @@ export const SimpleWithMap = {
241
240
242
241
const entry4 = SimpleWithMap_LongLookupEntry . decode ( reader , reader . uint32 ( ) ) ;
243
242
if ( entry4 . value !== undefined ) {
244
- message . longLookup [ entry4 . key ] = entry4 . value ;
243
+ message . longLookup . set ( entry4 . key , entry4 . value ) ;
245
244
}
246
245
continue ;
247
246
}
@@ -268,11 +267,11 @@ export const SimpleWithMap = {
268
267
} , { } )
269
268
: { } ,
270
269
longLookup : isObject ( object . longLookup )
271
- ? Object . entries ( object . longLookup ) . reduce < { [ key : string ] : Long } > ( ( acc , [ key , value ] ) => {
272
- acc [ key ] = Long . fromValue ( value as Long | string ) ;
270
+ ? Object . entries ( object . longLookup ) . reduce < Map < Long , Long > > ( ( acc , [ key , value ] ) => {
271
+ acc . set ( Long . fromValue ( key ) , Long . fromValue ( value as Long | string ) ) ;
273
272
return acc ;
274
- } , { } )
275
- : { } ,
273
+ } , new Map ( ) )
274
+ : new Map ( ) ,
276
275
} ;
277
276
} ,
278
277
@@ -296,14 +295,11 @@ export const SimpleWithMap = {
296
295
} ) ;
297
296
}
298
297
}
299
- if ( message . longLookup ) {
300
- const entries = Object . entries ( message . longLookup ) ;
301
- if ( entries . length > 0 ) {
302
- obj . longLookup = { } ;
303
- entries . forEach ( ( [ k , v ] ) => {
304
- obj . longLookup [ k ] = v . toString ( ) ;
305
- } ) ;
306
- }
298
+ if ( message . longLookup ?. size ) {
299
+ obj . longLookup = { } ;
300
+ message . longLookup . forEach ( ( v , k ) => {
301
+ obj . longLookup [ longToNumber ( k ) ] = v . toString ( ) ;
302
+ } ) ;
307
303
}
308
304
return obj ;
309
305
} ,
@@ -331,15 +327,15 @@ export const SimpleWithMap = {
331
327
} ,
332
328
{ } ,
333
329
) ;
334
- message . longLookup = Object . entries ( object . longLookup ?? { } ) . reduce < { [ key : string ] : Long } > (
335
- ( acc , [ key , value ] ) => {
330
+ message . longLookup = ( ( ) => {
331
+ const m = new Map ( ) ;
332
+ ( object . longLookup as Map < Long , Long > ?? new Map ( ) ) . forEach ( ( value , key ) => {
336
333
if ( value !== undefined ) {
337
- acc [ key ] = Long . fromValue ( value ) ;
334
+ m . set ( key , Long . fromValue ( value ) ) ;
338
335
}
339
- return acc ;
340
- } ,
341
- { } ,
342
- ) ;
336
+ } ) ;
337
+ return m ;
338
+ } ) ( ) ;
343
339
return message ;
344
340
} ,
345
341
} ;
@@ -489,13 +485,13 @@ export const SimpleWithMap_IntLookupEntry = {
489
485
} ;
490
486
491
487
function createBaseSimpleWithMap_LongLookupEntry ( ) : SimpleWithMap_LongLookupEntry {
492
- return { key : "" , value : Long . ZERO } ;
488
+ return { key : Long . ZERO , value : Long . ZERO } ;
493
489
}
494
490
495
491
export const SimpleWithMap_LongLookupEntry = {
496
492
encode ( message : SimpleWithMap_LongLookupEntry , writer : _m0 . Writer = _m0 . Writer . create ( ) ) : _m0 . Writer {
497
- if ( message . key !== "" ) {
498
- writer . uint32 ( 10 ) . string ( message . key ) ;
493
+ if ( ! message . key . isZero ( ) ) {
494
+ writer . uint32 ( 8 ) . int64 ( message . key ) ;
499
495
}
500
496
if ( ! message . value . isZero ( ) ) {
501
497
writer . uint32 ( 16 ) . int64 ( message . value ) ;
@@ -511,11 +507,11 @@ export const SimpleWithMap_LongLookupEntry = {
511
507
const tag = reader . uint32 ( ) ;
512
508
switch ( tag >>> 3 ) {
513
509
case 1 :
514
- if ( tag !== 10 ) {
510
+ if ( tag !== 8 ) {
515
511
break ;
516
512
}
517
513
518
- message . key = reader . string ( ) ;
514
+ message . key = reader . int64 ( ) as Long ;
519
515
continue ;
520
516
case 2 :
521
517
if ( tag !== 16 ) {
@@ -535,15 +531,15 @@ export const SimpleWithMap_LongLookupEntry = {
535
531
536
532
fromJSON ( object : any ) : SimpleWithMap_LongLookupEntry {
537
533
return {
538
- key : isSet ( object . key ) ? String ( object . key ) : "" ,
534
+ key : isSet ( object . key ) ? Long . fromValue ( object . key ) : Long . ZERO ,
539
535
value : isSet ( object . value ) ? Long . fromValue ( object . value ) : Long . ZERO ,
540
536
} ;
541
537
} ,
542
538
543
539
toJSON ( message : SimpleWithMap_LongLookupEntry ) : unknown {
544
540
const obj : any = { } ;
545
- if ( message . key !== "" ) {
546
- obj . key = message . key ;
541
+ if ( ! message . key . isZero ( ) ) {
542
+ obj . key = ( message . key || Long . ZERO ) . toString ( ) ;
547
543
}
548
544
if ( ! message . value . isZero ( ) ) {
549
545
obj . value = ( message . value || Long . ZERO ) . toString ( ) ;
@@ -558,7 +554,7 @@ export const SimpleWithMap_LongLookupEntry = {
558
554
object : I ,
559
555
) : SimpleWithMap_LongLookupEntry {
560
556
const message = createBaseSimpleWithMap_LongLookupEntry ( ) ;
561
- message . key = object . key ?? "" ;
557
+ message . key = ( object . key !== undefined && object . key !== null ) ? Long . fromValue ( object . key ) : Long . ZERO ;
562
558
message . value = ( object . value !== undefined && object . value !== null ) ? Long . fromValue ( object . value ) : Long . ZERO ;
563
559
return message ;
564
560
} ,
@@ -837,6 +833,25 @@ export const Numbers = {
837
833
} ,
838
834
} ;
839
835
836
+ declare const self : any | undefined ;
837
+ declare const window : any | undefined ;
838
+ declare const global : any | undefined ;
839
+ const tsProtoGlobalThis : any = ( ( ) => {
840
+ if ( typeof globalThis !== "undefined" ) {
841
+ return globalThis ;
842
+ }
843
+ if ( typeof self !== "undefined" ) {
844
+ return self ;
845
+ }
846
+ if ( typeof window !== "undefined" ) {
847
+ return window ;
848
+ }
849
+ if ( typeof global !== "undefined" ) {
850
+ return global ;
851
+ }
852
+ throw "Unable to locate global object" ;
853
+ } ) ( ) ;
854
+
840
855
type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined ;
841
856
842
857
export type DeepPartial < T > = T extends Builtin ? T
@@ -849,6 +864,13 @@ type KeysOfUnion<T> = T extends T ? keyof T : never;
849
864
export type Exact < P , I extends P > = P extends Builtin ? P
850
865
: P & { [ K in keyof P ] : Exact < P [ K ] , I [ K ] > } & { [ K in Exclude < keyof I , KeysOfUnion < P > > ] : never } ;
851
866
867
+ function longToNumber ( long : Long ) : number {
868
+ if ( long . gt ( Number . MAX_SAFE_INTEGER ) ) {
869
+ throw new tsProtoGlobalThis . Error ( "Value is larger than Number.MAX_SAFE_INTEGER" ) ;
870
+ }
871
+ return long . toNumber ( ) ;
872
+ }
873
+
852
874
if ( _m0 . util . Long !== Long ) {
853
875
_m0 . util . Long = Long as any ;
854
876
_m0 . configure ( ) ;
0 commit comments