refactor newtmgr to use cbor instead of json

Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/commit/ade80cfc
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/ade80cfc
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/ade80cfc

Branch: refs/heads/develop
Commit: ade80cfc0576be75b837507ef6b0761d89ffb39b
Parents: a47565d
Author: Paul Dietrich <paulfdietr...@yahoo.com>
Authored: Tue Oct 11 16:51:33 2016 -0700
Committer: Paul Dietrich <paulfdietr...@yahoo.com>
Committed: Thu Oct 13 11:10:47 2016 -0700

----------------------------------------------------------------------
 newtmgr/cli/image.go                  | 25 +++++++-------
 newtmgr/protocol/config.go            |  6 ++--
 newtmgr/protocol/coreerase.go         |  4 +--
 newtmgr/protocol/corelist.go          |  4 +--
 newtmgr/protocol/coreload.go          | 11 +++----
 newtmgr/protocol/crash.go             |  4 +--
 newtmgr/protocol/datetime.go          |  8 ++---
 newtmgr/protocol/echo.go              | 10 +++---
 newtmgr/protocol/imageboot2.go        | 53 +++++++++---------------------
 newtmgr/protocol/imagefiledownload.go | 13 ++++----
 newtmgr/protocol/imagefileupload.go   | 17 +++++-----
 newtmgr/protocol/imagelist2.go        |  6 ++--
 newtmgr/protocol/imagesplit.go        |  6 ++--
 newtmgr/protocol/imageupload.go       | 17 +++++-----
 newtmgr/protocol/logs.go              | 36 ++++++++++----------
 newtmgr/protocol/mpstats.go           |  4 +--
 newtmgr/protocol/stats.go             | 12 +++----
 newtmgr/protocol/taskstats.go         |  4 +--
 18 files changed, 106 insertions(+), 134 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/ade80cfc/newtmgr/cli/image.go
