2021-02-09 20:17:06 +01:00
|
|
|
package pngstructure
|
|
|
|
|
|
|
|
import (
|
2021-02-10 01:00:02 +01:00
|
|
|
"fmt"
|
|
|
|
"bytes"
|
2021-02-09 20:17:06 +01:00
|
|
|
|
2021-02-10 01:00:02 +01:00
|
|
|
"github.com/dsoprea/go-logging"
|
2021-02-09 20:17:06 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func DumpBytes(data []byte) {
|
2021-02-10 01:00:02 +01:00
|
|
|
fmt.Printf("DUMP: ")
|
|
|
|
for _, x := range data {
|
|
|
|
fmt.Printf("%02x ", x)
|
|
|
|
}
|
2021-02-09 20:17:06 +01:00
|
|
|
|
2021-02-10 01:00:02 +01:00
|
|
|
fmt.Printf("\n")
|
2021-02-09 20:17:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func DumpBytesClause(data []byte) {
|
2021-02-10 01:00:02 +01:00
|
|
|
fmt.Printf("DUMP: ")
|
2021-02-09 20:17:06 +01:00
|
|
|
|
2021-02-10 01:00:02 +01:00
|
|
|
fmt.Printf("[]byte { ")
|
2021-02-09 20:17:06 +01:00
|
|
|
|
2021-02-10 01:00:02 +01:00
|
|
|
for i, x := range data {
|
|
|
|
fmt.Printf("0x%02x", x)
|
2021-02-09 20:17:06 +01:00
|
|
|
|
2021-02-10 01:00:02 +01:00
|
|
|
if i < len(data) - 1 {
|
|
|
|
fmt.Printf(", ")
|
|
|
|
}
|
|
|
|
}
|
2021-02-09 20:17:06 +01:00
|
|
|
|
2021-02-10 01:00:02 +01:00
|
|
|
fmt.Printf(" }\n")
|
2021-02-09 20:17:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func DumpBytesToString(data []byte) string {
|
2021-02-10 01:00:02 +01:00
|
|
|
b := new(bytes.Buffer)
|
2021-02-09 20:17:06 +01:00
|
|
|
|
2021-02-10 01:00:02 +01:00
|
|
|
for i, x := range data {
|
|
|
|
_, err := b.WriteString(fmt.Sprintf("%02x", x))
|
|
|
|
log.PanicIf(err)
|
2021-02-09 20:17:06 +01:00
|
|
|
|
2021-02-10 01:00:02 +01:00
|
|
|
if i < len(data) - 1 {
|
|
|
|
_, err := b.WriteRune(' ')
|
|
|
|
log.PanicIf(err)
|
|
|
|
}
|
|
|
|
}
|
2021-02-09 20:17:06 +01:00
|
|
|
|
2021-02-10 01:00:02 +01:00
|
|
|
return b.String()
|
2021-02-09 20:17:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func DumpBytesClauseToString(data []byte) string {
|
2021-02-10 01:00:02 +01:00
|
|
|
b := new(bytes.Buffer)
|
2021-02-09 20:17:06 +01:00
|
|
|
|
2021-02-10 01:00:02 +01:00
|
|
|
for i, x := range data {
|
|
|
|
_, err := b.WriteString(fmt.Sprintf("0x%02x", x))
|
|
|
|
log.PanicIf(err)
|
2021-02-09 20:17:06 +01:00
|
|
|
|
2021-02-10 01:00:02 +01:00
|
|
|
if i < len(data) - 1 {
|
|
|
|
_, err := b.WriteString(", ")
|
|
|
|
log.PanicIf(err)
|
|
|
|
}
|
|
|
|
}
|
2021-02-09 20:17:06 +01:00
|
|
|
|
2021-02-10 01:00:02 +01:00
|
|
|
return b.String()
|
2021-02-09 20:17:06 +01:00
|
|
|
}
|