2
0
mirror of synced 2025-02-24 06:38:14 +00:00
2021-09-30 09:01:10 +10:00

31 lines
493 B
Go

package peer_protocol
import (
"bytes"
"encoding/binary"
"io"
)
type Integer uint32
func (i *Integer) Read(r io.Reader) error {
return binary.Read(r, binary.BigEndian, i)
}
func (i *Integer) UnmarshalBinary(b []byte) error {
return i.Read(bytes.NewReader(b))
}
// It's perfectly fine to cast these to an int. TODO: Or is it?
func (i Integer) Int() int {
return int(i)
}
func (i Integer) Uint64() uint64 {
return uint64(i)
}
func (i Integer) Uint32() uint32 {
return uint32(i)
}