aboutsummaryrefslogtreecommitdiff
path: root/src/encoding
diff options
context:
space:
mode:
Diffstat (limited to 'src/encoding')
-rw-r--r--src/encoding/gob/dec_helpers.go32
-rw-r--r--src/encoding/gob/decgen.go2
-rw-r--r--src/encoding/gob/decode.go9
-rw-r--r--src/encoding/gob/enc_helpers.go32
-rw-r--r--src/encoding/gob/encgen.go2
-rw-r--r--src/encoding/gob/encode.go9
6 files changed, 46 insertions, 40 deletions
diff --git a/src/encoding/gob/dec_helpers.go b/src/encoding/gob/dec_helpers.go
index 44a74e2442..e8696830e5 100644
--- a/src/encoding/gob/dec_helpers.go
+++ b/src/encoding/gob/dec_helpers.go
@@ -58,7 +58,7 @@ func decBoolArray(state *decoderState, v reflect.Value, length int, ovfl error)
}
func decBoolSlice(state *decoderState, v reflect.Value, length int, ovfl error) bool {
- slice, ok := v.Interface().([]bool)
+ slice, ok := reflect.TypeAssert[[]bool](v)
if !ok {
// It is kind bool but not type bool. TODO: We can handle this unsafely.
return false
@@ -85,7 +85,7 @@ func decComplex64Array(state *decoderState, v reflect.Value, length int, ovfl er
}
func decComplex64Slice(state *decoderState, v reflect.Value, length int, ovfl error) bool {
- slice, ok := v.Interface().([]complex64)
+ slice, ok := reflect.TypeAssert[[]complex64](v)
if !ok {
// It is kind complex64 but not type complex64. TODO: We can handle this unsafely.
return false
@@ -114,7 +114,7 @@ func decComplex128Array(state *decoderState, v reflect.Value, length int, ovfl e
}
func decComplex128Slice(state *decoderState, v reflect.Value, length int, ovfl error) bool {
- slice, ok := v.Interface().([]complex128)
+ slice, ok := reflect.TypeAssert[[]complex128](v)
if !ok {
// It is kind complex128 but not type complex128. TODO: We can handle this unsafely.
return false
@@ -143,7 +143,7 @@ func decFloat32Array(state *decoderState, v reflect.Value, length int, ovfl erro
}
func decFloat32Slice(state *decoderState, v reflect.Value, length int, ovfl error) bool {
- slice, ok := v.Interface().([]float32)
+ slice, ok := reflect.TypeAssert[[]float32](v)
if !ok {
// It is kind float32 but not type float32. TODO: We can handle this unsafely.
return false
@@ -170,7 +170,7 @@ func decFloat64Array(state *decoderState, v reflect.Value, length int, ovfl erro
}
func decFloat64Slice(state *decoderState, v reflect.Value, length int, ovfl error) bool {
- slice, ok := v.Interface().([]float64)
+ slice, ok := reflect.TypeAssert[[]float64](v)
if !ok {
// It is kind float64 but not type float64. TODO: We can handle this unsafely.
return false
@@ -197,7 +197,7 @@ func decIntArray(state *decoderState, v reflect.Value, length int, ovfl error) b
}
func decIntSlice(state *decoderState, v reflect.Value, length int, ovfl error) bool {
- slice, ok := v.Interface().([]int)
+ slice, ok := reflect.TypeAssert[[]int](v)
if !ok {
// It is kind int but not type int. TODO: We can handle this unsafely.
return false
@@ -229,7 +229,7 @@ func decInt16Array(state *decoderState, v reflect.Value, length int, ovfl error)
}
func decInt16Slice(state *decoderState, v reflect.Value, length int, ovfl error) bool {
- slice, ok := v.Interface().([]int16)
+ slice, ok := reflect.TypeAssert[[]int16](v)
if !ok {
// It is kind int16 but not type int16. TODO: We can handle this unsafely.
return false
@@ -260,7 +260,7 @@ func decInt32Array(state *decoderState, v reflect.Value, length int, ovfl error)
}
func decInt32Slice(state *decoderState, v reflect.Value, length int, ovfl error) bool {
- slice, ok := v.Interface().([]int32)
+ slice, ok := reflect.TypeAssert[[]int32](v)
if !ok {
// It is kind int32 but not type int32. TODO: We can handle this unsafely.
return false
@@ -291,7 +291,7 @@ func decInt64Array(state *decoderState, v reflect.Value, length int, ovfl error)
}
func decInt64Slice(state *decoderState, v reflect.Value, length int, ovfl error) bool {
- slice, ok := v.Interface().([]int64)
+ slice, ok := reflect.TypeAssert[[]int64](v)
if !ok {
// It is kind int64 but not type int64. TODO: We can handle this unsafely.
return false
@@ -318,7 +318,7 @@ func decInt8Array(state *decoderState, v reflect.Value, length int, ovfl error)
}
func decInt8Slice(state *decoderState, v reflect.Value, length int, ovfl error) bool {
- slice, ok := v.Interface().([]int8)
+ slice, ok := reflect.TypeAssert[[]int8](v)
if !ok {
// It is kind int8 but not type int8. TODO: We can handle this unsafely.
return false
@@ -349,7 +349,7 @@ func decStringArray(state *decoderState, v reflect.Value, length int, ovfl error
}
func decStringSlice(state *decoderState, v reflect.Value, length int, ovfl error) bool {
- slice, ok := v.Interface().([]string)
+ slice, ok := reflect.TypeAssert[[]string](v)
if !ok {
// It is kind string but not type string. TODO: We can handle this unsafely.
return false
@@ -390,7 +390,7 @@ func decUintArray(state *decoderState, v reflect.Value, length int, ovfl error)
}
func decUintSlice(state *decoderState, v reflect.Value, length int, ovfl error) bool {
- slice, ok := v.Interface().([]uint)
+ slice, ok := reflect.TypeAssert[[]uint](v)
if !ok {
// It is kind uint but not type uint. TODO: We can handle this unsafely.
return false
@@ -421,7 +421,7 @@ func decUint16Array(state *decoderState, v reflect.Value, length int, ovfl error
}
func decUint16Slice(state *decoderState, v reflect.Value, length int, ovfl error) bool {
- slice, ok := v.Interface().([]uint16)
+ slice, ok := reflect.TypeAssert[[]uint16](v)
if !ok {
// It is kind uint16 but not type uint16. TODO: We can handle this unsafely.
return false
@@ -452,7 +452,7 @@ func decUint32Array(state *decoderState, v reflect.Value, length int, ovfl error
}
func decUint32Slice(state *decoderState, v reflect.Value, length int, ovfl error) bool {
- slice, ok := v.Interface().([]uint32)
+ slice, ok := reflect.TypeAssert[[]uint32](v)
if !ok {
// It is kind uint32 but not type uint32. TODO: We can handle this unsafely.
return false
@@ -483,7 +483,7 @@ func decUint64Array(state *decoderState, v reflect.Value, length int, ovfl error
}
func decUint64Slice(state *decoderState, v reflect.Value, length int, ovfl error) bool {
- slice, ok := v.Interface().([]uint64)
+ slice, ok := reflect.TypeAssert[[]uint64](v)
if !ok {
// It is kind uint64 but not type uint64. TODO: We can handle this unsafely.
return false
@@ -510,7 +510,7 @@ func decUintptrArray(state *decoderState, v reflect.Value, length int, ovfl erro
}
func decUintptrSlice(state *decoderState, v reflect.Value, length int, ovfl error) bool {
- slice, ok := v.Interface().([]uintptr)
+ slice, ok := reflect.TypeAssert[[]uintptr](v)
if !ok {
// It is kind uintptr but not type uintptr. TODO: We can handle this unsafely.
return false
diff --git a/src/encoding/gob/decgen.go b/src/encoding/gob/decgen.go
index af4cdbee9d..420c86207c 100644
--- a/src/encoding/gob/decgen.go
+++ b/src/encoding/gob/decgen.go
@@ -231,7 +231,7 @@ func dec%[2]sArray(state *decoderState, v reflect.Value, length int, ovfl error)
const sliceHelper = `
func dec%[2]sSlice(state *decoderState, v reflect.Value, length int, ovfl error) bool {
- slice, ok := v.Interface().([]%[1]s)
+ slice, ok := reflect.TypeAssert[[]%[1]s](v)
if !ok {
// It is kind %[1]s but not type %[1]s. TODO: We can handle this unsafely.
return false
diff --git a/src/encoding/gob/decode.go b/src/encoding/gob/decode.go
index 26b5f6d62b..fb7837b11b 100644
--- a/src/encoding/gob/decode.go
+++ b/src/encoding/gob/decode.go
@@ -768,11 +768,14 @@ func (dec *Decoder) decodeGobDecoder(ut *userTypeInfo, state *decoderState, valu
// We know it's one of these.
switch ut.externalDec {
case xGob:
- err = value.Interface().(GobDecoder).GobDecode(b)
+ gobDecoder, _ := reflect.TypeAssert[GobDecoder](value)
+ err = gobDecoder.GobDecode(b)
case xBinary:
- err = value.Interface().(encoding.BinaryUnmarshaler).UnmarshalBinary(b)
+ binaryUnmarshaler, _ := reflect.TypeAssert[encoding.BinaryUnmarshaler](value)
+ err = binaryUnmarshaler.UnmarshalBinary(b)
case xText:
- err = value.Interface().(encoding.TextUnmarshaler).UnmarshalText(b)
+ textUnmarshaler, _ := reflect.TypeAssert[encoding.TextUnmarshaler](value)
+ err = textUnmarshaler.UnmarshalText(b)
}
if err != nil {
error_(err)
diff --git a/src/encoding/gob/enc_helpers.go b/src/encoding/gob/enc_helpers.go
index c3b4ca8972..a9c45a4669 100644
--- a/src/encoding/gob/enc_helpers.go
+++ b/src/encoding/gob/enc_helpers.go
@@ -57,7 +57,7 @@ func encBoolArray(state *encoderState, v reflect.Value) bool {
}
func encBoolSlice(state *encoderState, v reflect.Value) bool {
- slice, ok := v.Interface().([]bool)
+ slice, ok := reflect.TypeAssert[[]bool](v)
if !ok {
// It is kind bool but not type bool. TODO: We can handle this unsafely.
return false
@@ -83,7 +83,7 @@ func encComplex64Array(state *encoderState, v reflect.Value) bool {
}
func encComplex64Slice(state *encoderState, v reflect.Value) bool {
- slice, ok := v.Interface().([]complex64)
+ slice, ok := reflect.TypeAssert[[]complex64](v)
if !ok {
// It is kind complex64 but not type complex64. TODO: We can handle this unsafely.
return false
@@ -108,7 +108,7 @@ func encComplex128Array(state *encoderState, v reflect.Value) bool {
}
func encComplex128Slice(state *encoderState, v reflect.Value) bool {
- slice, ok := v.Interface().([]complex128)
+ slice, ok := reflect.TypeAssert[[]complex128](v)
if !ok {
// It is kind complex128 but not type complex128. TODO: We can handle this unsafely.
return false
@@ -133,7 +133,7 @@ func encFloat32Array(state *encoderState, v reflect.Value) bool {
}
func encFloat32Slice(state *encoderState, v reflect.Value) bool {
- slice, ok := v.Interface().([]float32)
+ slice, ok := reflect.TypeAssert[[]float32](v)
if !ok {
// It is kind float32 but not type float32. TODO: We can handle this unsafely.
return false
@@ -156,7 +156,7 @@ func encFloat64Array(state *encoderState, v reflect.Value) bool {
}
func encFloat64Slice(state *encoderState, v reflect.Value) bool {
- slice, ok := v.Interface().([]float64)
+ slice, ok := reflect.TypeAssert[[]float64](v)
if !ok {
// It is kind float64 but not type float64. TODO: We can handle this unsafely.
return false
@@ -179,7 +179,7 @@ func encIntArray(state *encoderState, v reflect.Value) bool {
}
func encIntSlice(state *encoderState, v reflect.Value) bool {
- slice, ok := v.Interface().([]int)
+ slice, ok := reflect.TypeAssert[[]int](v)
if !ok {
// It is kind int but not type int. TODO: We can handle this unsafely.
return false
@@ -201,7 +201,7 @@ func encInt16Array(state *encoderState, v reflect.Value) bool {
}
func encInt16Slice(state *encoderState, v reflect.Value) bool {
- slice, ok := v.Interface().([]int16)
+ slice, ok := reflect.TypeAssert[[]int16](v)
if !ok {
// It is kind int16 but not type int16. TODO: We can handle this unsafely.
return false
@@ -223,7 +223,7 @@ func encInt32Array(state *encoderState, v reflect.Value) bool {
}
func encInt32Slice(state *encoderState, v reflect.Value) bool {
- slice, ok := v.Interface().([]int32)
+ slice, ok := reflect.TypeAssert[[]int32](v)
if !ok {
// It is kind int32 but not type int32. TODO: We can handle this unsafely.
return false
@@ -245,7 +245,7 @@ func encInt64Array(state *encoderState, v reflect.Value) bool {
}
func encInt64Slice(state *encoderState, v reflect.Value) bool {
- slice, ok := v.Interface().([]int64)
+ slice, ok := reflect.TypeAssert[[]int64](v)
if !ok {
// It is kind int64 but not type int64. TODO: We can handle this unsafely.
return false
@@ -267,7 +267,7 @@ func encInt8Array(state *encoderState, v reflect.Value) bool {
}
func encInt8Slice(state *encoderState, v reflect.Value) bool {
- slice, ok := v.Interface().([]int8)
+ slice, ok := reflect.TypeAssert[[]int8](v)
if !ok {
// It is kind int8 but not type int8. TODO: We can handle this unsafely.
return false
@@ -289,7 +289,7 @@ func encStringArray(state *encoderState, v reflect.Value) bool {
}
func encStringSlice(state *encoderState, v reflect.Value) bool {
- slice, ok := v.Interface().([]string)
+ slice, ok := reflect.TypeAssert[[]string](v)
if !ok {
// It is kind string but not type string. TODO: We can handle this unsafely.
return false
@@ -312,7 +312,7 @@ func encUintArray(state *encoderState, v reflect.Value) bool {
}
func encUintSlice(state *encoderState, v reflect.Value) bool {
- slice, ok := v.Interface().([]uint)
+ slice, ok := reflect.TypeAssert[[]uint](v)
if !ok {
// It is kind uint but not type uint. TODO: We can handle this unsafely.
return false
@@ -334,7 +334,7 @@ func encUint16Array(state *encoderState, v reflect.Value) bool {
}
func encUint16Slice(state *encoderState, v reflect.Value) bool {
- slice, ok := v.Interface().([]uint16)
+ slice, ok := reflect.TypeAssert[[]uint16](v)
if !ok {
// It is kind uint16 but not type uint16. TODO: We can handle this unsafely.
return false
@@ -356,7 +356,7 @@ func encUint32Array(state *encoderState, v reflect.Value) bool {
}
func encUint32Slice(state *encoderState, v reflect.Value) bool {
- slice, ok := v.Interface().([]uint32)
+ slice, ok := reflect.TypeAssert[[]uint32](v)
if !ok {
// It is kind uint32 but not type uint32. TODO: We can handle this unsafely.
return false
@@ -378,7 +378,7 @@ func encUint64Array(state *encoderState, v reflect.Value) bool {
}
func encUint64Slice(state *encoderState, v reflect.Value) bool {
- slice, ok := v.Interface().([]uint64)
+ slice, ok := reflect.TypeAssert[[]uint64](v)
if !ok {
// It is kind uint64 but not type uint64. TODO: We can handle this unsafely.
return false
@@ -400,7 +400,7 @@ func encUintptrArray(state *encoderState, v reflect.Value) bool {
}
func encUintptrSlice(state *encoderState, v reflect.Value) bool {
- slice, ok := v.Interface().([]uintptr)
+ slice, ok := reflect.TypeAssert[[]uintptr](v)
if !ok {
// It is kind uintptr but not type uintptr. TODO: We can handle this unsafely.
return false
diff --git a/src/encoding/gob/encgen.go b/src/encoding/gob/encgen.go
index 64f5c69bd4..b89fa47ef6 100644
--- a/src/encoding/gob/encgen.go
+++ b/src/encoding/gob/encgen.go
@@ -208,7 +208,7 @@ func enc%[2]sArray(state *encoderState, v reflect.Value) bool {
const sliceHelper = `
func enc%[2]sSlice(state *encoderState, v reflect.Value) bool {
- slice, ok := v.Interface().([]%[1]s)
+ slice, ok := reflect.TypeAssert[[]%[1]s](v)
if !ok {
// It is kind %[1]s but not type %[1]s. TODO: We can handle this unsafely.
return false
diff --git a/src/encoding/gob/encode.go b/src/encoding/gob/encode.go
index ed3494218c..15932aabe0 100644
--- a/src/encoding/gob/encode.go
+++ b/src/encoding/gob/encode.go
@@ -440,11 +440,14 @@ func (enc *Encoder) encodeGobEncoder(b *encBuffer, ut *userTypeInfo, v reflect.V
// We know it's one of these.
switch ut.externalEnc {
case xGob:
- data, err = v.Interface().(GobEncoder).GobEncode()
+ gobEncoder, _ := reflect.TypeAssert[GobEncoder](v)
+ data, err = gobEncoder.GobEncode()
case xBinary:
- data, err = v.Interface().(encoding.BinaryMarshaler).MarshalBinary()
+ binaryMarshaler, _ := reflect.TypeAssert[encoding.BinaryMarshaler](v)
+ data, err = binaryMarshaler.MarshalBinary()
case xText:
- data, err = v.Interface().(encoding.TextMarshaler).MarshalText()
+ textMarshaler, _ := reflect.TypeAssert[encoding.TextMarshaler](v)
+ data, err = textMarshaler.MarshalText()
}
if err != nil {
error_(err)