Skip to content
This repository has been archived by the owner on Aug 9, 2018. It is now read-only.

Commit

Permalink
fix memory.Writer
Browse files Browse the repository at this point in the history
  • Loading branch information
mildred committed Feb 13, 2016
1 parent bd61fcc commit c39006e
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions memory/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ func (w *Writer) WriteValue(val interface{}) error {
switch w.stack[last].(type) {
case *Node:
(*w.stack[last].(*Node))[w.curKey] = val
case []interface{}:
w.stack[last] = append(w.stack[last].([]interface{}), val)
case *[]interface{}:
*w.stack[last].(*[]interface{}) = append(*w.stack[last].(*[]interface{}), val)
default:
panic("Currupted stack")
}
Expand All @@ -60,9 +60,9 @@ func (w *Writer) WriteBeginNode(n_elems int) error {
w.stack = append(w.stack, &w.Node)
return nil
} else {
n := &Node{}
n := Node{}
err := w.WriteValue(n)
w.stack = append(w.stack, n)
w.stack = append(w.stack, &n)
return err
}
}
Expand All @@ -86,7 +86,8 @@ func (w *Writer) WriteBeginArray(n_elems int) error {
return fmt.Errorf("Cannot start array")
}

w.stack = append(w.stack, []interface{}{})
slice := []interface{}{}
w.stack = append(w.stack, w.curKey, &slice)
return nil
}

Expand All @@ -95,6 +96,9 @@ func (w *Writer) WriteEndArray() error {
return fmt.Errorf("Cannot end array")
}

w.stack = w.stack[:len(w.stack)-1]
return nil
slice := w.stack[len(w.stack)-1].(*[]interface{})
w.curKey = w.stack[len(w.stack)-2].(string)
w.stack = w.stack[:len(w.stack)-2]
err := w.WriteValue(*slice)
return err
}

0 comments on commit c39006e

Please sign in to comment.