Skip to content

Commit cf2f85f

Browse files
author
Matthieu Vachon
committed
Some deprecation notices
- Renamed `TypeSize.UInt8` to `TypeSize.Uint8` - Renamed `TypeSize.UInt16` to `TypeSize.Uint16` - Renamed `TypeSize.UInt32` to `TypeSize.Uint32` - Renamed `TypeSize.UInt64` to `TypeSize.Uint64` - Renamed `TypeSize.UInt128` to `TypeSize.Uint128` - Renamed `Decoder.ReadUInt8` to `Decoder.ReadUint8`
1 parent 6e70b6c commit cf2f85f

File tree

2 files changed

+100
-58
lines changed

2 files changed

+100
-58
lines changed

decoder.go

Lines changed: 93 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -24,45 +24,81 @@ type UnmarshalerBinary interface {
2424
}
2525

2626
var TypeSize = struct {
27-
Byte int
28-
Int8 int
29-
UInt8 int
30-
UInt16 int
31-
Int16 int
32-
UInt32 int
33-
UInt64 int
34-
UInt128 int
35-
Float32 int
36-
Float64 int
37-
Checksum160 int
38-
Checksum256 int
39-
Checksum512 int
40-
PublicKey int
41-
Signature int
27+
Bool int
28+
Byte int
29+
30+
Int8 int
31+
Int16 int
32+
33+
Uint8 int
34+
Uint16 int
35+
Uint32 int
36+
Uint64 int
37+
Uint128 int
38+
39+
Float32 int
40+
Float64 int
41+
42+
Checksum160 int
43+
Checksum256 int
44+
Checksum512 int
45+
46+
PublicKey int
47+
Signature int
48+
4249
Tstamp int
4350
BlockTimestamp int
44-
CurrencyName int
45-
Bool int
51+
52+
CurrencyName int
53+
54+
// Deprecated Fields
55+
56+
// Deprecated: use Uint8 instead
57+
UInt8 int
58+
// Deprecated: use Uint16 instead
59+
UInt16 int
60+
// Deprecated: use Uint32 instead
61+
UInt32 int
62+
// Deprecated: use Uint64 instead
63+
UInt64 int
64+
// Deprecated: use Uint128 instead
65+
UInt128 int
4666
}{
47-
Byte: 1,
48-
Int8: 1,
49-
UInt8: 1,
50-
UInt16: 2,
51-
Int16: 2,
52-
UInt32: 4,
53-
UInt64: 8,
54-
UInt128: 16,
55-
Float32: 4,
56-
Float64: 8,
57-
Checksum160: 20,
58-
Checksum256: 32,
59-
Checksum512: 64,
60-
PublicKey: 34,
61-
Signature: 66,
67+
Byte: 1,
68+
Bool: 1,
69+
70+
Int8: 1,
71+
Int16: 2,
72+
73+
Uint8: 1,
74+
Uint16: 2,
75+
Uint32: 4,
76+
Uint64: 8,
77+
Uint128: 16,
78+
79+
Float32: 4,
80+
Float64: 8,
81+
82+
Checksum160: 20,
83+
Checksum256: 32,
84+
Checksum512: 64,
85+
86+
PublicKey: 34,
87+
Signature: 66,
88+
6289
Tstamp: 8,
6390
BlockTimestamp: 4,
64-
CurrencyName: 7,
65-
Bool: 1,
91+
92+
CurrencyName: 7,
93+
}
94+
95+
func init() {
96+
// Deprecated fields initialization
97+
TypeSize.UInt8 = TypeSize.Uint8
98+
TypeSize.UInt16 = TypeSize.Uint16
99+
TypeSize.UInt32 = TypeSize.Uint32
100+
TypeSize.UInt64 = TypeSize.Uint64
101+
TypeSize.UInt128 = TypeSize.Uint128
66102
}
67103

68104
var RegisteredActions = map[AccountName]map[ActionName]reflect.Type{}
@@ -592,10 +628,16 @@ func (d *Decoder) ReadBool() (out bool, err error) {
592628

593629
}
594630

