本文整理匯總了Golang中encoding/hex.Dumper函數的典型用法代碼示例。如果您正苦於以下問題:Golang Dumper函數的具體用法?Golang Dumper怎麽用?Golang Dumper使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Dumper函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: shouldHaveSameContentAs
func shouldHaveSameContentAs(actual interface{}, expected ...interface{}) string {
if len(expected) != 1 {
return "shouldHaveSameContentAs must have only one expected value"
}
actualIn, err := os.Open(actual.(string))
if err != nil {
return err.Error()
}
defer actualIn.Close()
expectedIn, err := os.Open(expected[0].(string))
if err != nil {
return err.Error()
}
defer expectedIn.Close()
actualPipeIn, actualPipeOut := io.Pipe()
actualScanner := bufio.NewScanner(actualPipeIn)
actualDumper := hex.Dumper(actualPipeOut)
go func() {
io.Copy(actualDumper, actualIn)
actualDumper.Close()
actualPipeOut.Close()
}()
expectedPipeIn, expectedPipeOut := io.Pipe()
expectedScanner := bufio.NewScanner(expectedPipeIn)
expectedDumper := hex.Dumper(expectedPipeOut)
go func() {
io.Copy(expectedDumper, expectedIn)
expectedDumper.Close()
expectedPipeOut.Close()
}()
for {
actualNext := actualScanner.Scan()
expectedNext := expectedScanner.Scan()
if expectedNext && !actualNext {
return fmt.Sprintf("%v and %v differ: extra Line %s", actual, expected[0], expectedScanner.Text())
}
if !expectedNext && actualNext {
return fmt.Sprintf("%v and %v differ: extra Line %s", actual, expected[0], actualScanner.Text())
}
if actualScanner.Text() != expectedScanner.Text() {
return fmt.Sprintf("%v and %v differ: %s != %s", actual, expected[0], actualScanner.Text(), expectedScanner.Text())
}
if !actualNext || !expectedNext {
break
}
}
return ""
}
示例2: dump
func dump(args ...string) error {
var w io.WriteCloser
if len(args) == 0 {
w = hex.Dumper(os.Stdout)
} else {
var err error
w, err = os.Create(args[0])
if err != nil {
return err
}
}
defer w.Close()
d, err := openDevice()
if err != nil {
return err
}
defer d.Close()
if dumpCount == 0 {
dumpCount = eeprom.MaxBytes - dumpStart
}
data := make([]byte, dumpCount)
if err := d.Read(uint16(dumpStart), data); err != nil {
d.Reset()
return err
}
_, err = w.Write(data)
return err
}
示例3: layout
func layout(g *gocui.Gui) error {
maxX, _ := g.Size()
if v, err := g.SetView("legend", maxX-23, 0, maxX-1, 5); err != nil {
if err != gocui.ErrUnknownView {
return err
}
fmt.Fprintln(v, "KEYBINDINGS")
fmt.Fprintln(v, "↑ ↓: Seek input")
fmt.Fprintln(v, "A: Enable autoscroll")
fmt.Fprintln(v, "^C: Exit")
}
if v, err := g.SetView("stdin", 0, 0, 80, 35); err != nil {
if err != gocui.ErrUnknownView {
return err
}
if _, err := g.SetCurrentView("stdin"); err != nil {
return err
}
dumper := hex.Dumper(v)
if _, err := io.Copy(dumper, os.Stdin); err != nil {
return err
}
v.Wrap = true
}
return nil
}
示例4: main
func main() {
if len(os.Args) < 2 {
fmt.Println("you must supply a file name")
os.Exit(1)
}
fp, err := os.Open(os.Args[1])
if err != nil {
panic(err)
}
reader := bufio.NewReader(fp)
w := hex.Dumper(os.Stdout)
buf := make([]byte, 1024)
for {
n, err := reader.Read(buf)
if err != nil && err != io.EOF {
panic(err)
}
if n == 0 {
break
}
w.Write(buf[:n])
}
}
示例5: WriteTo
// WriteTo writes Go source code to w that contains the recorded traffic.
func (r *recordingConn) WriteTo(w io.Writer) (int64, error) {
// TLS always starts with a client to server flow.
clientToServer := true
var written int64
for i, flow := range r.flows {
source, dest := "client", "server"
if !clientToServer {
source, dest = dest, source
}
n, err := fmt.Fprintf(w, ">>> Flow %d (%s to %s)\n", i+1, source, dest)
written += int64(n)
if err != nil {
return written, err
}
dumper := hex.Dumper(w)
n, err = dumper.Write(flow)
written += int64(n)
if err != nil {
return written, err
}
err = dumper.Close()
if err != nil {
return written, err
}
clientToServer = !clientToServer
}
return written, nil
}
示例6: Sender
func Sender(interval int, logfile *LogFile, peers []LoadPeer) {
lm := LoadMessage{Interval: uint16(interval)}
lm.ProbeInit()
for {
var buffer bytes.Buffer
time.Sleep(time.Duration(lm.Interval) * time.Second)
lm.Probe()
if err := lm.Encode(&buffer); err != nil {
log.Fatal("encode error:", err)
}
fmt.Println()
if *f_verbose > 1 {
fmt.Printf("Local LoadMessage, size=%d\n", buffer.Len())
hex.Dumper(os.Stdout).Write(buffer.Bytes())
fmt.Println()
}
lm.Dump(os.Stdout)
if logfile != nil {
logfile.WriteMessage(buffer.Bytes())
}
for _, peer := range peers {
peer.conn.Write(buffer.Bytes())
}
lm.ProbeRotate()
}
}
示例7: DumpLogFile
func DumpLogFile(filename string) {
var lm LoadMessage
logfile, err := OpenLogFile(filename, MODE_READ)
if err != nil {
fmt.Println("Error open log file:", err)
return
}
for {
ts, buffer, err := logfile.ReadMessage()
if err != nil {
break
}
t := FromTimestamp(ts).Format("20060102-150405")
err = lm.Decode(bytes.NewReader(buffer))
if err != nil {
fmt.Println("Error decode packet:", err)
break
}
fmt.Println()
if *f_verbose > 1 {
fmt.Printf("Read LoadMessage, local time %s, size=%d\n", t, len(buffer))
hex.Dumper(os.Stdout).Write(buffer)
fmt.Println()
}
lm.Dump(os.Stdout)
}
if err != nil && err != io.EOF {
fmt.Println(err)
}
}
示例8: Flush
func (hd *hexDumper) Flush() error {
// Default to Stdout if not specified.
var writer = hd.Writer
if writer == nil {
writer = os.Stdout
}
// Dump the hex dump with the optional prefix.
if hd.Len() > 0 {
buf := &bytes.Buffer{}
dumper := hex.Dumper(buf)
hd.WriteTo(dumper)
dumper.Close()
hd.Reset()
hd.mu.Lock()
defer hd.mu.Unlock()
scanner := bufio.NewScanner(buf)
for scanner.Scan() {
if _, err := writer.Write([]byte(hd.Prefix)); err != nil {
return err
} else if _, err := writer.Write(scanner.Bytes()); err != nil {
return err
} else if _, err := writer.Write([]byte("\n")); err != nil {
return err
}
}
}
return nil
}
示例9: dump
func (c *hexDump) dump(b []byte) {
if !c.quiet {
hd := hex.Dumper(c.out)
hd.Write(b)
hd.Close()
c.out.Write([]byte("\n"))
}
}
示例10: logConnection
func logConnection(c net.Conn) net.Conn {
w := hex.Dumper(os.Stdout)
r := io.TeeReader(c, w)
return &loggedConnection{
Conn: c,
reader: r,
}
}
示例11: debug
func debug(d io.Reader) {
dumper := hex.Dumper(os.Stdout)
bs, err := ioutil.ReadAll(d)
if err != nil {
log.Fatal(err)
}
dumper.Write(bs)
dumper.Close()
}
示例12: hexdump
func hexdump(buf []byte) {
dumper := hex.Dumper(os.Stdout)
if _, err := dumper.Write(buf); err != nil {
panic(err)
}
dumper.Close()
}
示例13: dumpFile
func dumpFile() {
data, err := ioutil.ReadFile("hex.go")
if err != nil {
log.Fatalf("failed reading file: %s", err)
}
dumper := hex.Dumper(os.Stdout)
defer dumper.Close()
log.Println("dumping hex.go to stdout")
dumper.Write(data)
}
示例14: dumpDataSeg
func dumpDataSeg(start uint32, b []byte) {
n := len(b)
fmt.Println("[data] // %08x - %08x, %d bytes\n",
start, start+uint32(n), n,
)
dumper := hex.Dumper(os.Stdout)
dumper.Write(b)
dumper.Close()
fmt.Println()
}
示例15: Dump
func (sys *System) Dump(writer io.Writer, name string) error {
fmt.Fprintf(writer, "%v\n%s\n\n", time.Now(), name)
fmt.Fprintf(writer, "PC: 0x%X, SP: 0x%X, I: 0x%X\n\n", sys.pc, sys.sp, sys.i)
for i, v := range sys.v {
fmt.Fprintf(writer, "V%d: 0x%X\n", i, v)
}
stackDumper := hex.Dumper(writer)
defer stackDumper.Close()
fmt.Fprintln(writer)
if err := binary.Write(stackDumper, binary.BigEndian, sys.stack[:]); err != nil {
return err
}
memoryDumper := hex.Dumper(writer)
defer memoryDumper.Close()
fmt.Fprintln(writer)
if _, err := memoryDumper.Write(sys.memory[:]); err != nil {
return err
}
for y := 0; y < 32; y++ {
fmt.Fprintln(writer)
for x := 0; x < 64; x++ {
if sys.video[y*64+x] != 0 {
fmt.Fprint(writer, "#")
} else {
fmt.Fprint(writer, ".")
}
}
}
return nil
}