-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutils_bytes.go
More file actions
39 lines (35 loc) · 661 Bytes
/
utils_bytes.go
File metadata and controls
39 lines (35 loc) · 661 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package parco
import (
"bytes"
"fmt"
"math"
)
func MaxByteSize64(byteLength int) int64 {
switch byteLength {
case 1:
return math.MaxUint8
case 2:
return math.MaxUint16
case 4:
return math.MaxUint32
case 8:
return math.MaxInt64
default:
return (1 << (byteLength / 8)) - 1
}
}
func MaxSize(byteLength int) int {
return int(MaxByteSize64(byteLength))
}
func FormatBytes(data []byte) string {
var buf bytes.Buffer
buf.WriteString("[]byte{")
if len(data) > 0 {
buf.WriteString(fmt.Sprintf("%d", data[0]))
}
for i := 1; i < len(data); i++ {
buf.WriteString(fmt.Sprintf(", %d", data[i]))
}
buf.WriteByte('}')
return buf.String()
}