status-go/vendor/github.com/anacrolix/dht/v2/krpc/CompactIPv4NodeAddrs.go

37 lines
877 B
Go
Raw Normal View History

2022-03-10 09:44:48 +00:00
package krpc
import "github.com/anacrolix/missinggo/slices"
type CompactIPv4NodeAddrs []NodeAddr
func (CompactIPv4NodeAddrs) ElemSize() int { return 6 }
func (me CompactIPv4NodeAddrs) MarshalBinary() ([]byte, error) {
return marshalBinarySlice(slices.Map(func(addr NodeAddr) NodeAddr {
if a := addr.IP.To4(); a != nil {
addr.IP = a
}
return addr
}, me).(CompactIPv4NodeAddrs))
}
func (me CompactIPv4NodeAddrs) MarshalBencode() ([]byte, error) {
return bencodeBytesResult(me.MarshalBinary())
}
func (me *CompactIPv4NodeAddrs) UnmarshalBinary(b []byte) error {
return unmarshalBinarySlice(me, b)
}
func (me *CompactIPv4NodeAddrs) UnmarshalBencode(b []byte) error {
return unmarshalBencodedBinary(me, b)
}
func (me CompactIPv4NodeAddrs) NodeAddrs() []NodeAddr {
return me
}
func (me CompactIPv4NodeAddrs) Index(x NodeAddr) int {
return addrIndex(me, x)
}