Bumps [github.com/shamaton/msgpack/v2](https://github.com/shamaton/msgpack) from 2.3.0 to 2.3.1. - [Release notes](https://github.com/shamaton/msgpack/releases) - [Commits](https://github.com/shamaton/msgpack/compare/v2.3.0...v2.3.1) --- updated-dependencies: - dependency-name: github.com/shamaton/msgpack/v2 dependency-version: 2.3.1 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com>
44 lines
1.0 KiB
Go
44 lines
1.0 KiB
Go
package encoding
|
|
|
|
import (
|
|
"math"
|
|
"unsafe"
|
|
|
|
"github.com/shamaton/msgpack/v2/def"
|
|
)
|
|
|
|
func (e *encoder) calcString(v string) int {
|
|
// NOTE : unsafe
|
|
strBytes := *(*[]byte)(unsafe.Pointer(&v))
|
|
l := len(strBytes)
|
|
if l < 32 {
|
|
return def.Byte1 + l
|
|
} else if l <= math.MaxUint8 {
|
|
return def.Byte1 + def.Byte1 + l
|
|
} else if l <= math.MaxUint16 {
|
|
return def.Byte1 + def.Byte2 + l
|
|
}
|
|
return def.Byte1 + def.Byte4 + l
|
|
// NOTE : length over uint32
|
|
}
|
|
|
|
func (e *encoder) writeString(str string, offset int) int {
|
|
// NOTE : unsafe
|
|
strBytes := *(*[]byte)(unsafe.Pointer(&str))
|
|
l := len(strBytes)
|
|
if l < 32 {
|
|
offset = e.setByte1Int(def.FixStr+l, offset)
|
|
} else if l <= math.MaxUint8 {
|
|
offset = e.setByte1Int(def.Str8, offset)
|
|
offset = e.setByte1Int(l, offset)
|
|
} else if l <= math.MaxUint16 {
|
|
offset = e.setByte1Int(def.Str16, offset)
|
|
offset = e.setByte2Int(l, offset)
|
|
} else {
|
|
offset = e.setByte1Int(def.Str32, offset)
|
|
offset = e.setByte4Int(l, offset)
|
|
}
|
|
offset += copy(e.d[offset:], str)
|
|
return offset
|
|
}
|