Skip to content

Commit ba9fcab

Browse files
Copilotgonzalocasas
andcommitted
Remove duplicate MessageCodec and move import to top
- Removed duplicate MessageCodec class from core.py (only in codecs.py now) - Moved JsonMessageCodec import to top of core.py to avoid lazy import - Updated __init__.py to import MessageCodec from codecs module - Simplified Transport.__init__ to use `codec or JsonMessageCodec()` Co-authored-by: gonzalocasas <[email protected]>
1 parent 36a0af7 commit ba9fcab

File tree

2 files changed

+4
-48
lines changed

2 files changed

+4
-48
lines changed

src/compas_eve/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,10 @@
4646
EchoSubscriber,
4747
Transport,
4848
Topic,
49-
MessageCodec,
5049
get_default_transport,
5150
set_default_transport,
5251
)
53-
from .codecs import JsonMessageCodec
52+
from .codecs import MessageCodec, JsonMessageCodec
5453
from .memory import InMemoryTransport
5554

5655
HERE = os.path.dirname(__file__)

src/compas_eve/core.py

Lines changed: 3 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,6 @@
1-
DEFAULT_TRANSPORT = None
2-
3-
4-
class MessageCodec(object):
5-
"""Abstract base class for message codecs.
6-
7-
A codec is responsible for encoding and decoding messages
8-
to/from a specific representation format (e.g., JSON, Protocol Buffers).
9-
"""
10-
11-
def encode(self, message):
12-
"""Encode a message to the codec's representation format.
13-
14-
Parameters
15-
----------
16-
message : :class:`Message` or dict or object
17-
Message to encode. Can be a Message instance, a dict, or
18-
an object implementing the COMPAS data framework.
19-
20-
Returns
21-
-------
22-
bytes or str
23-
Encoded representation of the message.
24-
"""
25-
raise NotImplementedError("Subclasses must implement encode()")
26-
27-
def decode(self, encoded_data, message_type):
28-
"""Decode data from the codec's representation format.
29-
30-
Parameters
31-
----------
32-
encoded_data : bytes or str
33-
Encoded data to decode.
34-
message_type : type
35-
The message type class to use for parsing.
1+
from compas_eve.codecs import JsonMessageCodec
362

37-
Returns
38-
-------
39-
:class:`Message`
40-
Decoded message object.
41-
"""
42-
raise NotImplementedError("Subclasses must implement decode()")
3+
DEFAULT_TRANSPORT = None
434

445

456
def get_default_transport():
@@ -80,11 +41,7 @@ class Transport(object):
8041
def __init__(self, codec=None, *args, **kwargs):
8142
super(Transport, self).__init__(*args, **kwargs)
8243
self._id_counter = 0
83-
if codec is None:
84-
from compas_eve.codecs import JsonMessageCodec
85-
86-
codec = JsonMessageCodec()
87-
self.codec = codec
44+
self.codec = codec or JsonMessageCodec()
8845

8946
@property
9047
def id_counter(self):

0 commit comments

Comments
 (0)