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) +}