Skip to content
Open
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
13 changes: 8 additions & 5 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ classifiers = [

[tool.poetry.dependencies]
python = ">=3.7,<4.0"
construct = "2.8.8"
construct = "2.10.68"

[tool.poetry.group.dev.dependencies]
coverage = { version="^7.2.3", extras=["toml"] }
Expand Down
38 changes: 38 additions & 0 deletions src/pymp4/adapters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from __future__ import annotations

from abc import ABC
from uuid import UUID

from construct import Adapter, int2byte


class ISO6392TLanguageCode(Adapter, ABC):
def _decode(self, obj, context, path):
return "".join([
chr(bit + 0x60)
for bit in (
(obj >> 10) & 0b11111,
(obj >> 5) & 0b11111,
obj & 0b11111
)
])

def _encode(self, obj, context, path):
bits = [ord(c) - 0x60 for c in obj]
return (bits[0] << 10) | (bits[1] << 5) | bits[2]


class MaskedInteger(Adapter, ABC):
def _decode(self, obj, context, path):
return obj & 0x1F

def _encode(self, obj, context, path):
return obj & 0x1F


class UUIDBytes(Adapter, ABC):
def _decode(self, obj, context, path):
return UUID(bytes=obj)

def _encode(self, obj, context, path):
return obj.bytes
Loading