Skip to content

Commit

Permalink
cmd: add hex-vis
Browse files Browse the repository at this point in the history
helps debugging all this byte stuffk

Signed-off-by: Ciro S. Costa <[email protected]>
  • Loading branch information
cirocosta committed Apr 19, 2021
1 parent 598a420 commit fefcb2f
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions cmd/hex-vis/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package main

import (
"encoding/binary"
"os"

"github.com/davecgh/go-spew/spew"
"github.com/jessevdk/go-flags"
)

var opts = struct {
Uint16 uint16 `long:"uint16"`
Uint32 uint32 `long:"uint32"`
String string `long:"string"`
}{}

func main() {
parser := flags.NewParser(&opts, flags.Default)

if _, err := parser.Parse(); err != nil {
os.Exit(1)
}

var b []byte

switch {
case opts.Uint16 != 0:
b = make([]byte, 2)
binary.LittleEndian.PutUint16(b, opts.Uint16)
case opts.Uint32 != 0:
b = make([]byte, 4)
binary.LittleEndian.PutUint32(b, opts.Uint32)
case len(opts.String) != 0:
b = []byte(opts.String)
default:
parser.WriteHelp(os.Stderr)
os.Exit(1)
}

spew.Dump(b)
}

0 comments on commit fefcb2f

Please sign in to comment.