diff --git a/pkg/io/size.go b/pkg/io/size.go index ea8bcc562..594d6bb0a 100644 --- a/pkg/io/size.go +++ b/pkg/io/size.go @@ -31,9 +31,9 @@ func (cw *counterWriter) Write(p []byte) (int, error) { return n, nil } -// GetVarIntSize returns the size in number of bytes of a variable integer +// getVarIntSize returns the size in number of bytes of a variable integer // (reference: GetVarSize(int value), https://github.com/neo-project/neo/blob/master/neo/IO/Helper.cs) -func GetVarIntSize(value int) int { +func getVarIntSize(value int) int { var size uintptr if value < 0xFD { @@ -46,11 +46,11 @@ func GetVarIntSize(value int) int { return int(size) } -// GetVarStringSize returns the size of a variable string +// getVarStringSize returns the size of a variable string // (reference: GetVarSize(this string value), https://github.com/neo-project/neo/blob/master/neo/IO/Helper.cs) -func GetVarStringSize(value string) int { +func getVarStringSize(value string) int { valueSize := len([]byte(value)) - return GetVarIntSize(valueSize) + valueSize + return getVarIntSize(valueSize) + valueSize } // GetVarSize return the size om bytes of a variable. This implementation is not exactly like the C# @@ -60,19 +60,19 @@ func GetVarSize(value interface{}) int { v := reflect.ValueOf(value) switch v.Kind() { case reflect.String: - return GetVarStringSize(v.String()) + return getVarStringSize(v.String()) case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: - return GetVarIntSize(int(v.Int())) + return getVarIntSize(int(v.Int())) case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64: - return GetVarIntSize(int(v.Uint())) + return getVarIntSize(int(v.Uint())) case reflect.Ptr: vser, ok := v.Interface().(Serializable) if !ok { @@ -106,7 +106,7 @@ func GetVarSize(value interface{}) int { } } - return GetVarIntSize(valueLength) + valueSize + return getVarIntSize(valueLength) + valueSize default: panic(fmt.Sprintf("unable to calculate GetVarSize, %s", reflect.TypeOf(value))) }