def serialize(self, msg, cid=None):
        try:
            if has_binary(msg):
                return bson.BSON.encode(msg)
            else:    
                return json.dumps(msg)
        except:
            if cid is not None:
                # Only bother sending the log message if there's an id
                self.log("error", "Unable to serialize %s message to client"
                         % msg["op"], cid)
            return None
Turns a dictionary of values into the appropriate wire-level
dataset/ETHPy150Open RobotWebTools/rosbridge_suite/rosbridge_library/src/rosbridge_library/protocol.py/Protocol.serialize