forked from grafana/loki
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bytes.go
44 lines (35 loc) · 873 Bytes
/
bytes.go
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
40
41
42
43
44
package storage
import (
"bytes"
"unsafe"
)
// Bytes exists to stop proto copying the byte array
type Bytes []byte
// Marshal just returns bs
func (bs *Bytes) Marshal() ([]byte, error) {
return []byte(*bs), nil
}
// MarshalTo copies Bytes to data
func (bs *Bytes) MarshalTo(data []byte) (n int, err error) {
return copy(data, *bs), nil
}
// Unmarshal updates Bytes to be data, without a copy
func (bs *Bytes) Unmarshal(data []byte) error {
*bs = data
return nil
}
// Size returns the length of Bytes
func (bs *Bytes) Size() int {
return len(*bs)
}
// Equal returns true if other equals Bytes
func (bs *Bytes) Equal(other Bytes) bool {
return bytes.Equal(*bs, other)
}
// Compare Bytes to other
func (bs *Bytes) Compare(other Bytes) int {
return bytes.Compare(*bs, other)
}
func yoloString(buf []byte) string {
return *((*string)(unsafe.Pointer(&buf)))
}