Skip to content

Commit da2a8fa

Browse files
committed
Fixed reference decode error.
1 parent 092546a commit da2a8fa

18 files changed

+133
-119
lines changed

encoding/array_decoder.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
| |
77
| encoding/array_decoder.go |
88
| |
9-
| LastModified: Jan 23, 2021 |
9+
| LastModified: May 14, 2021 |
1010
| Author: Ma Bingyao <[email protected]> |
1111
| |
1212
\*________________________________________________________*/
@@ -59,7 +59,7 @@ func (valdec arrayDecoder) Decode(dec *Decoder, p interface{}, tag byte) {
5959
}
6060
dec.Skip()
6161
default:
62-
dec.decodeError(valdec.at.Type1(), tag)
62+
dec.defaultDecode(valdec.at.Type1(), p, tag)
6363
}
6464
}
6565

encoding/big_decoder.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
| |
77
| encoding/big_decoder.go |
88
| |
9-
| LastModified: Feb 18, 2021 |
9+
| LastModified: May 14, 2021 |
1010
| Author: Ma Bingyao <[email protected]> |
1111
| |
1212
\*________________________________________________________*/
@@ -80,7 +80,7 @@ func (dec *Decoder) ReadBigFloat() *big.Float {
8080
return dec.readBigFloat(nil)
8181
}
8282

83-
func (dec *Decoder) decodeBigInt(t reflect.Type, tag byte) *big.Int {
83+
func (dec *Decoder) decodeBigInt(t reflect.Type, tag byte) (result *big.Int) {
8484
if i := intDigits[tag]; i != invalidDigit {
8585
return big.NewInt(int64(i))
8686
}
@@ -108,9 +108,9 @@ func (dec *Decoder) decodeBigInt(t reflect.Type, tag byte) *big.Int {
108108
}
109109
return dec.stringToBigInt(dec.ReadString(), t)
110110
default:
111-
dec.decodeError(t, tag)
111+
dec.defaultDecode(t, &result, tag)
112112
}
113-
return nil
113+
return
114114
}
115115

