// decodeGobDecoder decodes something implementing the GobDecoder interface.
// The data is encoded as a byte slice.
-func (dec *Decoder) decodeGobDecoder(state *decoderState, v reflect.Value, index int) {
+func (dec *Decoder) decodeGobDecoder(state *decoderState, v reflect.Value) {
// Read the bytes for the value.
b := make([]byte, state.decodeUint())
_, err := state.b.Read(b)
} else {
v = reflect.ValueOf(unsafe.Unreflect(rcvrType, p))
}
- state.dec.decodeGobDecoder(state, v, methodIndex(rcvrType, gobDecodeMethodName))
+ state.dec.decodeGobDecoder(state, v)
}
return &op, int(ut.indir)
// encGobEncoder encodes a value that implements the GobEncoder interface.
// The data is sent as a byte array.
-func (enc *Encoder) encodeGobEncoder(b *bytes.Buffer, v reflect.Value, index int) {
+func (enc *Encoder) encodeGobEncoder(b *bytes.Buffer, v reflect.Value) {
// TODO: should we catch panics from the called method?
// We know it's a GobEncoder, so just call the method directly.
data, err := v.Interface().(GobEncoder).GobEncode()
return &op, indir
}
-// methodIndex returns which method of rt implements the method.
-func methodIndex(rt reflect.Type, method string) int {
- for i := 0; i < rt.NumMethod(); i++ {
- if rt.Method(i).Name == method {
- return i
- }
- }
- errorf("internal error: can't find method %s", method)
- return 0
-}
-
// gobEncodeOpFor returns the op for a type that is known to implement
// GobEncoder.
func (enc *Encoder) gobEncodeOpFor(ut *userTypeInfo) (*encOp, int) {
v = reflect.ValueOf(unsafe.Unreflect(rt, p))
}
state.update(i)
- state.enc.encodeGobEncoder(state.b, v, methodIndex(rt, gobEncodeMethodName))
+ state.enc.encodeGobEncoder(state.b, v)
}
return &op, int(ut.encIndir) // encIndir: op will get called with p == address of receiver.
}
return
}
-const (
- gobEncodeMethodName = "GobEncode"
- gobDecodeMethodName = "GobDecode"
-)
-
var (
gobEncoderInterfaceType = reflect.TypeOf(new(GobEncoder)).Elem()
gobDecoderInterfaceType = reflect.TypeOf(new(GobDecoder)).Elem()