Skip to content

Commit

Permalink
fix: Use jsonpb for unmarshalling proto messages from json
Browse files Browse the repository at this point in the history
Signed-off-by: Ondrej Fabry <ofabry@cisco.com>
  • Loading branch information
ondrej-fabry committed Oct 15, 2019
1 parent 824dc65 commit d41e5f2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
5 changes: 3 additions & 2 deletions datasync/syncbase/kv_iterator.go
Expand Up @@ -15,8 +15,9 @@
package syncbase

import (
"encoding/json"
"bytes"

"github.com/golang/protobuf/jsonpb"
"github.com/golang/protobuf/proto"
"github.com/ligato/cn-infra/datasync"
)
Expand Down Expand Up @@ -97,7 +98,7 @@ func (kv *KeyValBytes) GetKey() string {

// GetValue returns the value of the pair.
func (kv *KeyValBytes) GetValue(message proto.Message) error {
return json.Unmarshal(kv.value, message)
return jsonpb.Unmarshal(bytes.NewReader(kv.value), message)
}

// GetRevision returns revision associated with the latest change in the key-value pair.
Expand Down
5 changes: 3 additions & 2 deletions datasync/syncbase/msg/change_event.go
Expand Up @@ -15,9 +15,10 @@
package msg

import (
"bytes"
"context"
"encoding/json"

"github.com/golang/protobuf/jsonpb"
"github.com/golang/protobuf/proto"
"github.com/ligato/cn-infra/datasync"
"github.com/ligato/cn-infra/logging/logrus"
Expand Down Expand Up @@ -87,7 +88,7 @@ func (ev *ChangeWatchResp) GetRevision() int64 {

// GetValue - see the comments in the interface datasync.ChangeEvent.
func (ev *ChangeWatchResp) GetValue(val proto.Message) error {
return json.Unmarshal(ev.message.Content, val) //TODO use contentType...
return jsonpb.Unmarshal(bytes.NewReader(ev.message.Content), val) //TODO use contentType...
}

// GetPrevValue returns the value before change.
Expand Down

0 comments on commit d41e5f2

Please sign in to comment.