Files
dependabot[bot] 6a5e3ddc8a chore(deps): bump github.com/shamaton/msgpack/v2 from 2.3.0 to 2.3.1
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>
2025-09-26 06:03:15 +00:00

42 lines
1.0 KiB
Go

package encoding
import (
"fmt"
"math"
"reflect"
"github.com/shamaton/msgpack/v2/def"
)
var typeByte = reflect.TypeOf(byte(0))
func (e *encoder) isByteSlice(rv reflect.Value) bool {
return rv.Type().Elem() == typeByte
}
func (e *encoder) calcByteSlice(l int) (int, error) {
if l <= math.MaxUint8 {
return def.Byte1 + def.Byte1 + l, nil
} else if l <= math.MaxUint16 {
return def.Byte1 + def.Byte2 + l, nil
} else if uint(l) <= math.MaxUint32 {
return def.Byte1 + def.Byte4 + l, nil
}
// not supported error
return 0, fmt.Errorf("%w slice length : %d", def.ErrUnsupportedType, l)
}
func (e *encoder) writeByteSliceLength(l int, offset int) int {
if l <= math.MaxUint8 {
offset = e.setByte1Int(def.Bin8, offset)
offset = e.setByte1Int(l, offset)
} else if l <= math.MaxUint16 {
offset = e.setByte1Int(def.Bin16, offset)
offset = e.setByte2Int(l, offset)
} else if uint(l) <= math.MaxUint32 {
offset = e.setByte1Int(def.Bin32, offset)
offset = e.setByte4Int(l, offset)
}
return offset
}