import pickle


def message_decode(encoded_msg, lazy=False):
    """
    Decodes the message object.

    This method deserializes the pickled message, and decodes the message
    payload if 'lazy' is False.

    Args:
        encoded_msg: the message to decode.
        lazy: if this is True, then the payload will only be decoded once it's
        accessed.
    """
    msg = pickle.loads(encoded_msg)
    if not lazy:
        msg.payload.decode()
    return msg