MCPcopy
hub / github.com/osrg/gobgp / addrPrefixOnlySerialize

Function addrPrefixOnlySerialize

internal/pkg/table/table.go:38–57  ·  view source on GitHub ↗
(nlri bgp.NLRI)

Source from the content-addressed store, hash-verified

36)
37
38func addrPrefixOnlySerialize(nlri bgp.NLRI) []byte {
39 switch T := nlri.(type) {
40 case *bgp.IPAddrPrefix:
41 byteLen := T.Prefix.Addr().BitLen() / 8
42 b := make([]byte, byteLen+1)
43 copy(b, T.Prefix.Addr().AsSlice())
44 b[byteLen] = uint8(T.Prefix.Bits())
45 return b
46 case *bgp.LabeledVPNIPAddrPrefix:
47 byteLen := T.Prefix.Addr().BitLen() / 8
48 // RD and length
49 b := make([]byte, byteLen+9)
50 serializedRD, _ := T.RD.Serialize()
51 copy(b, serializedRD)
52 copy(b[8:], T.Prefix.Addr().AsSlice())
53 b[8+byteLen] = uint8(T.Prefix.Bits())
54 return b
55 }
56 return []byte(nlri.String())
57}
58
59func AddrPrefixOnlyCompare(a, b bgp.NLRI) int {
60 return bytes.Compare(addrPrefixOnlySerialize(a), addrPrefixOnlySerialize(b))

Callers 1

AddrPrefixOnlyCompareFunction · 0.85

Calls 3

AddrMethod · 0.80
SerializeMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…