116116
func (dec *Decoder) decodeBigIntValue(t reflect.Type, tag byte) big.Int {
@@ -120,7 +120,7 @@ func (dec *Decoder) decodeBigIntValue(t reflect.Type, tag byte) big.Int {
120120
return *bigIntZero
121121
}
122122

123-
func (dec *Decoder) decodeBigFloat(t reflect.Type, tag byte) *big.Float {
123+
func (dec *Decoder) decodeBigFloat(t reflect.Type, tag byte) (result *big.Float) {
124124
if i := intDigits[tag]; i != invalidDigit {
125125
return big.NewFloat(float64(i))
126126
}
@@ -148,9 +148,9 @@ func (dec *Decoder) decodeBigFloat(t reflect.Type, tag byte) *big.Float {
148148
}
149149
return dec.stringToBigFloat(dec.ReadString(), t)
150150
default:
151-
dec.decodeError(t, tag)
151+
dec.defaultDecode(t, &result, tag)
152152
}
153-
return nil
153+
return
154154
}
155155

156156
func (dec *Decoder) decodeBigFloatValue(t reflect.Type, tag byte) big.Float {
@@ -160,7 +160,7 @@ func (dec *Decoder) decodeBigFloatValue(t reflect.Type, tag byte) big.Float {
160160
return *bigFloatZero
161161
}
162162

163-
func (dec *Decoder) decodeBigRat(t reflect.Type, tag byte) *big.Rat {
163+
func (dec *Decoder) decodeBigRat(t reflect.Type, tag byte) (result *big.Rat) {
164164
if i := intDigits[tag]; i != invalidDigit {
165165
return big.NewRat(int64(i), 1)
166166
}
@@ -185,9 +185,9 @@ func (dec *Decoder) decodeBigRat(t reflect.Type, tag byte) *big.Rat {
185185
}
186186
return dec.stringToBigRat(dec.ReadString(), t)
187187
default:
188-
dec.decodeError(t, tag)
188+
dec.defaultDecode(t, &result, tag)
189189
}
190-
return nil
190+
return
191191
}
192192

193193
func (dec *Decoder) decodeBigRatValue(t reflect.Type, tag byte) big.Rat {

encoding/bool_decoder.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
| |
77
| encoding/bool_decoder.go |
88
| |
9-
| LastModified: Jun 15, 2020 |
9+
| LastModified: May 14, 2021 |
1010
| Author: Ma Bingyao <[email protected]> |
1111
| |
1212
\*________________________________________________________*/
@@ -28,7 +28,7 @@ func (dec *Decoder) stringToBool(s string) bool {
2828
return b
2929
}
3030

31-
func (dec *Decoder) decodeBool(t reflect.Type, tag byte) bool {
31+
func (dec *Decoder) decodeBool(t reflect.Type, tag byte) (result bool) {
3232
if i := intDigits[tag]; i != invalidDigit {
3333
return i > 0
3434
}
@@ -57,9 +57,9 @@ func (dec *Decoder) decodeBool(t reflect.Type, tag byte) bool {
5757
}
5858
return dec.stringToBool(dec.ReadString())
5959
default:
60-
dec.decodeError(t, tag)
60+
dec.defaultDecode(t, &result, tag)
6161
}
62-
return false
62+
return
6363
}
6464

6565
func (dec *Decoder) decodeBoolPtr(t reflect.Type, tag byte) *bool {

encoding/bytes_decoder.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
| |
77
| encoding/bytes_decoder.go |
88
| |
9-
| LastModified: Feb 18, 2021 |
9+
| LastModified: May 14, 2021 |
1010
| Author: Ma Bingyao <[email protected]> |
1111
| |
1212
\*________________________________________________________*/
@@ -49,7 +49,7 @@ func (dec *Decoder) readUint8Slice(et reflect.Type) []byte {
4949
return slice
5050
}
5151

52-
func (dec *Decoder) decodeBytes(t reflect.Type, tag byte) []byte {
52+
func (dec *Decoder) decodeBytes(t reflect.Type, tag byte) (result []byte) {
5353
switch tag {
5454
case TagNull:
5555
return nil
@@ -70,9 +70,9 @@ func (dec *Decoder) decodeBytes(t reflect.Type, tag byte) []byte {
7070
bytes, _ := dec.ReadUUID().MarshalBinary()
7171
return bytes
7272
default:
73-
dec.decodeError(t, tag)
73+
dec.defaultDecode(t, &result, tag)
7474
}
75-
return nil
75+
return
7676
}
7777

7878
func (dec *Decoder) decodeBytesPtr(t reflect.Type, tag byte) *[]byte {

encoding/complex_decoder.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
| |
77
| encoding/complex_decoder.go |
88
| |
9-
| LastModified: Feb 18, 2021 |
9+
| LastModified: May 14, 2021 |
1010
| Author: Ma Bingyao <[email protected]> |
1111
| |
1212
\*________________________________________________________*/
@@ -37,7 +37,7 @@ func (dec *Decoder) stringToComplex128(s string) complex128 {
3737
return c
3838
}
3939

40-
func (dec *Decoder) decodeComplex64(t reflect.Type, tag byte) complex64 {
40+
func (dec *Decoder) decodeComplex64(t reflect.Type, tag byte) (result complex64) {
4141
if i := intDigits[tag]; i != invalidDigit {
4242
return complex(float32(i), 0)
4343
}
@@ -62,9 +62,9 @@ func (dec *Decoder) decodeComplex64(t reflect.Type, tag byte) complex64 {
6262
}
6363
return dec.stringToComplex64(dec.ReadString())
6464
default:
65-
dec.decodeError(t, tag)
65+
dec.defaultDecode(t, &result, tag)
6666
}
67-
return 0
67+
return
6868
}
6969

7070
func (dec *Decoder) decodeComplex64Ptr(t reflect.Type, tag byte) *complex64 {
@@ -75,7 +75,7 @@ func (dec *Decoder) decodeComplex64Ptr(t reflect.Type, tag byte) *complex64 {
7575
return &c
7676
}
7777

78-
func (dec *Decoder) decodeComplex128(t reflect.Type, tag byte) complex128 {
78+
func (dec *Decoder) decodeComplex128(t reflect.Type, tag byte) (result complex128) {
7979
if i := intDigits[tag]; i != invalidDigit {
8080
return complex(float64(i), 0)
8181
}
@@ -100,9 +100,9 @@ func (dec *Decoder) decodeComplex128(t reflect.Type, tag byte) complex128 {
100100
}
101101
return dec.stringToComplex128(dec.ReadString())
102102
default:
103-
dec.decodeError(t, tag)
103+
dec.defaultDecode(t, &result, tag)
104104
}
105-
return 0
105+
return
106106
}
107107

108108
func (dec *Decoder) decodeComplex128Ptr(t reflect.Type, tag byte) *complex128 {

encoding/decoder.go

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
| |
77
| encoding/decoder.go |
88
| |
9-
| LastModified: Feb 18, 2021 |
9+
| LastModified: May 14, 2021 |
1010
| Author: Ma Bingyao <[email protected]> |
1111
| |
1212
\*________________________________________________________*/
@@ -213,18 +213,6 @@ func (dec *Decoder) fastDecodePtr(p interface{}, tag byte) bool {
213213
}
214214

215215
func (dec *Decoder) decode(p interface{}, tag byte) {
216-
switch tag {
217-
case TagRef:
218-
dec.ReadReference(p)
219-
return
220-
case TagClass:
221-
dec.ReadStruct()
222-
dec.Decode(p)
223-
return
224-
case TagError:
225-
dec.Error = DecodeError(dec.decodeString(stringType, dec.NextByte()))
226-
return
227-
}
228216
if dec.fastDecode(p, tag) {
229217
return
230218
}
@@ -510,6 +498,22 @@ func (dec *Decoder) decodeStringError(s string, typeName string) {
510498
}
511499
}
512500

501+
func (dec *Decoder) defaultDecode(t reflect.Type, p interface{}, tag byte) {
502+
switch tag {
503+
case TagRef:
504+
dec.ReadReference(p)
505+
return
506+
case TagClass:
507+
dec.ReadStruct(t)
508+
dec.Decode(p)
509+
return
510+
case TagError:
511+
dec.Error = DecodeError(dec.decodeString(stringType, dec.NextByte()))
512+
return
513+
default:
514+
dec.decodeError(t, tag)
515+
}
516+
}
513517
func (dec *Decoder) decodeError(t reflect.Type, tag byte) {
514518
if dec.Error == nil {
515519
var iface interface{}

encoding/float_decoder.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
| |
77
| encoding/float_decoder.go |
88
| |
9-
| LastModified: Jun 15, 2020 |
9+
| LastModified: May 14, 2021 |
1010
| Author: Ma Bingyao <[email protected]> |
1111
| |
1212
\*________________________________________________________*/
@@ -44,7 +44,7 @@ func (dec *Decoder) readInf() float64 {
4444
return math.Inf(1)
4545
}
4646

47-
func (dec *Decoder) decodeFloat32(t reflect.Type, tag byte) float32 {
47+
func (dec *Decoder) decodeFloat32(t reflect.Type, tag byte) (result float32) {
4848
if i := intDigits[tag]; i != invalidDigit {
4949
return float32(i)
5050
}
@@ -69,9 +69,9 @@ func (dec *Decoder) decodeFloat32(t reflect.Type, tag byte) float32 {
6969
}
7070
return dec.stringToFloat32(dec.ReadString())
7171
default:
72-
dec.decodeError(t, tag)
72+
dec.defaultDecode(t, &result, tag)
7373
}
74-
return 0
74+
return
7575
}
7676

7777
func (dec *Decoder) decodeFloat32Ptr(t reflect.Type, tag byte) *float32 {
@@ -82,7 +82,7 @@ func (dec *Decoder) decodeFloat32Ptr(t reflect.Type, tag byte) *float32 {
8282
return &f
8383
}
8484

85-
func (dec *Decoder) decodeFloat64(t reflect.Type, tag byte) float64 {
85+
func (dec *Decoder) decodeFloat64(t reflect.Type, tag byte) (result float64) {
8686
if i := intDigits[tag]; i != invalidDigit {
8787
return float64(i)
8888
}
@@ -107,9 +107,9 @@ func (dec *Decoder) decodeFloat64(t reflect.Type, tag byte) float64 {
107107
}
108108
return dec.stringToFloat64(dec.ReadString())
109109
default:
110-
dec.decodeError(t, tag)
110+
dec.defaultDecode(t, &result, tag)
111111
}
112-
return 0
112+
return
113113
}
114114

115115
func (dec *Decoder) decodeFloat64Ptr(t reflect.Type, tag byte) *float64 {

0 commit comments

Comments
 (0)