Respond to RFCs in PR #2767.

pull/2767/head
Kieran Prasch 2021-09-22 21:11:06 -07:00
parent 68df8897a5
commit 887916b31d
1 changed files with 5 additions and 4 deletions

View File

@ -55,16 +55,17 @@ class Versioned(ABC):
if version_number == cls._version():
return cls._from_bytes_current(remainder)
handlers = cls._old_version_handlers()
try:
return handlers[version_number](remainder) # process
except KeyError:
raise ValueError(f"Incorrect or unknown version number ({version_number}).")
return handlers[version_number](remainder) # process
def __bytes__(self):
return self._header() + self._payload()
@classmethod
def _header(cls) -> bytes:
if len(cls._brand()) != cls._BRAND_LENGTH:
raise cls.InvalidHeader("Brand must be exactly two bytes.")
if not cls._brand().isalpha():
raise cls.InvalidHeader("Brand must be alphanumeric.")
version_bytes = cls._version().to_bytes(cls._VERSION_LENGTH, 'big')
return cls._brand() + version_bytes