| 69 | |
| 70 | |
| 71 | class EncodedMetaString: |
| 72 | __slots__ = ("data", "length", "encoding", "hashcode") |
| 73 | |
| 74 | def __init__(self, data: bytes, hashcode: int): |
| 75 | self.data = data |
| 76 | self.length = len(data) |
| 77 | if hashcode >= (1 << 63): |
| 78 | hashcode -= 1 << 64 |
| 79 | elif hashcode < -(1 << 63): |
| 80 | hashcode += 1 << 64 |
| 81 | self.hashcode = hashcode |
| 82 | self.encoding = hashcode & 0xFF |
| 83 | |
| 84 | def decode(self, decoder): |
| 85 | return decoder.decode(self.data, Encoding(self.encoding)) |
| 86 | |
| 87 | def __hash__(self): |
| 88 | return hash((self.hashcode, self.data)) |
| 89 | |
| 90 | def __eq__(self, other): |
| 91 | return type(other) is EncodedMetaString and self.hashcode == other.hashcode and self.data == other.data |
| 92 | |
| 93 | def __repr__(self): |
| 94 | return f"EncodedMetaString(data={self.data}, hashcode={self.hashcode})" |
| 95 | |
| 96 | |
| 97 | EMPTY_ENCODED_META_STRING = EncodedMetaString(b"", 0) |
no outgoing calls