diff --git a/python/pycrdt/doc.py b/python/pycrdt/doc.py index 1198723..6a86c69 100644 --- a/python/pycrdt/doc.py +++ b/python/pycrdt/doc.py @@ -23,7 +23,7 @@ def get_state(self) -> bytes: def get_update(self, state: bytes | None = None) -> bytes: if state is None: - state = self.get_state() + state = b"\x00" return self._doc.get_update(state) def apply_update(self, update: bytes) -> None: diff --git a/tests/test_doc.py b/tests/test_doc.py index 3ad7979..49eb905 100644 --- a/tests/test_doc.py +++ b/tests/test_doc.py @@ -7,6 +7,17 @@ def callback(events, event): events.append(event) +def encode_client_id(client_id_bytes): + client_id_len = len(client_id_bytes) + b = [] + for i, n in enumerate(client_id_bytes[::-1]): + j = n << i + if i != client_id_len - 1: + j |= 0x80 + b.append(j) + return bytes(b) + + def test_subdoc(): doc0 = Doc() state0 = doc0.get_state() @@ -80,5 +91,14 @@ def test_client_id(): doc1 = Doc() assert doc0.client_id != doc1.client_id - doc2 = Doc(client_id=123) - assert doc2.client_id == 123 + client_id_bytes = b"\x01\x02\x03\x04" + client_id = int.from_bytes(client_id_bytes, byteorder="big") + doc2 = Doc(client_id=client_id) + assert doc2.client_id == client_id + text = Text("Hello, World!") + doc2["text"] = text + update = doc2.get_update() + + b = encode_client_id(client_id_bytes) + + assert update[2 : 2 + len(b)] == b