Commit 96b9efe8 authored by Rob Pike's avatar Rob Pike

gob: make the debugging (dumping) code work again. Mostly rewrite it, in fact.

It's still not compiled in by default.

R=rsc, r2
CC=golang-dev
https://golang.org/cl/2754043
parent 907e998c
......@@ -1269,3 +1269,50 @@ func TestIgnoreInterface(t *testing.T) {
t.Error("normal float did not decode correctly")
}
}
// A type that won't be defined in the gob until we send it in an interface value.
type OnTheFly struct {
a int
}
type DT struct {
// X OnTheFly
a int
b string
c float
i interface{}
j interface{}
i_nil interface{}
m map[string]int
r [3]int
s []string
}
func TestDebug(t *testing.T) {
if debugFunc == nil {
return
}
Register(OnTheFly{})
var dt DT
dt.a = 17
dt.b = "hello"
dt.c = 3.14159
dt.i = 271828
dt.j = OnTheFly{3}
dt.i_nil = nil
dt.m = map[string]int{"one": 1, "two": 2}
dt.r = [3]int{11, 22, 33}
dt.s = []string{"hi", "joe"}
b := new(bytes.Buffer)
err := NewEncoder(b).Encode(dt)
if err != nil {
t.Fatal("encode:", err)
}
debugBuffer := bytes.NewBuffer(b.Bytes())
dt2 := &DT{}
err = NewDecoder(b).Decode(&dt2)
if err != nil {
t.Error("decode:", err)
}
debugFunc(debugBuffer)
}
This diff is collapsed.
......@@ -108,9 +108,6 @@ func (dec *Decoder) decodeValueFromBuffer(value reflect.Value, ignore bool) {
for dec.state.b.Len() > 0 {
// Receive a type id.
id := typeId(decodeInt(dec.state))
if dec.err != nil {
break
}
// Is it a new type?
if id < 0 { // 0 is the error state, handled above
......@@ -155,3 +152,7 @@ func (dec *Decoder) DecodeValue(value reflect.Value) os.Error {
dec.decodeValueFromBuffer(value, false)
return dec.err
}
// If enabled, Debug prints a human-readable representation of the gob data read from r.
// If debug.go is compiled into the program it will override this link.
var debugFunc func(io.Reader)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment