Skip to content

Commit

Permalink
Merge pull request #192 from goccy/feature/fix-read-length
Browse files Browse the repository at this point in the history
Reset read length at finished reading
  • Loading branch information
goccy authored Jan 29, 2021
2 parents 7c371c2 + 8b20767 commit f6ab5cc
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions ast/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ type Node interface {
readLen() int
// append read length
addReadLen(int)
// clean read length
clearLen()
}

// ScalarNode type for scalar node
Expand All @@ -146,6 +148,10 @@ func (n *BaseNode) readLen() int {
return n.read
}

func (n *BaseNode) clearLen() {
n.read = 0
}

func (n *BaseNode) addReadLen(len int) {
n.read += len
}
Expand Down Expand Up @@ -176,6 +182,7 @@ func readNode(p []byte, node Node) (int, error) {
readLen := node.readLen()
remain := len(s) - readLen
if remain == 0 {
node.clearLen()
return 0, io.EOF
}
size := min(remain, len(p))
Expand Down

0 comments on commit f6ab5cc

Please sign in to comment.