595-
func (d *Decoder) ReadUInt8() (out uint8, err error) {
631+
func (d *Decoder) ReadUint8() (out uint8, err error) {
596632
out, err = d.ReadByte()
597633
return
598634
}
635+
636+
// Deprecated: Use `ReadUint8` (with a lower case `i`) instead
637+
func (d *Decoder) ReadUInt8() (out uint8, err error) {
638+
return d.ReadUint8()
639+
}
640+
599641
func (d *Decoder) ReadInt8() (out int8, err error) {
600642
b, err := d.ReadByte()
601643
out = int8(b)
@@ -606,13 +648,13 @@ func (d *Decoder) ReadInt8() (out int8, err error) {
606648
}
607649

608650
func (d *Decoder) ReadUint16() (out uint16, err error) {
609-
if d.remaining() < TypeSize.UInt16 {
610-
err = fmt.Errorf("uint16 required [%d] bytes, remaining [%d]", TypeSize.UInt16, d.remaining())
651+
if d.remaining() < TypeSize.Uint16 {
652+
err = fmt.Errorf("uint16 required [%d] bytes, remaining [%d]", TypeSize.Uint16, d.remaining())
611653
return
612654
}
613655

614656
out = binary.LittleEndian.Uint16(d.data[d.pos:])
615-
d.pos += TypeSize.UInt16
657+
d.pos += TypeSize.Uint16
616658
if loggingEnabled {
617659
decoderLog.Debug("read uint16", zap.Uint16("val", out))
618660
}
@@ -637,13 +679,13 @@ func (d *Decoder) ReadInt64() (out int64, err error) {
637679
}
638680

639681
func (d *Decoder) ReadUint32() (out uint32, err error) {
640-
if d.remaining() < TypeSize.UInt32 {
641-
err = fmt.Errorf("uint32 required [%d] bytes, remaining [%d]", TypeSize.UInt32, d.remaining())
682+
if d.remaining() < TypeSize.Uint32 {
683+
err = fmt.Errorf("uint32 required [%d] bytes, remaining [%d]", TypeSize.Uint32, d.remaining())
642684
return
643685
}
644686

645687
out = binary.LittleEndian.Uint32(d.data[d.pos:])
646-
d.pos += TypeSize.UInt32
688+
d.pos += TypeSize.Uint32
647689
if loggingEnabled {
648690
decoderLog.Debug("read uint32", zap.Uint32("val", out))
649691
}
@@ -659,31 +701,31 @@ func (d *Decoder) ReadInt32() (out int32, err error) {
659701
}
660702

661703
func (d *Decoder) ReadUint64() (out uint64, err error) {
662-
if d.remaining() < TypeSize.UInt64 {
663-
err = fmt.Errorf("uint64 required [%d] bytes, remaining [%d]", TypeSize.UInt64, d.remaining())
704+
if d.remaining() < TypeSize.Uint64 {
705+
err = fmt.Errorf("uint64 required [%d] bytes, remaining [%d]", TypeSize.Uint64, d.remaining())
664706
return
665707
}
666708

667-
data := d.data[d.pos : d.pos+TypeSize.UInt64]
709+
data := d.data[d.pos : d.pos+TypeSize.Uint64]
668710
out = binary.LittleEndian.Uint64(data)
669-
d.pos += TypeSize.UInt64
711+
d.pos += TypeSize.Uint64
670712
if loggingEnabled {
671713
decoderLog.Debug("read uint64", zap.Uint64("val", out), zap.Stringer("hex", HexBytes(data)))
672714
}
673715
return
674716
}
675717

676718
func (d *Decoder) ReadUint128(typeName string) (out Uint128, err error) {
677-
if d.remaining() < TypeSize.UInt128 {
678-
err = fmt.Errorf("%s required [%d] bytes, remaining [%d]", typeName, TypeSize.UInt128, d.remaining())
719+
if d.remaining() < TypeSize.Uint128 {
720+
err = fmt.Errorf("%s required [%d] bytes, remaining [%d]", typeName, TypeSize.Uint128, d.remaining())
679721
return
680722
}
681723

682-
data := d.data[d.pos : d.pos+TypeSize.UInt128]
724+
data := d.data[d.pos : d.pos+TypeSize.Uint128]
683725
out.Lo = binary.LittleEndian.Uint64(data)
684726
out.Hi = binary.LittleEndian.Uint64(data[8:])
685727

686-
d.pos += TypeSize.UInt128
728+
d.pos += TypeSize.Uint128
687729
if loggingEnabled {
688730
decoderLog.Debug("read uint128", zap.Stringer("hex", out), zap.Uint64("lo", out.Lo), zap.Uint64("lo", out.Lo))
689731
}
@@ -775,7 +817,7 @@ func (d *Decoder) ReadChecksum512() (out Checksum512, err error) {
775817
}
776818

777819
func (d *Decoder) ReadPublicKey() (out ecc.PublicKey, err error) {
778-
typeID, err := d.ReadUInt8()
820+
typeID, err := d.ReadUint8()
779821
if err != nil {
780822
return out, fmt.Errorf("unable to read public key type: %s", err)
781823
}
@@ -850,7 +892,7 @@ func (d *Decoder) readWAPublicKeyMaterial() (out []byte, err error) {
850892
}
851893

852894
func (d *Decoder) ReadSignature() (out ecc.Signature, err error) {
853-
typeID, err := d.ReadUInt8()
895+
typeID, err := d.ReadUint8()
854896
if err != nil {
855897
return out, fmt.Errorf("unable to read signature type: %s", err)
856898
}

encoder.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ func (e *Encoder) writeUint16(i uint16) (err error) {
295295
if loggingEnabled {
296296
encoderLog.Debug("write uint16", zap.Uint16("val", i))
297297
}
298-
buf := make([]byte, TypeSize.UInt16)
298+
buf := make([]byte, TypeSize.Uint16)
299299
binary.LittleEndian.PutUint16(buf, i)
300300
return e.toWriter(buf)
301301
}
@@ -318,7 +318,7 @@ func (e *Encoder) writeUint32(i uint32) (err error) {
318318
if loggingEnabled {
319319
encoderLog.Debug("write uint32", zap.Uint32("val", i))
320320
}
321-
buf := make([]byte, TypeSize.UInt32)
321+
buf := make([]byte, TypeSize.Uint32)
322322
binary.LittleEndian.PutUint32(buf, i)
323323
return e.toWriter(buf)
324324
}
@@ -334,7 +334,7 @@ func (e *Encoder) writeUint64(i uint64) (err error) {
334334
if loggingEnabled {
335335
encoderLog.Debug("write uint64", zap.Uint64("val", i))
336336
}
337-
buf := make([]byte, TypeSize.UInt64)
337+
buf := make([]byte, TypeSize.Uint64)
338338
binary.LittleEndian.PutUint64(buf, i)
339339
return e.toWriter(buf)
340340
}
@@ -343,9 +343,9 @@ func (e *Encoder) writeUint128(i Uint128) (err error) {
343343
if loggingEnabled {
344344
encoderLog.Debug("write uint128", zap.Stringer("hex", i), zap.Uint64("lo", i.Lo), zap.Uint64("hi", i.Hi))
345345
}
346-
buf := make([]byte, TypeSize.UInt128)
346+
buf := make([]byte, TypeSize.Uint128)
347347
binary.LittleEndian.PutUint64(buf, i.Lo)
348-
binary.LittleEndian.PutUint64(buf[TypeSize.UInt64:], i.Hi)
348+
binary.LittleEndian.PutUint64(buf[TypeSize.Uint64:], i.Hi)
349349
return e.toWriter(buf)
350350
}
351351

@@ -354,7 +354,7 @@ func (e *Encoder) writeFloat32(f float32) (err error) {
354354
encoderLog.Debug("write float32", zap.Float32("val", f))
355355
}
356356
i := math.Float32bits(f)
357-
buf := make([]byte, TypeSize.UInt32)
357+
buf := make([]byte, TypeSize.Uint32)
358358
binary.LittleEndian.PutUint32(buf, i)
359359

360360
return e.toWriter(buf)
@@ -364,7 +364,7 @@ func (e *Encoder) writeFloat64(f float64) (err error) {
364364
encoderLog.Debug("write float64", zap.Float64("val", f))
365365
}
366366
i := math.Float64bits(f)
367-
buf := make([]byte, TypeSize.UInt64)
367+
buf := make([]byte, TypeSize.Uint64)
368368
binary.LittleEndian.PutUint64(buf, i)
369369

370370
return e.toWriter(buf)

0 commit comments

Comments
 (0)