From 533ee32d5daba4d267593e79581afac50b57773c Mon Sep 17 00:00:00 2001 From: Ravi Raju Date: Thu, 10 May 2018 18:21:30 -0700 Subject: [PATCH] fix needed after calling encoder via interface (#60) --- internal/cbor/string.go | 2 +- internal/cbor/types.go | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/internal/cbor/string.go b/internal/cbor/string.go index 681640a..ff42afa 100644 --- a/internal/cbor/string.go +++ b/internal/cbor/string.go @@ -45,7 +45,7 @@ func (Encoder) AppendBytes(dst, s []byte) []byte { } // AppendEmbeddedJSON adds a tag and embeds input JSON as such. -func (Encoder) AppendEmbeddedJSON(dst, s []byte) []byte { +func AppendEmbeddedJSON(dst, s []byte) []byte { major := majorTypeTags minor := additionalTypeEmbeddedJSON diff --git a/internal/cbor/types.go b/internal/cbor/types.go index 2a8a716..eb4f697 100644 --- a/internal/cbor/types.go +++ b/internal/cbor/types.go @@ -24,7 +24,9 @@ func (Encoder) AppendEndMarker(dst []byte) []byte { // AppendObjectData takes an object in form of a byte array and appends to dst. func (Encoder) AppendObjectData(dst []byte, o []byte) []byte { - return append(dst, o...) + // BeginMarker is present in the dst, which + // should not be copied when appending to existing data. + return append(dst, o[1:]...) } // AppendArrayStart adds markers to indicate the start of an array. @@ -434,7 +436,7 @@ func (e Encoder) AppendInterface(dst []byte, i interface{}) []byte { if err != nil { return e.AppendString(dst, fmt.Sprintf("marshaling error: %v", err)) } - return e.AppendEmbeddedJSON(dst, marshaled) + return AppendEmbeddedJSON(dst, marshaled) } // AppendIPAddr encodes and inserts an IP Address (IPv4 or IPv6).