@@ -22,43 +22,43 @@ func createDecoderOfNative(schema Schema, typ reflect2.Type) ValDecoder {
22
22
if schema .Type () != Int {
23
23
break
24
24
}
25
- return & intCodec {}
25
+ return & intCodec [ int ] {}
26
26
27
27
case reflect .Int8 :
28
28
if schema .Type () != Int {
29
29
break
30
30
}
31
- return & int8Codec {}
31
+ return & intCodec [ int8 ] {}
32
32
33
33
case reflect .Uint8 :
34
34
if schema .Type () != Int {
35
35
break
36
36
}
37
- return & uint8Codec {}
37
+ return & intCodec [ uint8 ] {}
38
38
39
39
case reflect .Int16 :
40
40
if schema .Type () != Int {
41
41
break
42
42
}
43
- return & int16Codec {}
43
+ return & intCodec [ int16 ] {}
44
44
45
45
case reflect .Uint16 :
46
46
if schema .Type () != Int {
47
47
break
48
48
}
49
- return & uint16Codec {}
49
+ return & intCodec [ uint16 ] {}
50
50
51
51
case reflect .Int32 :
52
52
if schema .Type () != Int {
53
53
break
54
54
}
55
- return & int32Codec {}
55
+ return & intCodec [ int32 ] {}
56
56
57
57
case reflect .Uint32 :
58
58
if schema .Type () != Long {
59
59
break
60
60
}
61
- return & uint32Codec {}
61
+ return & longCodec [ uint32 ] {}
62
62
63
63
case reflect .Int64 :
64
64
st := schema .Type ()
@@ -71,7 +71,7 @@ func createDecoderOfNative(schema Schema, typ reflect2.Type) ValDecoder {
71
71
return & timeMicrosCodec {}
72
72
73
73
case st == Long :
74
- return & int64Codec {}
74
+ return & longCodec [ int64 ] {}
75
75
76
76
default :
77
77
break
@@ -157,46 +157,46 @@ func createEncoderOfNative(schema Schema, typ reflect2.Type) ValEncoder {
157
157
if schema .Type () != Int {
158
158
break
159
159
}
160
- return & intCodec {}
160
+ return & intCodec [ int ] {}
161
161
162
162
case reflect .Int8 :
163
163
if schema .Type () != Int {
164
164
break
165
165
}
166
- return & int8Codec {}
166
+ return & intCodec [ int8 ] {}
167
167
168
168
case reflect .Uint8 :
169
169
if schema .Type () != Int {
170
170
break
171
171
}
172
- return & uint8Codec {}
172
+ return & intCodec [ uint8 ] {}
173
173
174
174
case reflect .Int16 :
175
175
if schema .Type () != Int {
176
176
break
177
177
}
178
- return & int16Codec {}
178
+ return & intCodec [ int16 ] {}
179
179
180
180
case reflect .Uint16 :
181
181
if schema .Type () != Int {
182
182
break
183
183
}
184
- return & uint16Codec {}
184
+ return & intCodec [ uint16 ] {}
185
185
186
186
case reflect .Int32 :
187
187
switch schema .Type () {
188
188
case Long :
189
- return & int32LongCodec {}
189
+ return & longCodec [ int32 ] {}
190
190
191
191
case Int :
192
- return & int32Codec {}
192
+ return & intCodec [ int32 ] {}
193
193
}
194
194
195
195
case reflect .Uint32 :
196
196
if schema .Type () != Long {
197
197
break
198
198
}
199
- return & uint32Codec {}
199
+ return & longCodec [ uint32 ] {}
200
200
201
201
case reflect .Int64 :
202
202
st := schema .Type ()
@@ -209,7 +209,7 @@ func createEncoderOfNative(schema Schema, typ reflect2.Type) ValEncoder {
209
209
return & timeMicrosCodec {}
210
210
211
211
case st == Long :
212
- return & int64Codec {}
212
+ return & longCodec [ int64 ] {}
213
213
214
214
default :
215
215
break
@@ -322,90 +322,32 @@ func (*boolCodec) Encode(ptr unsafe.Pointer, w *Writer) {
322
322
w .WriteBool (* ((* bool )(ptr )))
323
323
}
324
324
325
- type intCodec struct {}
326
-
327
- func (* intCodec ) Decode (ptr unsafe.Pointer , r * Reader ) {
328
- * ((* int )(ptr )) = int (r .ReadInt ())
329
- }
330
-
331
- func (* intCodec ) Encode (ptr unsafe.Pointer , w * Writer ) {
332
- w .WriteInt (int32 (* ((* int )(ptr ))))
333
- }
334
-
335
- type int8Codec struct {}
336
-
337
- func (* int8Codec ) Decode (ptr unsafe.Pointer , r * Reader ) {
338
- * ((* int8 )(ptr )) = int8 (r .ReadInt ())
339
- }
340
-
341
- func (* int8Codec ) Encode (ptr unsafe.Pointer , w * Writer ) {
342
- w .WriteInt (int32 (* ((* int8 )(ptr ))))
325
+ type smallInt interface {
326
+ ~ int | ~ int8 | ~ int16 | ~ int32 | ~ uint | ~ uint8 | ~ uint16
343
327
}
344
328
345
- type uint8Codec struct {}
329
+ type intCodec [ T smallInt ] struct {}
346
330
347
- func (* uint8Codec ) Decode (ptr unsafe.Pointer , r * Reader ) {
348
- * ((* uint8 )(ptr )) = uint8 (r .ReadInt ())
331
+ func (* intCodec [ T ] ) Decode (ptr unsafe.Pointer , r * Reader ) {
332
+ * ((* T )(ptr )) = T (r .ReadInt ())
349
333
}
350
334
351
- func (* uint8Codec ) Encode (ptr unsafe.Pointer , w * Writer ) {
352
- w .WriteInt (int32 (* ((* uint8 )(ptr ))))
335
+ func (* intCodec [ T ] ) Encode (ptr unsafe.Pointer , w * Writer ) {
336
+ w .WriteInt (int32 (* ((* T )(ptr ))))
353
337
}
354
338
355
- type int16Codec struct {}
356
-
357
- func (* int16Codec ) Decode (ptr unsafe.Pointer , r * Reader ) {
358
- * ((* int16 )(ptr )) = int16 (r .ReadInt ())
359
- }
360
-
361
- func (* int16Codec ) Encode (ptr unsafe.Pointer , w * Writer ) {
362
- w .WriteInt (int32 (* ((* int16 )(ptr ))))
363
- }
364
-
365
- type uint16Codec struct {}
366
-
367
- func (* uint16Codec ) Decode (ptr unsafe.Pointer , r * Reader ) {
368
- * ((* uint16 )(ptr )) = uint16 (r .ReadInt ())
369
- }
370
-
371
- func (* uint16Codec ) Encode (ptr unsafe.Pointer , w * Writer ) {
372
- w .WriteInt (int32 (* ((* uint16 )(ptr ))))
373
- }
374
-
375
- type int32Codec struct {}
376
-
377
- func (* int32Codec ) Decode (ptr unsafe.Pointer , r * Reader ) {
378
- * ((* int32 )(ptr )) = r .ReadInt ()
379
- }
380
-
381
- func (* int32Codec ) Encode (ptr unsafe.Pointer , w * Writer ) {
382
- w .WriteInt (* ((* int32 )(ptr )))
383
- }
384
-
385
- type uint32Codec struct {}
386
-
387
- func (* uint32Codec ) Decode (ptr unsafe.Pointer , r * Reader ) {
388
- * ((* uint32 )(ptr )) = uint32 (r .ReadLong ())
389
- }
390
-
391
- func (* uint32Codec ) Encode (ptr unsafe.Pointer , w * Writer ) {
392
- w .WriteLong (int64 (* ((* uint32 )(ptr ))))
393
- }
394
-
395
- type int32LongCodec struct {}
396
-
397
- func (* int32LongCodec ) Encode (ptr unsafe.Pointer , w * Writer ) {
398
- w .WriteLong (int64 (* ((* int32 )(ptr ))))
339
+ type largeInt interface {
340
+ ~ int32 | ~ uint32 | int64
399
341
}
400
342
401
- type int64Codec struct {}
343
+ type longCodec [ T largeInt ] struct {}
402
344
403
- func (* int64Codec ) Decode (ptr unsafe.Pointer , r * Reader ) {
404
- * ((* int64 )(ptr )) = r .ReadLong ()
345
+ func (* longCodec [ T ] ) Decode (ptr unsafe.Pointer , r * Reader ) {
346
+ * ((* T )(ptr )) = T ( r .ReadLong () )
405
347
}
406
348
407
- func (* int64Codec ) Encode (ptr unsafe.Pointer , w * Writer ) {
408
- w .WriteLong (* ((* int64 )(ptr )))
349
+ func (* longCodec [ T ] ) Encode (ptr unsafe.Pointer , w * Writer ) {
350
+ w .WriteLong (int64 ( * ((* T )(ptr ) )))
409
351
}
410
352
411
353
type float32Codec struct {}
0 commit comments