mirror of
https://github.com/apple/foundationdb.git
synced 2026-01-25 12:28:19 +00:00
* For Java code, provide a `equals` method as the behavior of Java == is different from C++ * For Python code, fix a has_feature bug
104 lines
2.9 KiB
Plaintext
104 lines
2.9 KiB
Plaintext
""" Protocol Version
|
|
|
|
This code is generated by `protocol_version.py`. Do not modify by hand.
|
|
"""
|
|
|
|
|
|
class ProtocolVersion:
|
|
_supported_protocol_versions = set()
|
|
|
|
def __init__(self, version: int):
|
|
self._version = version
|
|
|
|
def __hash__(self):
|
|
return hash(self._version)
|
|
|
|
@property
|
|
def _version_flag_mask(self) -> int:
|
|
return 0x0FFFFFFFFFFFFFFF
|
|
|
|
@property
|
|
def version(self) -> int:
|
|
return self._version & self._version_flag_mask
|
|
|
|
@property
|
|
def compatible_protocol_version_mask(self) -> int:
|
|
return 0xFFFFFFFFFFFF0000;
|
|
|
|
@property
|
|
def normalized_version(self) -> "ProtocolVersion":
|
|
return ProtocolVersion(self.version & self.compatible_protocol_version_mask)
|
|
|
|
def is_compatible(self, other: "ProtocolVersion") -> bool:
|
|
return (other._version & self.compatible_protocol_version_mask) == (self._version & self.compatible_protocol_version_mask)
|
|
|
|
def _cmp_(self, other: "ProtocolVersion"):
|
|
if self.version > other.version:
|
|
return 1
|
|
elif self.version == other.version:
|
|
return 0
|
|
else:
|
|
return -1
|
|
|
|
def __gt__(self, other: "ProtocolVersion"):
|
|
return self._cmp_(other) > 0
|
|
|
|
def __lt__(self, other: "ProtocolVersion"):
|
|
return self._cmp_(other) < 0
|
|
|
|
def __eq__(self, other: "ProtocolVersion"):
|
|
return self._cmp_(other) == 0
|
|
|
|
def __ne__(self, other: "ProtocolVersion"):
|
|
return self._cmp_(other) != 0
|
|
|
|
def __ge__(self, other: "ProtocolVersion"):
|
|
return self._cmp_(other) >= 0
|
|
|
|
def __le__(self, other: "ProtocolVersion"):
|
|
return self._cmp_(other) <= 0
|
|
|
|
def is_supported(self) -> bool:
|
|
return self in ProtocolVersion._supported_protocol_versions
|
|
|
|
{% for version, features in all_features.items() %}
|
|
{% for feature in features %}
|
|
|
|
@property
|
|
def has_{{ feature | feature_name_transformer }}(self) -> bool:
|
|
return self >= ProtocolVersion({{ version | encode_version }})
|
|
|
|
@staticmethod
|
|
def with_{{ feature | feature_name_transformer }}() -> "ProtocolVersion":
|
|
return ProtocolVersion({{ version | encode_version }})
|
|
|
|
{% endfor %}
|
|
{% endfor %}
|
|
|
|
|
|
PROTOCOL_VERSION_5_2 = 0x0FDB00A552000001
|
|
PROTOCOL_VERSION_6_0 = 0x0FDB00A570010001
|
|
PROTOCOL_VERSION_6_1 = 0x0FDB00B061060001
|
|
PROTOCOL_VERSION_6_2 = 0x0FDB00B062010001
|
|
PROTOCOL_VERSION_6_3 = 0x0FDB00B063010001
|
|
PROTOCOL_VERSION_7_0 = 0x0FDB00B070010001
|
|
PROTOCOL_VERSION_7_1 = 0x0FDB00B071010000
|
|
PROTOCOL_VERSION_7_2 = 0x0FDB00B072000000
|
|
PROTOCOL_VERSION_7_3 = 0x0FDB00B073000000
|
|
|
|
def _module_init():
|
|
for raw_version in (
|
|
PROTOCOL_VERSION_5_2,
|
|
PROTOCOL_VERSION_6_0,
|
|
PROTOCOL_VERSION_6_1,
|
|
PROTOCOL_VERSION_6_2,
|
|
PROTOCOL_VERSION_6_3,
|
|
PROTOCOL_VERSION_7_0,
|
|
PROTOCOL_VERSION_7_1,
|
|
PROTOCOL_VERSION_7_2,
|
|
PROTOCOL_VERSION_7_3,
|
|
):
|
|
ProtocolVersion._supported_protocol_versions.add(ProtocolVersion(raw_version))
|
|
|
|
_module_init()
|