// Check type compatibility.
// TODO(r): need to make the decoder work correctly if the wire type is compatible
// but not equal to the local type (e.g, extra fields).
- if info.wire.name != dec.seen[id].name {
+ if info.wire.name() != dec.seen[id].name() {
dec.state.err = os.ErrorString("gob decode: incorrect type for wire value");
return dec.state.err
}
t.Fatal("error decoding ET1 type:", err);
}
info := getTypeInfo(reflect.Typeof(ET1{}));
- trueWire1 := &wireType{name:"ET1", s: info.typeId.gobType().(*structType)};
+ trueWire1 := &wireType{s: info.typeId.gobType().(*structType)};
if !reflect.DeepEqual(wire1, trueWire1) {
t.Fatalf("invalid wireType for ET1: expected %+v; got %+v\n", *trueWire1, *wire1);
}
t.Fatal("error decoding ET2 type:", err);
}
info = getTypeInfo(reflect.Typeof(ET2{}));
- trueWire2 := &wireType{name:"ET2", s: info.typeId.gobType().(*structType)};
+ trueWire2 := &wireType{s: info.typeId.gobType().(*structType)};
if !reflect.DeepEqual(wire2, trueWire2) {
t.Fatalf("invalid wireType for ET2: expected %+v; got %+v\n", *trueWire2, *wire2);
}
// are built in encode.go's init() function.
type wireType struct {
- name string;
s *structType;
}
+func (w *wireType) name() string {
+ // generalize once we can have non-struct types on the wire.
+ return w.s.name
+}
+
type decEngine struct // defined in decode.go
type encEngine struct // defined in encode.go
type typeInfo struct {
path, name := rt.Name();
info.typeId = getType(name, rt).id();
// assume it's a struct type
- info.wire = &wireType{name, info.typeId.gobType().(*structType)};
+ info.wire = &wireType{info.typeId.gobType().(*structType)};
typeInfoMap[rt] = info;
}
return info;