File: uint.go

package info (click to toggle)
golang-github-segmentio-encoding 0.5.3-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 14,468 kB
  • sloc: makefile: 286
file content (34 lines) | stat: -rw-r--r-- 657 bytes parent folder | download
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
package proto

import "unsafe"

var uintCodec = codec{
	wire:   varint,
	size:   sizeOfUint,
	encode: encodeUint,
	decode: decodeUint,
}

func sizeOfUint(p unsafe.Pointer, flags flags) int {
	if p != nil {
		if v := *(*uint)(p); v != 0 || flags.has(wantzero) {
			return sizeOfVarint(uint64(v))
		}
	}
	return 0
}

func encodeUint(b []byte, p unsafe.Pointer, flags flags) (int, error) {
	if p != nil {
		if v := *(*uint)(p); v != 0 || flags.has(wantzero) {
			return encodeVarint(b, uint64(v))
		}
	}
	return 0, nil
}

func decodeUint(b []byte, p unsafe.Pointer, _ flags) (int, error) {
	v, n, err := decodeVarint(b)
	*(*uint)(p) = uint(v)
	return n, err
}