mirror of
https://github.com/AdguardTeam/AdGuardDNS.git
synced 2025-02-20 11:23:36 +08:00
28 lines
541 B
Go
28 lines
541 B
Go
// Package agdprotobuf contains protobuf utils.
|
|
package agdprotobuf
|
|
|
|
import (
|
|
"fmt"
|
|
"net/netip"
|
|
)
|
|
|
|
// ByteSlicesToIPs converts a slice of byte slices into a slice of netip.Addrs.
|
|
func ByteSlicesToIPs(data [][]byte) (ips []netip.Addr, err error) {
|
|
if data == nil {
|
|
return nil, nil
|
|
}
|
|
|
|
ips = make([]netip.Addr, 0, len(data))
|
|
for i, ipData := range data {
|
|
var ip netip.Addr
|
|
err = ip.UnmarshalBinary(ipData)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("ip at index %d: %w", i, err)
|
|
}
|
|
|
|
ips = append(ips, ip)
|
|
}
|
|
|
|
return ips, nil
|
|
}
|