本文整理汇总了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
最后编辑: kuteng 文档更新时间: 2021-08-23 19:14 作者:kuteng