]> Cypherpunks repositories - gostls13.git/commitdiff
the name of the type was being sent twice. drop the outer instance.
authorRob Pike <r@golang.org>
Mon, 13 Jul 2009 18:41:02 +0000 (11:41 -0700)
committerRob Pike <r@golang.org>
Mon, 13 Jul 2009 18:41:02 +0000 (11:41 -0700)
R=rsc
DELTA=10  (5 added, 1 deleted, 4 changed)
OCL=31523
CL=31526

src/pkg/gob/decoder.go
src/pkg/gob/encoder_test.go
src/pkg/gob/type.go

index 4941a788b0524609af8ca5e302255a54a0c20985..8676533e62bdf224b91f9406c0e56aef3e9ba76c 100644 (file)
@@ -72,7 +72,7 @@ func (dec *Decoder) Decode(e interface{}) os.Error {
        // 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
        }
index 56f6151dbbf86ac2dfc08862b9b70cfdc695181e..1640ac72a54dff01613be65d344ef748c6508bfd 100644 (file)
@@ -72,7 +72,7 @@ func TestBasicEncoder(t *testing.T) {
                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);
        }
@@ -88,7 +88,7 @@ func TestBasicEncoder(t *testing.T) {
                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);
        }
index cd05a390bafb6fcb2fedf55bce25bce8d674112f..7eaae05a1bc7ddb9ab7a6433ba2528ceffc6c155 100644 (file)
@@ -310,10 +310,14 @@ func bootstrapType(name string, e interface{}) TypeId {
 // 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 {
@@ -336,7 +340,7 @@ func getTypeInfo(rt reflect.Type) *typeInfo {
                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;