7 "github.com/ugorji/go/codec"
13 func usage(retval int) {
14 fmt.Printf("%s: converts msgpack data structures to JSON.\n",
16 fmt.Printf("usage: %s [input-file]\n", os.Args[0])
18 fmt.Printf("The input file should contain hex digits with no spaces or linebreaks.\n")
27 if (os.Args[i] == "-h") || (os.Args[i] == "--help") {
30 if i >= len(os.Args) {
34 buf, err := ioutil.ReadFile(path)
36 fmt.Fprintf(os.Stderr, "Got error reading from %s: %s\n",
40 str := strings.ToLower(strings.TrimSpace(string(buf)))
42 fmt.Fprintf(os.Stderr, "The number of hex digits is not even.\n")
46 bin, err = hex.DecodeString(str)
48 fmt.Fprintf(os.Stderr, "Failed to decode hex string '%s': %s\n",
52 fmt.Fprintf(os.Stdout, "input=\n"+hex.Dump(bin)+"\n")
55 mh := new(codec.MsgpackHandle)
58 dec := codec.NewDecoderBytes(bin, mh)
60 err = dec.Decode(&body)
62 //fmt.Fprintf(os.Stdout, "body=%v\n", body);
65 jh := new(codec.JsonHandle)
67 enc := codec.NewEncoder(&out, jh)
68 err = enc.Encode(body)
70 fmt.Fprintf(os.Stderr, "Error re-encoding message as JSON: %s\n",
74 fmt.Fprintf(os.Stdout, "output=\n%s\n", out.String())