From d41e5f209dbbe90453cc797457f0293fa8529163 Mon Sep 17 00:00:00 2001 From: Ondrej Fabry Date: Tue, 15 Oct 2019 15:33:46 +0200 Subject: [PATCH] fix: Use jsonpb for unmarshalling proto messages from json Signed-off-by: Ondrej Fabry --- datasync/syncbase/kv_iterator.go | 5 +++-- datasync/syncbase/msg/change_event.go | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/datasync/syncbase/kv_iterator.go b/datasync/syncbase/kv_iterator.go index ca75cf5bd..e8f0625a4 100644 --- a/datasync/syncbase/kv_iterator.go +++ b/datasync/syncbase/kv_iterator.go @@ -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" ) @@ -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. diff --git a/datasync/syncbase/msg/change_event.go b/datasync/syncbase/msg/change_event.go index 871efae71..5d7eb7896 100644 --- a/datasync/syncbase/msg/change_event.go +++ b/datasync/syncbase/msg/change_event.go @@ -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" @@ -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.