Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions marine/marine.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ def _load_marine_packet(cls, field):
def _load_child_fields(cls, children):
child_fields = {}
for child in children.data[: children.len]:
name = child.name.decode("utf-8")
name = cls._safe_decode(child.name)
value = cls._load_marine_packet(child)
child_fields[name] = value
return child_fields
Expand All @@ -359,14 +359,21 @@ def _load_field_value(cls, value):
elif value_type == MarinePacketFieldValueType.BOOL:
return bool(value.bool_value)
elif value_type == MarinePacketFieldValueType.STR:
return value.str_value.decode("utf-8")
return cls._safe_decode(value.str_value)
elif value_type == MarinePacketFieldValueType.BYTES:
return value.str_value[:value_len]
elif value_type == MarinePacketFieldValueType.LIST:
return [cls._load_field_value(v) for v in value.list_value[:value_len]]
else:
raise ValueError(f"Unknown value type {value_type}")

@staticmethod
def _safe_decode(raw_value: bytes) -> str:
try:
return raw_value.decode("utf-8")
except UnicodeDecodeError:
return raw_value.hex()

def _add_or_get_filter(
self,
bpf: Optional[bytes] = None,
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name="marine",
version="3.1.0",
version="3.1.1",
description="Python client for Marine",
url="https://github.com/tomlegkov/marine-python",
author="Tom Legkov",
Expand Down