Skip to content

declearn.communication.messaging.parse_message_from_string

DEPRECATED - Instantiate a Message from its serialized string.

This function was DEPRECATED in DecLearn 2.4 and will be removed in v2.6 and/or v3.0. Use the declearn.messaging.SerializedMessage API to parse serialized message strings.

Parameters:

Name Type Description Default
string str

Serialized string dump of the message.

required

Returns:

Name Type Description
message Message

Message instance recovered from the input string.

Raises:

Type Description
KeyError

If the string's typekey does not match any supported Message subclass.

TypeError

If the string cannot be parsed to identify a message typekey.

ValueError

If the serialized data fails to be properly decoded.

Source code in declearn/communication/messaging/_messages.py
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
def parse_message_from_string(
    string: str,
) -> Message:
    """DEPRECATED - Instantiate a Message from its serialized string.

    This function was DEPRECATED in DecLearn 2.4 and will be removed
    in v2.6 and/or v3.0. Use the `declearn.messaging.SerializedMessage`
    API to parse serialized message strings.

    Parameters
    ----------
    string:
        Serialized string dump of the message.

    Returns
    -------
    message:
        Message instance recovered from the input string.

    Raises
    ------
    KeyError
        If the string's typekey does not match any supported Message
        subclass.
    TypeError
        If the string cannot be parsed to identify a message typekey.
    ValueError
        If the serialized data fails to be properly decoded.
    """
    warnings.warn(
        "'parse_message_from_string' was deprecated in DecLearn 2.4, in "
        "favor of using 'declearn.messaging.SerializedMessage' to parse "
        "and deserialize 'Message' instances from strings. It will be "
        "removed in DecLearn version 2.6 and/or 3.0.",
        DeprecationWarning,
    )
    serialized = SerializedMessage.from_message_string(
        string
    )  # type: SerializedMessage[Any]
    return serialized.deserialize()