Rename peer_ips to peer_prefixes and simplify EncodePrefix with AsSlice

This commit is contained in:
Viktor Liu
2026-03-19 13:38:55 +01:00
parent 01c4d5761d
commit 63c19dbf2e
3 changed files with 169 additions and 180 deletions

View File

@@ -17,19 +17,7 @@ import (
// The address is always unmapped before encoding.
func EncodePrefix(p netip.Prefix) []byte {
addr := p.Addr().Unmap()
raw := addr.As16()
if addr.Is4() {
b := make([]byte, 5)
copy(b, raw[12:16])
b[4] = byte(p.Bits())
return b
}
b := make([]byte, 17)
copy(b, raw[:])
b[16] = byte(p.Bits())
return b
return append(addr.AsSlice(), byte(p.Bits()))
}
// DecodePrefix decodes compact bytes into a netip.Prefix.