feat(value): update value

This commit is contained in:
bandl 2021-09-25 16:21:28 +08:00
parent 3d7df7149a
commit bcacc83df6
2 changed files with 10 additions and 4 deletions

View File

@ -1,7 +1,7 @@
package structure
const (
defaultLen = 32 // 默认创建的 value 大小
defaultLen = 8 // 默认创建的 value 大小
)
type DynamicType int8

View File

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