mirror of
https://github.com/golang/go.git
synced 2025-11-09 21:21:03 +00:00
gob: support GobEncoder for type T when the receiver is *T.
Still to do: **T. R=rsc CC=golang-dev https://golang.org/cl/4247061
This commit is contained in:
parent
2168e6aaf1
commit
22c45c558b
4 changed files with 99 additions and 56 deletions
|
|
@ -573,8 +573,11 @@ func (enc *Encoder) encOpFor(rt reflect.Type, inProgress map[reflect.Type]*encOp
|
|||
// GobEncoder.
|
||||
func (enc *Encoder) gobEncodeOpFor(ut *userTypeInfo) (*encOp, int) {
|
||||
rt := ut.user
|
||||
if ut.encIndir != 0 {
|
||||
errorf("gob: TODO: can't handle indirection to reach GobEncoder")
|
||||
if ut.encIndir > 0 {
|
||||
errorf("gob: TODO: can't handle >0 indirections to reach GobEncoder")
|
||||
}
|
||||
if ut.encIndir == -1 {
|
||||
rt = reflect.PtrTo(rt)
|
||||
}
|
||||
index := -1
|
||||
for i := 0; i < rt.NumMethod(); i++ {
|
||||
|
|
@ -588,8 +591,15 @@ func (enc *Encoder) gobEncodeOpFor(ut *userTypeInfo) (*encOp, int) {
|
|||
}
|
||||
var op encOp
|
||||
op = func(i *encInstr, state *encoderState, p unsafe.Pointer) {
|
||||
// TODO: this will need fixing when ut.encIndr != 0.
|
||||
v := reflect.NewValue(unsafe.Unreflect(rt, p))
|
||||
var v reflect.Value
|
||||
switch {
|
||||
case ut.encIndir == 0:
|
||||
v = reflect.NewValue(unsafe.Unreflect(rt, p))
|
||||
case ut.encIndir == -1:
|
||||
v = reflect.NewValue(unsafe.Unreflect(rt, unsafe.Pointer(&p)))
|
||||
default:
|
||||
errorf("gob: TODO: can't handle >0 indirections to reach GobEncoder")
|
||||
}
|
||||
state.update(i)
|
||||
state.enc.encodeGobEncoder(state.b, v, index)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue