@@ -22,43 +22,43 @@ func createDecoderOfNative(schema Schema, typ reflect2.Type) ValDecoder {
2222 if schema .Type () != Int {
2323 break
2424 }
25- return & intCodec {}
25+ return & intCodec [ int ] {}
2626
2727 case reflect .Int8 :
2828 if schema .Type () != Int {
2929 break
3030 }
31- return & int8Codec {}
31+ return & intCodec [ int8 ] {}
3232
3333 case reflect .Uint8 :
3434 if schema .Type () != Int {
3535 break
3636 }
37- return & uint8Codec {}
37+ return & intCodec [ uint8 ] {}
3838
3939 case reflect .Int16 :
4040 if schema .Type () != Int {
4141 break
4242 }
43- return & int16Codec {}
43+ return & intCodec [ int16 ] {}
4444
4545 case reflect .Uint16 :
4646 if schema .Type () != Int {
4747 break
4848 }
49- return & uint16Codec {}
49+ return & intCodec [ uint16 ] {}
5050
5151 case reflect .Int32 :
5252 if schema .Type () != Int {
5353 break
5454 }
55- return & int32Codec {}
55+ return & intCodec [ int32 ] {}
5656
5757 case reflect .Uint32 :
5858 if schema .Type () != Long {
5959 break
6060 }
61- return & uint32Codec {}
61+ return & longCodec [ uint32 ] {}
6262
6363 case reflect .Int64 :
6464 st := schema .Type ()
@@ -71,7 +71,7 @@ func createDecoderOfNative(schema Schema, typ reflect2.Type) ValDecoder {
7171 return & timeMicrosCodec {}
7272
7373 case st == Long :
74- return & int64Codec {}
74+ return & longCodec [ int64 ] {}
7575
7676 default :
7777 break
@@ -157,46 +157,46 @@ func createEncoderOfNative(schema Schema, typ reflect2.Type) ValEncoder {
157157 if schema .Type () != Int {
158158 break
159159 }
160- return & intCodec {}
160+ return & intCodec [ int ] {}
161161
162162 case reflect .Int8 :
163163 if schema .Type () != Int {
164164 break
165165 }
166- return & int8Codec {}
166+ return & intCodec [ int8 ] {}
167167
168168 case reflect .Uint8 :
169169 if schema .Type () != Int {
170170 break
171171 }
172- return & uint8Codec {}
172+ return & intCodec [ uint8 ] {}
173173
174174 case reflect .Int16 :
175175 if schema .Type () != Int {
176176 break
177177 }
178- return & int16Codec {}
178+ return & intCodec [ int16 ] {}
179179
180180 case reflect .Uint16 :
181181 if schema .Type () != Int {
182182 break
183183 }
184- return & uint16Codec {}
184+ return & intCodec [ uint16 ] {}
185185
186186 case reflect .Int32 :
187187 switch schema .Type () {
188188 case Long :
189- return & int32LongCodec {}
189+ return & longCodec [ int32 ] {}
190190
191191 case Int :
192- return & int32Codec {}
192+ return & intCodec [ int32 ] {}
193193 }
194194
195195 case reflect .Uint32 :
196196 if schema .Type () != Long {
197197 break
198198 }
199- return & uint32Codec {}
199+ return & longCodec [ uint32 ] {}
200200
201201 case reflect .Int64 :
202202 st := schema .Type ()
@@ -209,7 +209,7 @@ func createEncoderOfNative(schema Schema, typ reflect2.Type) ValEncoder {
209209 return & timeMicrosCodec {}
210210
211211 case st == Long :
212- return & int64Codec {}
212+ return & longCodec [ int64 ] {}
213213
214214 default :
215215 break
@@ -322,90 +322,32 @@ func (*boolCodec) Encode(ptr unsafe.Pointer, w *Writer) {
322322 w .WriteBool (* ((* bool )(ptr )))
323323}
324324
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
343327}
344328
345- type uint8Codec struct {}
329+ type intCodec [ T smallInt ] struct {}
346330
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 ())
349333}
350334
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 ))))
353337}
354338
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
399341}
400342
401- type int64Codec struct {}
343+ type longCodec [ T largeInt ] struct {}
402344
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 () )
405347}
406348
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 ) )))
409351}
410352
411353type float32Codec struct {}
0 commit comments