almost done ackshually

This commit is contained in:
2025-01-31 17:18:35 -05:00
parent 6dcf5b9e2e
commit b09cb83017
21 changed files with 1646 additions and 3 deletions

View File

@@ -0,0 +1,51 @@
package netsplit
import (
"net"
)
// SetParent sets the net.IPNet for a Splitter.
func (b *BaseSplitter) SetParent(pfx net.IPNet) {
b.network = &pfx
}
// MarshalText lets a BaseSplitter conform to an encoding.TextMarshaler.
func (b *BaseSplitter) MarshalText() (text []byte, err error) {
if b == nil || b.network == nil {
return
}
text = []byte(b.network.String())
return
}
/*
UnmarshalText lets a BaseSplitter conform to an encoding.TextUnmarshaler.
This is a potentially lossy operation! Any host bits set in the prefix's address will be lost.
They will not be set if the output was originally generated by `subnetter`.
*/
func (b *BaseSplitter) UnmarshalText(text []byte) (err error) {
var s string
var n *net.IPNet
if text == nil {
return
}
s = string(text)
if _, n, err = net.ParseCIDR(s); err != nil {
return
}
*b = BaseSplitter{
network: n,
}
return
}