improve export data as hex for gres

This commit is contained in:
john
2019-09-01 21:34:15 +08:00
parent 15a6680833
commit 6ccc4d119f
7 changed files with 21 additions and 20 deletions

View File

@ -9,18 +9,15 @@ package utilbytes
import (
"bytes"
"strconv"
"fmt"
)
func Export(b []byte) string {
buffer := bytes.NewBuffer(nil)
buffer.WriteString("[]byte{")
for k, v := range b {
if k > 0 {
buffer.WriteByte(',')
}
buffer.WriteString(strconv.Itoa(int(v)))
buffer.WriteString(`[]byte("`)
for _, v := range b {
fmt.Fprintf(buffer, `\x%02x`, v)
}
buffer.WriteString("}")
buffer.WriteString(`")`)
return buffer.String()
}