Everything seem to work now

This commit is contained in:
2018-11-11 14:24:45 +01:00
parent 9cd1d12583
commit 69353f61bc
9 changed files with 167 additions and 50 deletions
+5 -1
View File
@@ -28,12 +28,15 @@ func NewCommandBuffer(size int) *Buffer {
// Skip advances the cursor by N bytes.
func (b *Buffer) Skip(n int) {
Debugf("Skipped %d bytes: %X\n", n, b.data[b.pos:b.pos+n])
b.pos += n
}
// Read returns next N bytes and advances the cursor.
func (b *Buffer) Read(n int) []byte {
b.pos += n
Debugf("Read %d bytes: %X\n", n, b.data[b.pos-n:b.pos])
return b.data[b.pos-n:]
}
@@ -44,7 +47,8 @@ func (b *Buffer) Cur() []byte {
// More returns true if there's more to read.
func (b *Buffer) More() bool {
return b.pos < len(b.data)
Debug("*** BUFFER BOUNDS CHECK len:", len(b.data), "pos:", b.pos)
return b.pos < len(b.data)-1
}
// Bytes returns entire buffer contents.
+24
View File
@@ -0,0 +1,24 @@
package tools
import (
"fmt"
"github.com/localhots/pretty"
)
// EnableDebug controls debug output.
var EnableDebug = false
// Debug ...
func Debug(vals ...interface{}) {
if EnableDebug {
pretty.Println(vals...)
}
}
// Debugf ...
func Debugf(format string, args ...interface{}) {
if EnableDebug {
fmt.Printf(format, args...)
}
}