mstar.communication.codec#

The encode/decode seam shared by both ZMQ transports.

Kept apart from either communicator so they can both import it, and mirroring the Rust Codec trait:

pub trait Codec<M> {
    fn encode(msg: &M) -> Result<Vec<u8>, CommError>;
    fn decode(bytes: &[u8]) -> Option<M>;
}

The transport never looks inside the bytes, so moving an edge to another encoding is a codec change, never a transport change.

Functions

decode_each(codec, frames, who)

Decode a drained batch one frame at a time.

default_codec()

Select typed msgpack; reject the removed pickle codec at startup.

Classes

Codec()

MsgpackCodec()

Raw msgpack, no schema: for edges whose payloads are already plain dicts and whose other end is not Python — the Rust mstar-server frontend bridge.

WireCodec()

Typed msgpack (mstar.communication.wire): language-neutral and lossless for the message dataclasses.

class mstar.communication.codec.Codec[source]#

Bases: object

static decode(data)[source]#
Parameters:

data (bytes)

static encode(msg)[source]#
Return type:

bytes

class mstar.communication.codec.MsgpackCodec[source]#

Bases: Codec

Raw msgpack, no schema: for edges whose payloads are already plain dicts and whose other end is not Python — the Rust mstar-server frontend bridge. default=str is lossy, so this is NOT a general replacement for pickle; use WireCodec for message dataclasses.

static decode(data)[source]#
Parameters:

data (bytes)

static encode(msg)[source]#
Return type:

bytes

class mstar.communication.codec.WireCodec[source]#

Bases: Codec

Typed msgpack (mstar.communication.wire): language-neutral and lossless for the message dataclasses. The default.

static decode(data)[source]#
Parameters:

data (bytes)

static encode(msg)[source]#
Return type:

bytes

mstar.communication.codec.decode_each(codec, frames, who)[source]#

Decode a drained batch one frame at a time.

A frame that fails to decode is logged and skipped. Raising instead would lose every frame already drained with it – control messages for other requests included – to one bad payload.

Parameters:
Return type:

list

mstar.communication.codec.default_codec()[source]#

Select typed msgpack; reject the removed pickle codec at startup.

Both ends of an edge must agree, so this is all-or-nothing for a mesh — a single process set differently will not be able to talk to its peers.

Return type:

type[Codec]