push
wercker.com
501 of 992 relevant lines covered (50.5%)
397.84 hits per line
1 |
package packet
|
|
2 |
|
|
3 |
// encodeUint16 converts the unsigned 16-bit integer
|
|
4 |
// into a slice of bytes in big-endian order.
|
|
5 |
func encodeUint16(n uint16) []byte { |
65,549✔ |
6 |
return []byte{byte(n >> 8), byte(n)} |
65,549✔ |
7 |
} |
65,549✔ |
8 |
|
|
9 |
// encodeLength encodes the unsigned integer
|
|
10 |
// by using a variable length encoding scheme.
|
|
11 |
func encodeLength(n uint32) uint32 { |
13✔ |
12 |
var value, digit uint32 |
13✔ |
13 |
|
13✔ |
14 |
for n > 0 { |
23✔ |
15 |
if value != 0 { |
12✔ |
16 |
value <<= 8
|
12✔ |
17 |
} |
12✔ |
18 |
|
|
19 |
digit = n % 128
|
23✔ |
20 |
|
23✔ |
21 |
n /= 128
|
23✔ |
22 |
|
23✔ |
23 |
if n > 0 { |
12✔ |
24 |
digit |= 0x80
|
12✔ |
25 |
} |
12✔ |
26 |
|
|
27 |
value |= digit |
23✔ |
28 |
} |
|
29 |
|
|
30 |
return value
|
13✔ |
31 |
} |