----------------------------------------------------------------------
diff --git a/newtmgr/cli/image.go b/newtmgr/cli/image.go
index 445d8fe..087d57c 100644
--- a/newtmgr/cli/image.go
+++ b/newtmgr/cli/image.go
@@ -20,7 +20,6 @@
 package cli
 
 import (
-       "encoding/base64"
        "encoding/hex"
        "errors"
        "fmt"
@@ -81,15 +80,10 @@ func imageListCmd(cmd *cobra.Command, args []string) {
                fmt.Printf(" slot=%d\n", img.Slot)
                fmt.Printf("    version=%s\n", img.Version)
                fmt.Printf("    bootable=%v\n", img.Bootable)
-               if img.Hash == "" {
+               if len(img.Hash) == 0 {
                        fmt.Printf("    hash=Unavailable\n")
                } else {
-                       dec, err := base64.StdEncoding.DecodeString(img.Hash)
-                       if err != nil {
-                               fmt.Printf("    hash=Unable to Decode")
-                       } else {
-                               fmt.Printf("    hash=%s\n", 
hex.EncodeToString(dec[:]))
-                       }
+                       fmt.Printf("    hash=%x\n", img.Hash)
                }
        }
 }
@@ -245,7 +239,7 @@ func imageUploadCmd(cmd *cobra.Command, args []string) {
        if profile.Type() == "ble" {
                mtu = uint32((transport.BleMTU - 33) * 3 / 4)
        } else {
-               mtu = 36
+               mtu = 64
        }
 
        for currOff < imageSz {
@@ -259,7 +253,10 @@ func imageUploadCmd(cmd *cobra.Command, args []string) {
                        blockSz = mtu
                }
                if currOff == 0 {
-                       blockSz = 33
+                       /* we need extra space to encode the image size */
+                       if blockSz > (mtu - 8) {
+                               blockSz = mtu - 8
+                       }
                }
 
                imageUpload.Offset = currOff
@@ -332,7 +329,7 @@ func imageBootCmd(cmd *cobra.Command, args []string) {
        }
 
        if len(args) >= 1 {
-               imageBoot.BootTarget = args[0]
+               imageBoot.BootTarget, _ = hex.DecodeString(args[0])
        }
        nmr, err := imageBoot.EncodeWriteRequest()
        if err != nil {
@@ -353,9 +350,9 @@ func imageBootCmd(cmd *cobra.Command, args []string) {
                nmUsage(cmd, err)
        }
        if len(args) == 0 {
-               fmt.Println("   Test image:", iRsp.Test)
-               fmt.Println("   Main image:", iRsp.Main)
-               fmt.Println("   Active img:", iRsp.Active)
+               fmt.Printf("   Test image: %x\n", iRsp.Test)
+               fmt.Printf("   Main image: %x\n", iRsp.Main)
+               fmt.Printf("   Active img: %x\n", iRsp.Active)
        }
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/ade80cfc/newtmgr/protocol/config.go
----------------------------------------------------------------------
diff --git a/newtmgr/protocol/config.go b/newtmgr/protocol/config.go
index 1e18ffe..9406665 100644
--- a/newtmgr/protocol/config.go
+++ b/newtmgr/protocol/config.go
@@ -49,7 +49,7 @@ func (c *Config) EncodeRequest() (*NmgrReq, error) {
        nmr.Len = 0
 
        data := make([]byte, 0)
-       enc := codec.NewEncoderBytes(&data, new(codec.JsonHandle))
+       enc := codec.NewEncoderBytes(&data, new(codec.CborHandle))
 
        if c.Value == "" {
                type ConfigReadReq struct {
@@ -79,10 +79,10 @@ func DecodeConfigResponse(data []byte) (*Config, error) {
                return c, nil
        }
 
-       dec := codec.NewDecoderBytes(data, new(codec.JsonHandle))
+       dec := codec.NewDecoderBytes(data, new(codec.CborHandle))
        err := dec.Decode(&c)
        if err != nil {
-               return nil, util.NewNewtError(fmt.Sprintf("Invalid incoming 
json: %s",
+               return nil, util.NewNewtError(fmt.Sprintf("Invalid incoming 
cbor: %s",
                        err.Error()))
        }
        return c, nil

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/ade80cfc/newtmgr/protocol/coreerase.go
----------------------------------------------------------------------
diff --git a/newtmgr/protocol/coreerase.go b/newtmgr/protocol/coreerase.go
index 5b38d96..51926fa 100644
--- a/newtmgr/protocol/coreerase.go
+++ b/newtmgr/protocol/coreerase.go
@@ -54,10 +54,10 @@ func (ce *CoreErase) EncodeWriteRequest() (*NmgrReq, error) 
{
 func DecodeCoreEraseResponse(data []byte) (*CoreErase, error) {
        ce := &CoreErase{}
 
-       dec := codec.NewDecoderBytes(data, new(codec.JsonHandle))
+       dec := codec.NewDecoderBytes(data, new(codec.CborHandle))
        err := dec.Decode(&ce)
        if err != nil {
-               return nil, util.NewNewtError(fmt.Sprintf("Invalid incoming 
json: %s",
+               return nil, util.NewNewtError(fmt.Sprintf("Invalid incoming 
cbor: %s",
                        err.Error()))
        }
        return ce, nil

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/ade80cfc/newtmgr/protocol/corelist.go
----------------------------------------------------------------------
diff --git a/newtmgr/protocol/corelist.go b/newtmgr/protocol/corelist.go
index b8e3dd2..e285955 100644
--- a/newtmgr/protocol/corelist.go
+++ b/newtmgr/protocol/corelist.go
@@ -54,10 +54,10 @@ func (ce *CoreList) EncodeWriteRequest() (*NmgrReq, error) {
 func DecodeCoreListResponse(data []byte) (*CoreList, error) {
        cl := &CoreList{}
 
-       dec := codec.NewDecoderBytes(data, new(codec.JsonHandle))
+       dec := codec.NewDecoderBytes(data, new(codec.CborHandle))
        err := dec.Decode(&cl)
        if err != nil {
-               return nil, util.NewNewtError(fmt.Sprintf("Invalid incoming 
json: %s",
+               return nil, util.NewNewtError(fmt.Sprintf("Invalid incoming 
cbor: %s",
                        err.Error()))
        }
        return cl, nil

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/ade80cfc/newtmgr/protocol/coreload.go
----------------------------------------------------------------------
diff --git a/newtmgr/protocol/coreload.go b/newtmgr/protocol/coreload.go
index 4f0a689..55ca379 100644
--- a/newtmgr/protocol/coreload.go
+++ b/newtmgr/protocol/coreload.go
@@ -20,7 +20,6 @@
 package protocol
 
 import (
-       "encoding/base64"
        "fmt"
        "io"
        "os"
@@ -42,7 +41,7 @@ type coreLoadReq struct {
 type coreLoadResp struct {
        ErrCode uint32 `codec:"rc"`
        Off     uint32 `codec:"off"`
-       Data    string `codec:"data"`
+       Data    []byte `codec:"data"`
 }
 
 func NewCoreDownload() (*CoreDownload, error) {
@@ -72,7 +71,7 @@ func (cl *CoreDownload) Download(off, size uint32) error {
                req.Off = off
 
                data := make([]byte, 0)
-               enc := codec.NewEncoderBytes(&data, new(codec.JsonHandle))
+               enc := codec.NewEncoderBytes(&data, new(codec.CborHandle))
                enc.Encode(req)
 
                nmr.Op = NMGR_OP_READ
@@ -93,9 +92,9 @@ func (cl *CoreDownload) Download(off, size uint32) error {
 
                fmt.Printf("Got response: %d bytes\n", len(nmRsp.Data))
                clRsp := coreLoadResp{}
-               dec := codec.NewDecoderBytes(nmRsp.Data, new(codec.JsonHandle))
+               dec := codec.NewDecoderBytes(nmRsp.Data, new(codec.CborHandle))
                if err = dec.Decode(&clRsp); err != nil {
-                       return util.NewNewtError(fmt.Sprintf("Invalid incoming 
json: %s",
+                       return util.NewNewtError(fmt.Sprintf("Invalid incoming 
cbor: %s",
                                err.Error()))
                }
                if clRsp.ErrCode == NMGR_ERR_ENOENT {
@@ -114,7 +113,7 @@ func (cl *CoreDownload) Download(off, size uint32) error {
                                        clRsp.Off, off))
                }
 
-               data, err = base64.StdEncoding.DecodeString(clRsp.Data)
+               data = clRsp.Data
                if err != nil {
                        return util.NewNewtError(fmt.Sprintf("Invalid incoming 
json: %s",
                                err.Error()))

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/ade80cfc/newtmgr/protocol/crash.go
----------------------------------------------------------------------
diff --git a/newtmgr/protocol/crash.go b/newtmgr/protocol/crash.go
index fb171a7..60db8f7 100644
--- a/newtmgr/protocol/crash.go
+++ b/newtmgr/protocol/crash.go
@@ -40,7 +40,7 @@ func NewCrash(crashType string) (*Crash, error) {
 
 func (c *Crash) EncodeWriteRequest() (*NmgrReq, error) {
        data := make([]byte, 0)
-       enc := codec.NewEncoderBytes(&data, new(codec.JsonHandle))
+       enc := codec.NewEncoderBytes(&data, new(codec.CborHandle))
        enc.Encode(c)
 
        fmt.Printf("crashtype:%s\n", c.CrashType)
@@ -62,7 +62,7 @@ func (c *Crash) EncodeWriteRequest() (*NmgrReq, error) {
 func DecodeCrashResponse(data []byte) (*Crash, error) {
        c := &Crash{}
 
-       dec := codec.NewDecoderBytes(data, new(codec.JsonHandle))
+       dec := codec.NewDecoderBytes(data, new(codec.CborHandle))
        if err := dec.Decode(&c); err != nil {
                return nil, util.NewNewtError(fmt.Sprintf("Invalid response: 
%s",
                        err.Error()))

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/ade80cfc/newtmgr/protocol/datetime.go
----------------------------------------------------------------------
diff --git a/newtmgr/protocol/datetime.go b/newtmgr/protocol/datetime.go
index 8e73c5e..451b84a 100644
--- a/newtmgr/protocol/datetime.go
+++ b/newtmgr/protocol/datetime.go
@@ -50,8 +50,8 @@ func (i *DateTime) EncodeRequest() (*NmgrReq, error) {
 
        if i.DateTime != "" {
                data := make([]byte, 0)
-               enc := codec.NewEncoderBytes(&data, new(codec.JsonHandle))
-               enc.Encode(i);
+               enc := codec.NewEncoderBytes(&data, new(codec.CborHandle))
+               enc.Encode(i)
                nmr.Data = data
                nmr.Len = uint16(len(data))
        } else {
@@ -67,10 +67,10 @@ func DecodeDateTimeResponse(data []byte) (*DateTime, error) 
{
        if len(data) == 0 {
                return i, nil
        }
-       dec := codec.NewDecoderBytes(data, new(codec.JsonHandle))
+       dec := codec.NewDecoderBytes(data, new(codec.CborHandle))
        err := dec.Decode(&i)
        if err != nil {
-               return nil, util.NewNewtError(fmt.Sprintf("Invalid incoming 
json: %s",
+               return nil, util.NewNewtError(fmt.Sprintf("Invalid incoming 
cbor: %s",
                        err.Error()))
        }
        return i, nil

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/ade80cfc/newtmgr/protocol/echo.go
----------------------------------------------------------------------
diff --git a/newtmgr/protocol/echo.go b/newtmgr/protocol/echo.go
index b0dc83f..8e86231 100644
--- a/newtmgr/protocol/echo.go
+++ b/newtmgr/protocol/echo.go
@@ -28,8 +28,8 @@ import (
 )
 
 type Echo struct {
-       Message  string `codec:"d"`
-       Response string `codec:"r,omitempty"`
+       Message  string `codec:"d"`
+       Response string `codec:"r,omitempty"`
 }
 
 func NewEcho() (*Echo, error) {
@@ -39,7 +39,7 @@ func NewEcho() (*Echo, error) {
 
 func (e *Echo) EncodeWriteRequest() (*NmgrReq, error) {
        data := make([]byte, 0)
-       enc := codec.NewEncoderBytes(&data, new(codec.JsonHandle))
+       enc := codec.NewEncoderBytes(&data, new(codec.CborHandle))
        if err := enc.Encode(e); err != nil {
                return nil, util.NewNewtError(fmt.Sprintf("Failed to encode 
message %s",
                        err.Error()))
@@ -85,7 +85,7 @@ func (e *Echo) EncodeEchoCtrl() (*NmgrReq, error) {
        nmr.Id = NMGR_ID_CONS_ECHO_CTRL
 
        data := make([]byte, 0)
-       enc := codec.NewEncoderBytes(&data, new(codec.JsonHandle))
+       enc := codec.NewEncoderBytes(&data, new(codec.CborHandle))
        if err := enc.Encode(echoCtl); err != nil {
                return nil, util.NewNewtError(fmt.Sprintf("Failed to encode 
message %s",
                        err.Error()))
@@ -99,7 +99,7 @@ func (e *Echo) EncodeEchoCtrl() (*NmgrReq, error) {
 func DecodeEchoResponse(data []byte) (*Echo, error) {
        e := &Echo{}
 
-       cborCodec := new(codec.JsonHandle)
+       cborCodec := new(codec.CborHandle)
        dec := codec.NewDecoderBytes(data, cborCodec)
 
        if err := dec.Decode(e); err != nil {

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/ade80cfc/newtmgr/protocol/imageboot2.go
----------------------------------------------------------------------
diff --git a/newtmgr/protocol/imageboot2.go b/newtmgr/protocol/imageboot2.go
index 67982b9..3ded958 100644
--- a/newtmgr/protocol/imageboot2.go
+++ b/newtmgr/protocol/imageboot2.go
@@ -27,19 +27,19 @@ import (
 )
 
 type ImageBoot2 struct {
-       BootTarget string
-       Test       string `codec:"test"`
-       Main       string `codec:"main"`
-       Active     string `codec:"active"`
-       ReturnCode int `codec:"rc"`
+       BootTarget []byte
+       Test       []byte `codec:"test"`
+       Main       []byte `codec:"main"`
+       Active     []byte `codec:"active"`
+       ReturnCode int    `codec:"rc"`
 }
 
 func NewImageBoot2() (*ImageBoot2, error) {
        s := &ImageBoot2{}
-       s.BootTarget = ""
-       s.Test = ""
-       s.Main = ""
-       s.Active = ""
+       s.BootTarget = make([]byte, 0)
+       s.Test = make([]byte, 0)
+       s.Main = make([]byte, 0)
+       s.Active = make([]byte, 0)
        return s, nil
 }
 
@@ -55,20 +55,16 @@ func (i *ImageBoot2) EncodeWriteRequest() (*NmgrReq, error) 
{
        nmr.Id = IMGMGR_NMGR_OP_BOOT2
        nmr.Len = 0
 
-       if i.BootTarget != "" {
+       if len(i.BootTarget) != 0 {
                type BootReq struct {
-                       Test string `codec:"test"`
+                       Test []byte `codec:"test"`
                }
 
-               hash, err := HashEncode(i.BootTarget)
-               if err != nil {
-                       return nil, err
-               }
                bReq := &BootReq{
-                       Test: hash,
+                       Test: i.BootTarget,
                }
                data := make([]byte, 0)
-               enc := codec.NewEncoderBytes(&data, new(codec.JsonHandle))
+               enc := codec.NewEncoderBytes(&data, new(codec.CborHandle))
                enc.Encode(bReq)
                nmr.Data = data
                nmr.Len = uint16(len(data))
@@ -83,33 +79,16 @@ func DecodeImageBoot2Response(data []byte) (*ImageBoot2, 
error) {
        if len(data) == 0 {
                return i, nil
        }
-       dec := codec.NewDecoderBytes(data, new(codec.JsonHandle))
+       dec := codec.NewDecoderBytes(data, new(codec.CborHandle))
        err := dec.Decode(&i)
        if err != nil {
-               return nil, util.NewNewtError(fmt.Sprintf("Invalid incoming 
json: %s",
+               return nil, util.NewNewtError(fmt.Sprintf("Invalid incoming 
cbor: %s",
                        err.Error()))
        }
        if i.ReturnCode != 0 {
                return nil, util.NewNewtError(fmt.Sprintf("Target error: %d",
                        i.ReturnCode))
        }
-       if i.Test != "" {
-               i.Test, err = HashDecode(i.Test)
-               if err != nil {
-                       return nil, err
-               }
-       }
-       if i.Main != "" {
-               i.Main, err = HashDecode(i.Main)
-               if err != nil {
-                       return nil, err
-               }
-       }
-       if i.Active != "" {
-               i.Active, err = HashDecode(i.Active)
-               if err != nil {
-                       return nil, err
-               }
-       }
+
        return i, nil
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/ade80cfc/newtmgr/protocol/imagefiledownload.go
----------------------------------------------------------------------
diff --git a/newtmgr/protocol/imagefiledownload.go 
b/newtmgr/protocol/imagefiledownload.go
index 0273eca..4acb83f 100644
--- a/newtmgr/protocol/imagefiledownload.go
+++ b/newtmgr/protocol/imagefiledownload.go
@@ -20,7 +20,6 @@
 package protocol
 
 import (
-       "encoding/base64"
        "fmt"
 
        "github.com/ugorji/go/codec"
@@ -37,6 +36,7 @@ type FileDownload struct {
 func NewFileDownload() (*FileDownload, error) {
        f := &FileDownload{}
        f.Offset = 0
+       f.Data = make([]byte, 0)
 
        return f, nil
 }
@@ -62,7 +62,7 @@ func (f *FileDownload) EncodeWriteRequest() (*NmgrReq, error) 
{
        }
 
        data := make([]byte, 0)
-       enc := codec.NewEncoderBytes(&data, new(codec.JsonHandle))
+       enc := codec.NewEncoderBytes(&data, new(codec.CborHandle))
        enc.Encode(downloadReq)
        nmr.Len = uint16(len(data))
        nmr.Data = data
@@ -74,29 +74,28 @@ func DecodeFileDownloadResponse(data []byte) 
(*FileDownload, error) {
        type DownloadResp struct {
                Off        uint32 `json:"off"`
                Size       uint32 `json:"len"`
-               Data       string `json:"data"`
+               Data       []byte `json:"data"`
                ReturnCode int    `json:"rc"`
        }
        resp := &DownloadResp{}
 
-       dec := codec.NewDecoderBytes(data, new(codec.JsonHandle))
+       dec := codec.NewDecoderBytes(data, new(codec.CborHandle))
        err := dec.Decode(&resp)
        if err != nil {
-               return nil, util.NewNewtError(fmt.Sprintf("Invalid incoming 
json: %s",
+               return nil, util.NewNewtError(fmt.Sprintf("Invalid incoming 
cbor: %s",
                        err.Error()))
        }
        if resp.ReturnCode != 0 {
                return nil, util.NewNewtError(fmt.Sprintf("Target error: %d",
                        resp.ReturnCode))
        }
-       decodedData, err := base64.StdEncoding.DecodeString(resp.Data)
        if err != nil {
                return nil, util.NewNewtError(fmt.Sprintf("Invalid incoming 
json: %s",
                        err.Error()))
        }
        f := &FileDownload{
                Offset: resp.Off,
-               Data:   decodedData,
+               Data:   resp.Data,
                Size:   resp.Size,
        }
        return f, nil

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/ade80cfc/newtmgr/protocol/imagefileupload.go
----------------------------------------------------------------------
diff --git a/newtmgr/protocol/imagefileupload.go 
b/newtmgr/protocol/imagefileupload.go
index 6a2833a..229f4f9 100644
--- a/newtmgr/protocol/imagefileupload.go
+++ b/newtmgr/protocol/imagefileupload.go
@@ -20,7 +20,6 @@
 package protocol
 
 import (
-       "encoding/base64"
        "fmt"
 
        "github.com/ugorji/go/codec"
@@ -45,13 +44,13 @@ func NewFileUpload() (*FileUpload, error) {
 func (f *FileUpload) EncodeWriteRequest() (*NmgrReq, error) {
        type UploadReq struct {
                Off  uint32 `codec:"off"`
-               Data string `codec:"data"`
+               Data []byte `codec:"data"`
        }
        type UploadFirstReq struct {
                Off  uint32 `codec:"off"`
                Size uint32 `codec:"len"`
                Name string `codec:"name"`
-               Data string `codec:"data"`
+               Data []byte `codec:"data"`
        }
        nmr, err := NewNmgrReq()
        if err != nil {
@@ -70,16 +69,16 @@ func (f *FileUpload) EncodeWriteRequest() (*NmgrReq, error) 
{
                        Off:  f.Offset,
                        Size: f.Size,
                        Name: f.Name,
-                       Data: base64.StdEncoding.EncodeToString(f.Data),
+                       Data: f.Data,
                }
-               enc := codec.NewEncoderBytes(&data, new(codec.JsonHandle))
+               enc := codec.NewEncoderBytes(&data, new(codec.CborHandle))
                enc.Encode(uploadReq)
        } else {
                uploadReq := &UploadReq{
                        Off:  f.Offset,
-                       Data: base64.StdEncoding.EncodeToString(f.Data),
+                       Data: f.Data,
                }
-               enc := codec.NewEncoderBytes(&data, new(codec.JsonHandle))
+               enc := codec.NewEncoderBytes(&data, new(codec.CborHandle))
                enc.Encode(uploadReq)
        }
        nmr.Len = uint16(len(data))
@@ -91,10 +90,10 @@ func (f *FileUpload) EncodeWriteRequest() (*NmgrReq, error) 
{
 func DecodeFileUploadResponse(data []byte) (*FileUpload, error) {
        f := &FileUpload{}
 
-       dec := codec.NewDecoderBytes(data, new(codec.JsonHandle))
+       dec := codec.NewDecoderBytes(data, new(codec.CborHandle))
        err := dec.Decode(&f)
        if err != nil {
-               return nil, util.NewNewtError(fmt.Sprintf("Invalid incoming 
json: %s",
+               return nil, util.NewNewtError(fmt.Sprintf("Invalid incoming 
cbor: %s",
                        err.Error()))
        }
        if f.ReturnCode != 0 {

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/ade80cfc/newtmgr/protocol/imagelist2.go
----------------------------------------------------------------------
diff --git a/newtmgr/protocol/imagelist2.go b/newtmgr/protocol/imagelist2.go
index 13c6f90..04bb0b4 100644
--- a/newtmgr/protocol/imagelist2.go
+++ b/newtmgr/protocol/imagelist2.go
@@ -29,7 +29,7 @@ import (
 type Image2 struct {
        Slot     int    `codec:"slot"`
        Version  string `codec:"version"`
-       Hash     string `codec:"hash"`
+       Hash     []byte `codec:"hash"`
        Bootable bool   `codec:"bootable"`
 }
 
@@ -61,10 +61,10 @@ func DecodeImageListResponse2(data []byte) (*ImageList2, 
error) {
 
        list2 := &ImageList2{}
 
-       dec := codec.NewDecoderBytes(data, new(codec.JsonHandle))
+       dec := codec.NewDecoderBytes(data, new(codec.CborHandle))
        err := dec.Decode(&list2)
        if err != nil {
-               return nil, util.NewNewtError(fmt.Sprintf("Invalid incoming 
json: %s",
+               return nil, util.NewNewtError(fmt.Sprintf("Invalid incoming 
cbor: %s",
                        err.Error()))
        }
        return list2, nil

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/ade80cfc/newtmgr/protocol/imagesplit.go
----------------------------------------------------------------------
diff --git a/newtmgr/protocol/imagesplit.go b/newtmgr/protocol/imagesplit.go
index 05435e9..7c91cce 100644
--- a/newtmgr/protocol/imagesplit.go
+++ b/newtmgr/protocol/imagesplit.go
@@ -141,7 +141,7 @@ func (s *Split) EncoderReadRequest() (*NmgrReq, error) {
 func (s *Split) EncoderWriteRequest() (*NmgrReq, error) {
 
        data := make([]byte, 0)
-       enc := codec.NewEncoderBytes(&data, new(codec.JsonHandle))
+       enc := codec.NewEncoderBytes(&data, new(codec.CborHandle))
        err := enc.Encode(s)
        if err != nil {
                return nil, err
@@ -169,10 +169,10 @@ func DecodeSplitReadResponse(data []byte) (*Split, error) 
{
                return i, nil
        }
 
-       dec := codec.NewDecoderBytes(data, new(codec.JsonHandle))
+       dec := codec.NewDecoderBytes(data, new(codec.CborHandle))
        err := dec.Decode(&i)
        if err != nil {
-               return nil, util.NewNewtError(fmt.Sprintf("Invalid incoming 
json: %s",
+               return nil, util.NewNewtError(fmt.Sprintf("Invalid incoming 
cbor: %s",
                        err.Error()))
        }
        if i.ReturnCode != 0 {

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/ade80cfc/newtmgr/protocol/imageupload.go
----------------------------------------------------------------------
diff --git a/newtmgr/protocol/imageupload.go b/newtmgr/protocol/imageupload.go
index 43cd9f4..099352b 100644
--- a/newtmgr/protocol/imageupload.go
+++ b/newtmgr/protocol/imageupload.go
@@ -20,7 +20,6 @@
 package protocol
 
 import (
-       "encoding/base64"
        "fmt"
 
        "github.com/ugorji/go/codec"
@@ -44,12 +43,12 @@ func NewImageUpload() (*ImageUpload, error) {
 func (i *ImageUpload) EncodeWriteRequest() (*NmgrReq, error) {
        type UploadReq struct {
                Off  uint32 `codec:"off"`
-               Data string `codec:"data"`
+               Data []byte `codec:"data"`
        }
        type UploadFirstReq struct {
                Off  uint32 `codec:"off"`
                Size uint32 `codec:"len"`
-               Data string `codec:"data"`
+               Data []byte `codec:"data"`
        }
        nmr, err := NewNmgrReq()
        if err != nil {
@@ -67,16 +66,16 @@ func (i *ImageUpload) EncodeWriteRequest() (*NmgrReq, 
error) {
                uploadReq := &UploadFirstReq{
                        Off:  i.Offset,
                        Size: i.Size,
-                       Data: base64.StdEncoding.EncodeToString(i.Data),
+                       Data: i.Data,
                }
-               enc := codec.NewEncoderBytes(&data, new(codec.JsonHandle))
+               enc := codec.NewEncoderBytes(&data, new(codec.CborHandle))
                enc.Encode(uploadReq)
        } else {
                uploadReq := &UploadReq{
                        Off:  i.Offset,
-                       Data: base64.StdEncoding.EncodeToString(i.Data),
+                       Data: i.Data,
                }
-               enc := codec.NewEncoderBytes(&data, new(codec.JsonHandle))
+               enc := codec.NewEncoderBytes(&data, new(codec.CborHandle))
                enc.Encode(uploadReq)
        }
        nmr.Len = uint16(len(data))
@@ -88,10 +87,10 @@ func (i *ImageUpload) EncodeWriteRequest() (*NmgrReq, 
error) {
 func DecodeImageUploadResponse(data []byte) (*ImageUpload, error) {
        i := &ImageUpload{}
 
-       dec := codec.NewDecoderBytes(data, new(codec.JsonHandle))
+       dec := codec.NewDecoderBytes(data, new(codec.CborHandle))
        err := dec.Decode(&i)
        if err != nil {
-               return nil, util.NewNewtError(fmt.Sprintf("Invalid incoming 
json: %s",
+               return nil, util.NewNewtError(fmt.Sprintf("Invalid incoming 
cbor: %s",
                        err.Error()))
        }
        if i.ReturnCode != 0 {

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/ade80cfc/newtmgr/protocol/logs.go
----------------------------------------------------------------------
diff --git a/newtmgr/protocol/logs.go b/newtmgr/protocol/logs.go
index 539e9f4..0dda278 100644
--- a/newtmgr/protocol/logs.go
+++ b/newtmgr/protocol/logs.go
@@ -118,7 +118,7 @@ func (sr *LogsModuleListReq) Encode() (*NmgrReq, error) {
        req := &LogsModuleListReq{}
 
        data := make([]byte, 0)
-       enc := codec.NewEncoderBytes(&data, new(codec.JsonHandle))
+       enc := codec.NewEncoderBytes(&data, new(codec.CborHandle))
        enc.Encode(req)
 
        nmr.Data = data
@@ -129,10 +129,10 @@ func (sr *LogsModuleListReq) Encode() (*NmgrReq, error) {
 
 func DecodeLogsListResponse(data []byte) (*LogsListRsp, error) {
        var resp LogsListRsp
-       dec := codec.NewDecoderBytes(data, new(codec.JsonHandle))
+       dec := codec.NewDecoderBytes(data, new(codec.CborHandle))
        err := dec.Decode(&resp)
        if err != nil {
-               return nil, util.NewNewtError(fmt.Sprintf("Invalid incoming 
json: %s",
+               return nil, util.NewNewtError(fmt.Sprintf("Invalid incoming 
cbor: %s",
                        err.Error()))
        }
 
@@ -153,7 +153,7 @@ func (sr *LogsListReq) Encode() (*NmgrReq, error) {
        req := &LogsListReq{}
 
        data := make([]byte, 0)
-       enc := codec.NewEncoderBytes(&data, new(codec.JsonHandle))
+       enc := codec.NewEncoderBytes(&data, new(codec.CborHandle))
        enc.Encode(req)
 
        nmr.Data = data
@@ -164,10 +164,10 @@ func (sr *LogsListReq) Encode() (*NmgrReq, error) {
 
 func DecodeLogsLevelListResponse(data []byte) (*LogsLevelListRsp, error) {
        var resp LogsLevelListRsp
-       dec := codec.NewDecoderBytes(data, new(codec.JsonHandle))
+       dec := codec.NewDecoderBytes(data, new(codec.CborHandle))
        err := dec.Decode(&resp)
        if err != nil {
-               return nil, util.NewNewtError(fmt.Sprintf("Invalid incoming 
json: %s",
+               return nil, util.NewNewtError(fmt.Sprintf("Invalid incoming 
cbor: %s",
                        err.Error()))
        }
 
@@ -188,7 +188,7 @@ func (sr *LogsLevelListReq) Encode() (*NmgrReq, error) {
        req := &LogsLevelListReq{}
 
        data := make([]byte, 0)
-       enc := codec.NewEncoderBytes(&data, new(codec.JsonHandle))
+       enc := codec.NewEncoderBytes(&data, new(codec.CborHandle))
        enc.Encode(req)
        nmr.Data = data
        nmr.Len = uint16(len(data))
@@ -198,10 +198,10 @@ func (sr *LogsLevelListReq) Encode() (*NmgrReq, error) {
 
 func DecodeLogsModuleListResponse(data []byte) (*LogsModuleListRsp, error) {
        var resp LogsModuleListRsp
-       dec := codec.NewDecoderBytes(data, new(codec.JsonHandle))
+       dec := codec.NewDecoderBytes(data, new(codec.CborHandle))
        err := dec.Decode(&resp)
        if err != nil {
-               return nil, util.NewNewtError(fmt.Sprintf("Invalid incoming 
json: %s",
+               return nil, util.NewNewtError(fmt.Sprintf("Invalid incoming 
cbor: %s",
                        err.Error()))
        }
 
@@ -225,7 +225,7 @@ func (sr *LogsShowReq) Encode() (*NmgrReq, error) {
        }
 
        data := make([]byte, 0)
-       enc := codec.NewEncoderBytes(&data, new(codec.JsonHandle))
+       enc := codec.NewEncoderBytes(&data, new(codec.CborHandle))
        enc.Encode(req)
        nmr.Data = data
        nmr.Len = uint16(len(data))
@@ -235,10 +235,10 @@ func (sr *LogsShowReq) Encode() (*NmgrReq, error) {
 
 func DecodeLogsShowResponse(data []byte) (*LogsShowRsp, error) {
        var resp LogsShowRsp
-       dec := codec.NewDecoderBytes(data, new(codec.JsonHandle))
+       dec := codec.NewDecoderBytes(data, new(codec.CborHandle))
        err := dec.Decode(&resp)
        if err != nil {
-               return nil, util.NewNewtError(fmt.Sprintf("Invalid incoming 
json: %s",
+               return nil, util.NewNewtError(fmt.Sprintf("Invalid incoming 
cbor: %s",
                        err.Error()))
        }
 
@@ -272,7 +272,7 @@ func (sr *LogsClearReq) Encode() (*NmgrReq, error) {
        req := &LogsClearReq{}
 
        data := make([]byte, 0)
-       enc := codec.NewEncoderBytes(&data, new(codec.JsonHandle))
+       enc := codec.NewEncoderBytes(&data, new(codec.CborHandle))
        enc.Encode(req)
        nmr.Data = data
        nmr.Len = uint16(len(data))
@@ -282,10 +282,10 @@ func (sr *LogsClearReq) Encode() (*NmgrReq, error) {
 
 func DecodeLogsClearResponse(data []byte) (*LogsClearRsp, error) {
        var resp LogsClearRsp
-       dec := codec.NewDecoderBytes(data, new(codec.JsonHandle))
+       dec := codec.NewDecoderBytes(data, new(codec.CborHandle))
        err := dec.Decode(&resp)
        if err != nil {
-               return nil, util.NewNewtError(fmt.Sprintf("Invalid incoming 
json: %s",
+               return nil, util.NewNewtError(fmt.Sprintf("Invalid incoming 
cbor: %s",
                        err.Error()))
        }
 
@@ -321,7 +321,7 @@ func (sr *LogsAppendReq) Encode() (*NmgrReq, error) {
        req := &LogsAppendReq{}
 
        data := make([]byte, 0)
-       enc := codec.NewEncoderBytes(&data, new(codec.JsonHandle))
+       enc := codec.NewEncoderBytes(&data, new(codec.CborHandle))
        enc.Encode(req)
        nmr.Data = data
        nmr.Len = uint16(len(data))
@@ -331,10 +331,10 @@ func (sr *LogsAppendReq) Encode() (*NmgrReq, error) {
 
 func DecodeLogsAppendResponse(data []byte) (*LogsAppendRsp, error) {
        var resp LogsAppendRsp
-       dec := codec.NewDecoderBytes(data, new(codec.JsonHandle))
+       dec := codec.NewDecoderBytes(data, new(codec.CborHandle))
        err := dec.Decode(&resp)
        if err != nil {
-               return nil, util.NewNewtError(fmt.Sprintf("Invalid incoming 
json: %s",
+               return nil, util.NewNewtError(fmt.Sprintf("Invalid incoming 
cbor: %s",
                        err.Error()))
        }
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/ade80cfc/newtmgr/protocol/mpstats.go
----------------------------------------------------------------------
diff --git a/newtmgr/protocol/mpstats.go b/newtmgr/protocol/mpstats.go
index 637ed7e..9c531cc 100644
--- a/newtmgr/protocol/mpstats.go
+++ b/newtmgr/protocol/mpstats.go
@@ -58,10 +58,10 @@ func (tsr *MempoolStatsReadReq) EncodeWriteRequest() 
(*NmgrReq, error) {
 
 func DecodeMempoolStatsReadResponse(data []byte) (*MempoolStatsReadRsp, error) 
{
        var tsr MempoolStatsReadRsp
-       dec := codec.NewDecoderBytes(data, new(codec.JsonHandle))
+       dec := codec.NewDecoderBytes(data, new(codec.CborHandle))
        err := dec.Decode(&tsr)
        if err != nil {
-               return nil, util.NewNewtError(fmt.Sprintf("Invalid incoming 
json: %s",
+               return nil, util.NewNewtError(fmt.Sprintf("Invalid incoming 
cbor: %s",
                        err.Error()))
        }
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/ade80cfc/newtmgr/protocol/stats.go
----------------------------------------------------------------------
diff --git a/newtmgr/protocol/stats.go b/newtmgr/protocol/stats.go
index df5f896..b1a7eb4 100644
--- a/newtmgr/protocol/stats.go
+++ b/newtmgr/protocol/stats.go
@@ -66,10 +66,10 @@ func NewStatsReadReq() (*StatsReadReq, error) {
 func DecodeStatsListResponse(data []byte) (*StatsListRsp, error) {
        var resp StatsListRsp
 
-       dec := codec.NewDecoderBytes(data, new(codec.JsonHandle))
+       dec := codec.NewDecoderBytes(data, new(codec.CborHandle))
        err := dec.Decode(&resp)
        if err != nil {
-               return nil, util.NewNewtError(fmt.Sprintf("Invalid incoming 
json: %s",
+               return nil, util.NewNewtError(fmt.Sprintf("Invalid incoming 
cbor: %s",
                        err.Error()))
        }
 
@@ -90,7 +90,7 @@ func (sr *StatsListReq) Encode() (*NmgrReq, error) {
        req := &StatsListReq{}
 
        data := make([]byte, 0)
-       enc := codec.NewEncoderBytes(&data, new(codec.JsonHandle))
+       enc := codec.NewEncoderBytes(&data, new(codec.CborHandle))
        enc.Encode(req)
 
        nmr.Data = data
@@ -115,7 +115,7 @@ func (sr *StatsReadReq) Encode() (*NmgrReq, error) {
        }
 
        data := make([]byte, 0)
-       enc := codec.NewEncoderBytes(&data, new(codec.JsonHandle))
+       enc := codec.NewEncoderBytes(&data, new(codec.CborHandle))
        enc.Encode(srr)
 
        nmr.Data = data
@@ -127,10 +127,10 @@ func (sr *StatsReadReq) Encode() (*NmgrReq, error) {
 func DecodeStatsReadResponse(data []byte) (*StatsReadRsp, error) {
        var sr StatsReadRsp
 
-       dec := codec.NewDecoderBytes(data, new(codec.JsonHandle))
+       dec := codec.NewDecoderBytes(data, new(codec.CborHandle))
        err := dec.Decode(&sr)
        if err != nil {
-               return nil, util.NewNewtError(fmt.Sprintf("Invalid incoming 
json: %s",
+               return nil, util.NewNewtError(fmt.Sprintf("Invalid incoming 
cbor: %s",
                        err.Error()))
        }
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/ade80cfc/newtmgr/protocol/taskstats.go
----------------------------------------------------------------------
diff --git a/newtmgr/protocol/taskstats.go b/newtmgr/protocol/taskstats.go
index 2a23c54..0a83238 100644
--- a/newtmgr/protocol/taskstats.go
+++ b/newtmgr/protocol/taskstats.go
@@ -59,10 +59,10 @@ func (tsr *TaskStatsReadReq) EncodeWriteRequest() 
(*NmgrReq, error) {
 func DecodeTaskStatsReadResponse(data []byte) (*TaskStatsReadRsp, error) {
        var tsr TaskStatsReadRsp
 
-       dec := codec.NewDecoderBytes(data, new(codec.JsonHandle))
+       dec := codec.NewDecoderBytes(data, new(codec.CborHandle))
        err := dec.Decode(&tsr)
        if err != nil {
-               return nil, util.NewNewtError(fmt.Sprintf("Invalid incoming 
json: %s",
+               return nil, util.NewNewtError(fmt.Sprintf("Invalid incoming 
cbor: %s",
                        err.Error()))
        }
 

Reply via email to