-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
byte.go
32 lines (27 loc) · 1.01 KB
/
byte.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
package varint
import com "github.com/mus-format/common-go"
// MarshalByte fills bs with the MUS encoding (Varint) of a byte value.
//
// Returns the number of used bytes. It will panic if receives too small bs.
func MarshalByte(v byte, bs []byte) (n int) {
return marshalUint(v, bs)
}
// UnmarshalByte parses a MUS-encoded (Varint) byte value from bs.
//
// In addition to the byte value and the number of used bytes, it can also
// return mus.ErrTooSmallByteSlice or com.ErrOverflow.
func UnmarshalByte(bs []byte) (v byte, n int, err error) {
return unmarshalUint[byte](com.Uint8MaxVarintLen, com.Uint8MaxLastByte,
bs)
}
// SizeByte returns the size of a MUS-encoded (Varint) byte value.
func SizeByte(v byte) (size int) {
return sizeUint(v)
}
// SkipByte skips a MUS-encoded (Varint) byte.
//
// In addition to the number of skipped bytes, it can also return
// mus.ErrTooSmallByteSlice or com.ErrOverflow.
func SkipByte(bs []byte) (n int, err error) {
return skipUint(com.Uint8MaxVarintLen, com.Uint8MaxLastByte, bs)
}