From bcacc83df6c9b987ce772c2a140a613ad43d7421 Mon Sep 17 00:00:00 2001 From: bandl <1658002533@qq.com> Date: Sat, 25 Sep 2021 16:21:28 +0800 Subject: [PATCH] feat(value): update value --- pkg/structure/define.go | 2 +- pkg/structure/value.go | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/pkg/structure/define.go b/pkg/structure/define.go index 39f72d1..7e160fb 100644 --- a/pkg/structure/define.go +++ b/pkg/structure/define.go @@ -1,7 +1,7 @@ package structure const ( - defaultLen = 32 // 默认创建的 value 大小 + defaultLen = 8 // 默认创建的 value 大小 ) type DynamicType int8 diff --git a/pkg/structure/value.go b/pkg/structure/value.go index b440db1..d4fa323 100644 --- a/pkg/structure/value.go +++ b/pkg/structure/value.go @@ -3,10 +3,9 @@ package structure import ( "bytes" "encoding/binary" + "gitee.com/timedb/wheatCache/pkg/errorx" "math" "strconv" - - "gitee.com/timedb/wheatCache/pkg/errorx" ) // Value 提供一个基础的 动态类型 @@ -26,7 +25,7 @@ func NewValue() *Value { } func (v *Value) GetLength() int { - return v.length + return len(v.val) } func (v *Value) GetDynamicType() DynamicType { @@ -113,3 +112,10 @@ func (v *Value) InferValue(str string) { v.SetString(str) } + +// ChangeValueLength 根据类型推断 change 的大小 +func (v *Value) ChangeValueLength(f func()) int64 { + startLen := v.GetLength() + f() + return int64(v.GetLength() - startLen) +}