def dump_msg()

in src/rosbridge/zmq_serialize.py [0:0]


def dump_msg(msg):
    """
    Turn o into a list of binary strings suitable for sending over zmq.
    This is less general than Pickle, but it's:
        - High-performance
        - Language-neutral. Should be straightforward to read & write from JS or C++
        - Supports Gym objects like subtypes of gym.Space
        - Can be handed untrusted data without creating a remote execution risk
    It returns a list parts, where:
      - parts[0] is a JSON-formatted representation of msg, with some replacements as detailed below.
      - parts[1...] encode bulk data structures like numpy arrays in binary.
    The following replacements are made:
      - numpy arrays are replaced by a description (element type & shape) and reference to the binary
        data stored in parts
      - Numeric inf is sent as {"__type":"number","value":"inf"}
      - Spaces (Box, Tuple, Discrete) are send encoded something like {"__type":"Box","low"=...,"high"=...}
      - tuples and objects are wrapped with a {"__type":"tuple", ...} and {"__type":"object", ...}
    """
    parts = [None]
    msg1 = _dump_msg1(msg, parts)
    parts[0] = ujson.dumps(msg1, escape_forward_slashes=False)
    return parts