diff options
| author | 2026-03-06 08:04:32 +0800 | |
|---|---|---|
| committer | 2026-03-06 10:00:35 +0800 | |
| commit | 308bef16d6a1c73b0b135823637e2f06d00fb5db (patch) | |
| tree | 2c4d279639ece679ab3894a6e024a05451587ce1 /internal/intconv | |
| parent | format/pack/ingest: Actually we could just use algo.String() here (diff) | |
| signature | No signature | |
internal/intconv: Add Uint32ToUint8
Diffstat (limited to 'internal/intconv')
| -rw-r--r-- | internal/intconv/intconv.go | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/internal/intconv/intconv.go b/internal/intconv/intconv.go index 8d3ac9c6..ab9d5c63 100644 --- a/internal/intconv/intconv.go +++ b/internal/intconv/intconv.go @@ -77,3 +77,12 @@ func SignExtendByteToUint32(b byte) uint32 { return 0xFFFFFF00 | uint32(b) } + +// Uint32ToUint8 converts v to uint8, returning an error if it overflows. +func Uint32ToUint8(v uint32) (uint8, error) { + if v > math.MaxUint8 { + return 0, fmt.Errorf("intconv: uint32 %d overflows uint8", v) + } + + return uint8(v), nil +} |
