Decode a complete TLV-encoded value, ensuring all data is consumed. Args: data: Binary data to decode Returns: Decoded Python value Raises: DirtyProtocolError: If data is malformed or has trailing bytes
(data: bytes)
| 282 | |
| 283 | @staticmethod |
| 284 | def decode_full(data: bytes): |
| 285 | """ |
| 286 | Decode a complete TLV-encoded value, ensuring all data is consumed. |
| 287 | |
| 288 | Args: |
| 289 | data: Binary data to decode |
| 290 | |
| 291 | Returns: |
| 292 | Decoded Python value |
| 293 | |
| 294 | Raises: |
| 295 | DirtyProtocolError: If data is malformed or has trailing bytes |
| 296 | """ |
| 297 | value, offset = TLVEncoder.decode(data, 0) |
| 298 | if offset != len(data): |
| 299 | raise DirtyProtocolError( |
| 300 | f"Trailing data after TLV: {len(data) - offset} bytes", |
| 301 | raw_data=data[offset:offset + 20] |
| 302 | ) |
| 303 | return value |