From 1cf63ff17cf9f6995660fa1d0445b1b781f18b14 Mon Sep 17 00:00:00 2001 From: GoEdgeLab Date: Wed, 24 Apr 2024 14:33:15 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=BC=BAKV=E5=AD=97=E8=8A=82=E7=BC=96?= =?UTF-8?q?=E7=A0=81=E5=AE=89=E5=85=A8=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/utils/kvstore/value_encoder_bytes.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/internal/utils/kvstore/value_encoder_bytes.go b/internal/utils/kvstore/value_encoder_bytes.go index ec3ca16..79ed051 100644 --- a/internal/utils/kvstore/value_encoder_bytes.go +++ b/internal/utils/kvstore/value_encoder_bytes.go @@ -10,7 +10,13 @@ func NewBytesValueEncoder[T []byte]() *BytesValueEncoder[T] { } func (this *BytesValueEncoder[T]) Encode(value T) ([]byte, error) { - return value, nil + if len(value) == 0 { + return nil, nil + } + + var resultValue = make([]byte, len(value)) + copy(resultValue, value) + return resultValue, nil } func (this *BytesValueEncoder[T]) EncodeField(value T, fieldName string) ([]byte, error) { @@ -19,6 +25,11 @@ func (this *BytesValueEncoder[T]) EncodeField(value T, fieldName string) ([]byte } func (this *BytesValueEncoder[T]) Decode(valueData []byte) (value T, err error) { - value = valueData + if len(valueData) == 0 { + return + } + + value = make([]byte, len(valueData)) + copy(value, valueData) return }