diff --git a/src/dbus_fast/_private/marshaller.pxd b/src/dbus_fast/_private/marshaller.pxd index f94c95d..54b23ea 100644 --- a/src/dbus_fast/_private/marshaller.pxd +++ b/src/dbus_fast/_private/marshaller.pxd @@ -33,14 +33,14 @@ cdef class Marshaller: ) cdef unsigned int _write_boolean(self, object boolean) - cpdef write_string(self, str value, object _type) + cpdef write_string(self, object value, object _type) @cython.locals( value_len=cython.uint, signature_len=cython.uint, written=cython.uint, ) - cdef unsigned int _write_string(self, str value) + cdef unsigned int _write_string(self, object value) @cython.locals( signature_len=cython.uint, diff --git a/src/dbus_fast/_private/marshaller.py b/src/dbus_fast/_private/marshaller.py index cdf45b2..9a9bff8 100644 --- a/src/dbus_fast/_private/marshaller.py +++ b/src/dbus_fast/_private/marshaller.py @@ -179,18 +179,18 @@ class Marshaller: def _marshall(self) -> bytearray: """Marshalls the body into a byte array""" try: - self._construct_buffer() + return self._construct_buffer() except KeyError as ex: raise NotImplementedError(f'type is not implemented yet: "{ex.args}"') except error: self.signature_tree.verify(self.body) - return self._buf - def _construct_buffer(self) -> None: + def _construct_buffer(self) -> bytearray: self._buf.clear() body = self.body for i, type_ in enumerate(self.signature_tree.types): self._write_single(type_, body[i]) + return self._buf _writers: Dict[ str, diff --git a/tests/test_marshaller.py b/tests/test_marshaller.py index c2af741..290f5f3 100644 --- a/tests/test_marshaller.py +++ b/tests/test_marshaller.py @@ -1,8 +1,8 @@ import io import json import os +from enum import Enum from typing import Any, Dict -from unittest.mock import patch import pytest @@ -566,3 +566,24 @@ def test_unmarshall_big_endian_message(): message = unmarshaller.message unpacked = unpack_variants(message.body) assert unpacked == [42, "zip", "Trusted", True] + + +class RaucState(str, Enum): + """Rauc slot states.""" + + GOOD = "good" + BAD = "bad" + ACTIVE = "active" + + +def test_marshalling_enum(): + """Test marshalling an enum.""" + msg = Message( + path="/test", + member="test", + signature="s", + body=[RaucState.GOOD], + ) + marshalled = msg._marshall(False) + unmarshalled_msg = Unmarshaller(io.BytesIO(marshalled)).unmarshall() + assert unpack_variants(unmarshalled_msg.body)[0] == RaucState.GOOD.value