Fixes bytewriter to format output.

This commit is contained in:
Jim Teeuwen 2014-01-29 01:37:15 +01:00
parent 20077324b7
commit bb0b560542

View File

@ -9,7 +9,11 @@ import (
"io" "io"
) )
var newline = []byte{'\n'} var (
newline = []byte{'\n'}
dataindent = []byte{'\t', '\t'}
space = []byte{' '}
)
type ByteWriter struct { type ByteWriter struct {
io.Writer io.Writer
@ -24,7 +28,10 @@ func (w *ByteWriter) Write(p []byte) (n int, err error) {
for n = range p { for n = range p {
if w.c%12 == 0 { if w.c%12 == 0 {
w.Writer.Write(newline) w.Writer.Write(newline)
w.Writer.Write(dataindent)
w.c = 0 w.c = 0
} else {
w.Writer.Write(space)
} }
fmt.Fprintf(w.Writer, "0x%02x,", p[n]) fmt.Fprintf(w.Writer, "0x%02x,", p[n])