本文整理汇总了Golang中encoding/hex.Dumper函数的典型用法代码示例。如果您正苦于以下问题:Golang Dumper函数的具体用法?Golang Dumper怎么用?Golang Dumper使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Dumper函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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 ""
}
开发者ID:untoldwind,项目名称:gorrd,代码行数:52,代码来源:helpers_test.go
示例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
}
开发者ID:sstallion,项目名称:go,代码行数:32,代码来源:dump.go
示例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
}
开发者ID:jmptrader,项目名称:gocui,代码行数:29,代码来源:stdin.go
示例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])
}
}
开发者ID:sheik,项目名称:golang,代码行数:26,代码来源:hex.go
示例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
}
开发者ID:achanda,项目名称:go,代码行数:29,代码来源:handshake_test.go
示例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()
}
}
开发者ID:houcy,项目名称:loadmon,代码行数:30,代码来源:main.go
示例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)
}
}
开发者ID:houcy,项目名称:loadmon,代码行数:34,代码来源:main.go
示例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
}
开发者ID:robmurtha,项目名称:zenio,代码行数:31,代码来源:util.go
示例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"))
}
}
开发者ID:zsoman,项目名称:go-sqlite,代码行数:8,代码来源:hexdump.go
示例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,
}
}
开发者ID:oxtoacart,项目名称:mesos-go,代码行数:8,代码来源:http_transporter.go
示例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()
}
开发者ID:Tonkpils,项目名称:go-challenge,代码行数:9,代码来源:util.go
示例12: hexdump
func hexdump(buf []byte) {
dumper := hex.Dumper(os.Stdout)
if _, err := dumper.Write(buf); err != nil {
panic(err)
}
dumper.Close()
}
开发者ID:qmsk,项目名称:onewire,代码行数:9,代码来源:main.go
示例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)
}
开发者ID:rrudduck,项目名称:golang-stuff,代码行数:10,代码来源:hex.go
示例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()
}
开发者ID:8l,项目名称:e8,代码行数:11,代码来源:dasm.go
示例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
}
开发者ID:andreas-jonsson,项目名称:chip8,代码行数:37,代码来源:system.go
示例16: sendMessage
func sendMessage(w http.ResponseWriter, r *http.Request) {
src := r.FormValue("src")
dest := r.FormValue("dest")
text := r.FormValue("msg")
if radio == nil {
http.Error(w, "No radio", 500)
return
}
if text != "" {
d := hex.Dumper(os.Stdout)
defer d.Close()
mw := io.MultiWriter(d, radio)
_, err := mw.Write([]byte{0xc0, 0x00})
if err != nil {
http.Error(w, err.Error(), 500)
log.Printf("Error writing command: %v", err)
return
}
msg := aprs.Frame{
Source: aprs.AddressFromString(src),
Dest: aprs.AddressFromString(dest),
Path: []aprs.Address{
aprs.AddressFromString("WIDE2-2")},
Body: aprs.Info(text),
}
body := ax25.EncodeAPRSCommand(msg)
_, err = mw.Write(body)
if err != nil {
http.Error(w, err.Error(), 500)
log.Printf("Error writing command: %v", err)
return
}
_, err = mw.Write([]byte{0xc0})
if err != nil {
http.Error(w, err.Error(), 500)
log.Printf("Error finishing command: %v", err)
return
}
fmt.Fprintf(w, "Message sent")
} else {
http.Error(w, "No message", 400)
}
}
开发者ID:dustin,项目名称:go-aprs,代码行数:49,代码来源:web.go
示例17: main
func main() {
flag.Parse()
var f *os.File
if readFromStdin() {
f = os.Stdin
} else {
var err error
f, err = os.Open(*infile)
if err != nil {
log.Fatal("Failed to open ", *infile)
}
}
dumper := hex.Dumper(os.Stdout)
io.Copy(dumper, f)
f.Close()
}
开发者ID:borje,项目名称:hexdump,代码行数:16,代码来源:main.go
示例18: WriteTo
// WriteTo writes Go source code to w that contains the recorded traffic.
func (r *recordingConn) WriteTo(w io.Writer) {
// TLS always starts with a client to server flow.
clientToServer := true
for i, flow := range r.flows {
source, dest := "client", "server"
if !clientToServer {
source, dest = dest, source
}
fmt.Fprintf(w, ">>> Flow %d (%s to %s)\n", i+1, source, dest)
dumper := hex.Dumper(w)
dumper.Write(flow)
dumper.Close()
clientToServer = !clientToServer
}
}
开发者ID:Greentor,项目名称:go,代码行数:17,代码来源:handshake_test.go
示例19: WriteTo
// WriteTo writes hex dumps to w that contains the recorded traffic.
func (r *recordingConn) WriteTo(w io.Writer) {
fmt.Fprintf(w, ">>> runner is %s, shim is %s\n", r.local, r.peer)
for i, flow := range r.flows {
switch flow.flowType {
case readFlow:
fmt.Fprintf(w, ">>> Flow %d (%s to %s)\n", i+1, r.peer, r.local)
case writeFlow:
fmt.Fprintf(w, ">>> Flow %d (%s to %s)\n", i+1, r.local, r.peer)
case specialFlow:
fmt.Fprintf(w, ">>> Flow %d %q\n", i+1, flow.message)
}
if flow.data != nil {
dumper := hex.Dumper(w)
dumper.Write(flow.data)
dumper.Close()
}
}
}
开发者ID:caiolima,项目名称:webkit,代码行数:20,代码来源:recordingconn.go
示例20: TestClientInit
func TestClientInit(t *testing.T) {
hdump := hex.Dumper(os.Stdout)
pr, pw := io.Pipe()
go func(w io.Writer) {
time.Sleep(2 * time.Second)
WriteMessage(w, &ProtocolMessage{Num: 0, Type: MsgTypeGreeting & MsgTypeServerMask, Data: &MsgServerGreeting{Hash([]byte("testing"))}})
time.Sleep(2 * time.Second)
WriteMessage(w, &ProtocolMessage{Num: 1, Type: MsgTypeAuthenticate & MsgTypeServerMask})
time.Sleep(2 * time.Second)
WriteMessage(w, &ProtocolMessage{Num: 2, Type: MsgTypeGoodbye & MsgTypeServerMask})
}(pw)
c := FauxServer{hdump, pr}
client := NewClient(c, "account name", Hash([]byte("password")))
time.Sleep(1 * time.Second)
client.Close(true)
hdump.Close()
_ = client
}
开发者ID:fredli74,项目名称:hashbox,代码行数:21,代码来源:client_test.go
注:本文中的encoding/hex.Dumper函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论