utility.go (972B)
1 package pngstructure 2 3 import ( 4 "bytes" 5 "fmt" 6 7 "github.com/dsoprea/go-logging" 8 ) 9 10 func DumpBytes(data []byte) { 11 fmt.Printf("DUMP: ") 12 for _, x := range data { 13 fmt.Printf("%02x ", x) 14 } 15 16 fmt.Printf("\n") 17 } 18 19 func DumpBytesClause(data []byte) { 20 fmt.Printf("DUMP: ") 21 22 fmt.Printf("[]byte { ") 23 24 for i, x := range data { 25 fmt.Printf("0x%02x", x) 26 27 if i < len(data)-1 { 28 fmt.Printf(", ") 29 } 30 } 31 32 fmt.Printf(" }\n") 33 } 34 35 func DumpBytesToString(data []byte) string { 36 b := new(bytes.Buffer) 37 38 for i, x := range data { 39 _, err := b.WriteString(fmt.Sprintf("%02x", x)) 40 log.PanicIf(err) 41 42 if i < len(data)-1 { 43 _, err := b.WriteRune(' ') 44 log.PanicIf(err) 45 } 46 } 47 48 return b.String() 49 } 50 51 func DumpBytesClauseToString(data []byte) string { 52 b := new(bytes.Buffer) 53 54 for i, x := range data { 55 _, err := b.WriteString(fmt.Sprintf("0x%02x", x)) 56 log.PanicIf(err) 57 58 if i < len(data)-1 { 59 _, err := b.WriteString(", ") 60 log.PanicIf(err) 61 } 62 } 63 64 return b.String() 65 }