status-go/vendor/github.com/anacrolix/torrent/peer_protocol/compactip.go

23 lines
390 B
Go
Raw Permalink Normal View History

2022-03-10 09:44:48 +00:00
package peer_protocol
import (
"net"
"github.com/anacrolix/torrent/bencode"
)
// Marshals to the smallest compact byte representation.
type CompactIp net.IP
var _ bencode.Marshaler = CompactIp{}
func (me CompactIp) MarshalBencode() ([]byte, error) {
return bencode.Marshal(func() []byte {
if ip4 := net.IP(me).To4(); ip4 != nil {
return ip4
} else {
return me
}
}())
}