MCPcopy Create free account
hub / github.com/brimdata/super / CompareIP

Function CompareIP

runtime/sam/expr/boolean.go:115–133  ·  view source on GitHub ↗

Comparison returns a Predicate that compares typed byte slices that must be TypeAddr with the value's address using a comparison based on op. Only equality operands are allowed.

(op string, pattern netip.Addr)

Source from the content-addressed store, hash-verified

113// be TypeAddr with the value's address using a comparison based on op.
114// Only equality operands are allowed.
115func CompareIP(op string, pattern netip.Addr) (Boolean, error) {
116 compare, ok := compareAddr[op]
117 if !ok {
118 return nil, fmt.Errorf("unknown addr comparator: %s", op)
119 }
120 return func(val super.Value) super.Value {
121 val = val.Under()
122 if val.IsNull() {
123 return super.Null
124 }
125 if val.IsError() {
126 return val
127 }
128 if val.Type().ID() != super.IDIP {
129 return super.False
130 }
131 return super.NewBool(compare(super.DecodeIP(val.Bytes()), pattern))
132 }, nil
133}
134
135// CompareFloat64 returns a Predicate that compares typed byte slices that must
136// be coercible to an double with the value's double value using a comparison

Callers 1

ComparisonFunction · 0.85

Calls 9

NewBoolFunction · 0.92
DecodeIPFunction · 0.92
compareFunction · 0.85
UnderMethod · 0.80
IsNullMethod · 0.80
IsErrorMethod · 0.80
IDMethod · 0.65
TypeMethod · 0.65
BytesMethod · 0.45

Tested by

no test coverage detected