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

Function AppendNet

primitive.go:309–320  ·  view source on GitHub ↗
(zb scode.Bytes, p netip.Prefix)

Source from the content-addressed store, hash-verified

307var ones = [16]byte{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}
308
309func AppendNet(zb scode.Bytes, p netip.Prefix) scode.Bytes {
310 // Mask for canonical form.
311 p = p.Masked()
312 zb = append(zb, p.Addr().AsSlice()...)
313 length := p.Addr().BitLen() / 8
314 onesAddr, ok := netip.AddrFromSlice(ones[:length])
315 if !ok {
316 panic(fmt.Sprintf("bad slice length %d for %s", length, p))
317 }
318 mask := netip.PrefixFrom(onesAddr, p.Bits()).Masked()
319 return append(zb, mask.Addr().AsSlice()...)
320}
321
322func EncodeNet(p netip.Prefix) scode.Bytes {
323 return AppendNet(nil, p)

Callers 3

CallMethod · 0.92
appendPrimitiveMethod · 0.92
EncodeNetFunction · 0.85

Calls 1

AddrMethod · 0.80

Tested by

no test coverage detected