mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
store ids rather than Types in the structs so they can be encoded.
change Type to gobType. fix some bugs around recursive structures. lots of cleanup. add the first cut at a type encoder. R=rsc DELTA=400 (287 added, 11 deleted, 102 changed) OCL=31401 CL=31406
This commit is contained in:
parent
7472f4c951
commit
ec23467e65
8 changed files with 384 additions and 106 deletions
|
|
@ -13,7 +13,6 @@ import (
|
|||
"testing";
|
||||
"unsafe";
|
||||
)
|
||||
import "fmt" // TODO DELETE
|
||||
|
||||
// Guarantee encoding format by comparing some encodings to hand-written values
|
||||
type EncodeT struct {
|
||||
|
|
@ -560,6 +559,30 @@ func TestEndToEnd(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestNesting(t *testing.T) {
|
||||
type RT struct {
|
||||
a string;
|
||||
next *RT
|
||||
}
|
||||
rt := new(RT);
|
||||
rt.a = "level1";
|
||||
rt.next = new(RT);
|
||||
rt.next.a = "level2";
|
||||
b := new(bytes.Buffer);
|
||||
Encode(b, rt);
|
||||
var drt RT;
|
||||
Decode(b, &drt);
|
||||
if drt.a != rt.a {
|
||||
t.Errorf("nesting: encode expected %v got %v", *rt, drt);
|
||||
}
|
||||
if drt.next == nil {
|
||||
t.Errorf("nesting: recursion failed");
|
||||
}
|
||||
if drt.next.a != rt.next.a {
|
||||
t.Errorf("nesting: encode expected %v got %v", *rt.next, *drt.next);
|
||||
}
|
||||
}
|
||||
|
||||
// These three structures have the same data with different indirections
|
||||
type T0 struct {
|
||||
a int;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue