Decode a complete message (header + payload). Args: data: Complete message bytes Returns: tuple: (msg_type_str, request_id, payload_dict) msg_type_str is the string name (e.g., "request") payload_dict is the dec
(data: bytes)
| 357 | |
| 358 | @staticmethod |
| 359 | def decode_message(data: bytes) -> tuple: |
| 360 | """ |
| 361 | Decode a complete message (header + payload). |
| 362 | |
| 363 | Args: |
| 364 | data: Complete message bytes |
| 365 | |
| 366 | Returns: |
| 367 | tuple: (msg_type_str, request_id, payload_dict) |
| 368 | msg_type_str is the string name (e.g., "request") |
| 369 | payload_dict is the decoded TLV payload as a dict |
| 370 | |
| 371 | Raises: |
| 372 | DirtyProtocolError: If message is malformed |
| 373 | """ |
| 374 | msg_type, request_id, length = BinaryProtocol.decode_header(data) |
| 375 | |
| 376 | if len(data) < HEADER_SIZE + length: |
| 377 | raise DirtyProtocolError( |
| 378 | f"Incomplete message: expected {HEADER_SIZE + length} bytes, " |
| 379 | f"got {len(data)}", |
| 380 | raw_data=data[:50] |
| 381 | ) |
| 382 | |
| 383 | if length == 0: |
| 384 | # End message has empty payload |
| 385 | payload_dict = {} |
| 386 | else: |
| 387 | payload_data = data[HEADER_SIZE:HEADER_SIZE + length] |
| 388 | try: |
| 389 | payload_dict = TLVEncoder.decode_full(payload_data) |
| 390 | except DirtyProtocolError: |
| 391 | raise |
| 392 | except Exception as e: |
| 393 | raise DirtyProtocolError( |
| 394 | f"Failed to decode TLV payload: {e}", |
| 395 | raw_data=payload_data[:50] |
| 396 | ) |
| 397 | |
| 398 | # Convert to dict format similar to old JSON protocol |
| 399 | msg_type_str = MSG_TYPE_TO_STR[msg_type] |
| 400 | |
| 401 | return msg_type_str, request_id, payload_dict |
| 402 | |
| 403 | # ------------------------------------------------------------------------- |
| 404 | # Async API (primary - for DirtyArbiter and DirtyWorker) |
nothing calls this directly
no test coverage detected