-
Notifications
You must be signed in to change notification settings - Fork 22
/
cidr.go
52 lines (40 loc) · 842 Bytes
/
cidr.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package schema
import "encoding/json"
type CIDR Inet
type CIDRTransformer interface {
TransformCIDR(*CIDR) any
}
func (dst *CIDR) GetStatus() Status {
return dst.Status
}
func (*CIDR) Type() ValueType {
return TypeCIDR
}
func (dst *CIDR) Size() int {
return len(dst.IPNet.IP) + len(dst.IPNet.Mask)
}
func (dst *CIDR) String() string {
if dst.Status == Present {
return dst.IPNet.String()
}
return ""
}
func (dst *CIDR) Equal(src CQType) bool {
if src == nil {
return false
}
s, ok := src.(*CIDR)
if !ok {
return false
}
return dst.Status == s.Status && dst.IPNet.String() == s.IPNet.String()
}
func (dst *CIDR) Set(src any) error {
return (*Inet)(dst).Set(src)
}
func (dst CIDR) Get() any {
return (Inet)(dst).Get()
}
func (dst *CIDR) UnmarshalJSON(b []byte) error {
return json.Unmarshal(b, (*Inet)(dst))
}