]> Sergey Matveev's repositories - btrtrc.git/blob - peer_protocol/int.go
Improvements to decoder fuzzing
[btrtrc.git] / peer_protocol / int.go
1 package peer_protocol
2
3 import (
4         "bytes"
5         "encoding/binary"
6         "io"
7 )
8
9 type Integer uint32
10
11 func (i *Integer) Read(r io.Reader) error {
12         return binary.Read(r, binary.BigEndian, i)
13 }
14
15 func (i *Integer) UnmarshalBinary(b []byte) error {
16         return i.Read(bytes.NewReader(b))
17 }
18
19 // It's perfectly fine to cast these to an int. TODO: Or is it?
20 func (i Integer) Int() int {
21         return int(i)
22 }
23
24 func (i Integer) Uint64() uint64 {
25         return uint64(i)
26 }
27
28 func (i Integer) Uint32() uint32 {
29         return uint32(i)
30 }