rings: introduce ring-specific decoders
Signed-off-by: Alejandro Mery <amery@jpi.io>
This commit is contained in:
@@ -72,3 +72,51 @@ func unsafeDecodeAddress[T ~uint | NodeID](a, b, c, d byte) (RingID, RegionID, Z
|
||||
return k, r, 0, n
|
||||
}
|
||||
}
|
||||
|
||||
// DecodeRingZeroAddress attempts to extract region, zone and node identifiers
|
||||
// from a given ring 0 address.
|
||||
//
|
||||
// revive:disable:function-result-limit
|
||||
func DecodeRingZeroAddress(addr netip.Addr) (RegionID, ZoneID, NodeID, bool) {
|
||||
// revive:enable:function-result-limit
|
||||
k, r, z, n := DecodeAddress[NodeID](addr)
|
||||
if k == RingZeroID {
|
||||
return r, z, n, true
|
||||
}
|
||||
|
||||
return 0, 0, 0, false
|
||||
}
|
||||
|
||||
// DecodeRingOneAddress attempts to extract region, zone and node identifiers
|
||||
// from a given ring 1 address.
|
||||
//
|
||||
// revive:disable:function-result-limit
|
||||
func DecodeRingOneAddress(addr netip.Addr) (RegionID, ZoneID, NodeID, bool) {
|
||||
// revive:enable:function-result-limit
|
||||
k, r, z, n := DecodeAddress[NodeID](addr)
|
||||
if k == RingOneID {
|
||||
return r, z, n, true
|
||||
}
|
||||
|
||||
return 0, 0, 0, false
|
||||
}
|
||||
|
||||
// DecodeRingTwoAddress attempts to extract region and unique identifier for
|
||||
// a kubernetes service from a given ring 2 address.
|
||||
func DecodeRingTwoAddress(addr netip.Addr) (RegionID, uint, bool) {
|
||||
k, r, _, n := DecodeAddress[uint](addr)
|
||||
if k == RingTwoID {
|
||||
return r, n, true
|
||||
}
|
||||
return 0, 0, false
|
||||
}
|
||||
|
||||
// DecodeRingThreeAddress attempts to extract region and unique identifier for
|
||||
// a kubernetes pod from a given ring 3 address.
|
||||
func DecodeRingThreeAddress(addr netip.Addr) (RegionID, uint, bool) {
|
||||
k, r, _, n := DecodeAddress[uint](addr)
|
||||
if k == RingThreeID {
|
||||
return r, n, true
|
||||
}
|
||||
return 0, 0, false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user