File tree Expand file tree Collapse file tree 2 files changed +36
-0
lines changed
Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -18,4 +18,5 @@ func NewRegister() mappings.Register {
1818func (r * register ) Regist (m mappings.ExampleMapping ) {
1919 m ["binary_byteorder" ] = ByteOrder
2020 m ["binary_readwrite" ] = readwrite .ReadWrite
21+ m ["binary_using_hex_dumper" ] = UsingHexDumper
2122}
Original file line number Diff line number Diff line change 1+ package binaries
2+
3+ import (
4+ "encoding/hex"
5+ "io"
6+ "os"
7+ "strings"
8+
9+ "github.com/devlights/gomy/output"
10+ )
11+
12+ // UsingHexDumper -- encoding/hex#Dumper のサンプルです。
13+ func UsingHexDumper () error {
14+ // -----------------------------------------------------
15+ // encoding/hex#Dumper を利用すると hexdump コマンドを
16+ // 実行した場合のような16進数ダンプを出力することができる.
17+ //
18+ // hex.Dumper は、io.Writer を受け取り、io.WriteCloserを返す.
19+ // -----------------------------------------------------
20+ var (
21+ s string = "hello world"
22+ r io.Reader = strings .NewReader (s )
23+ w io.Writer = os .Stdout
24+ dumper io.WriteCloser = hex .Dumper (w )
25+ )
26+
27+ output .Stdoutl ("[original]" , s )
28+
29+ _ , err := io .Copy (dumper , r )
30+ if err != nil {
31+ return err
32+ }
33+
34+ return nil
35+ }
You can’t perform that action at this time.
0 commit comments