def serialize(self, msg, ident=None):
content = msg.get('<STR_LIT:content>', {})<EOL>if content is None:<EOL><INDENT>content = self.none<EOL><DEDENT>elif isinstance(content, dict):<EOL><INDENT>content = self.pack(content)<EOL><DEDENT>elif isinstance(content, bytes):<EOL><INDENT>pass<EOL><DEDENT>elif isinstance(content, unicode):<EOL><INDENT>content = content.encode('<STR_LIT:utf8>')<EOL><DEDENT>else:<EOL><INDENT>raise TypeError("<STR_LIT>"%type(content))<EOL><DEDENT>real_message = [self.pack(msg['<STR_LIT>']),<EOL>self.pack(msg['<STR_LIT>']),<EOL>content<EOL>]<EOL>to_send = []<EOL>if isinstance(ident, list):<EOL><INDENT>to_send.extend(ident)<EOL><DEDENT>elif ident is not None:<EOL><INDENT>to_send.append(ident)<EOL><DEDENT>to_send.append(DELIM)<EOL>signature = self.sign(real_message)<EOL>to_send.append(signature)<EOL>to_send.extend(real_message)<EOL>return to_send<EOL>
Serialize the message components to bytes.

        This is roughly the inverse of unserialize. The serialize/unserialize
        methods work with full message lists, whereas pack/unpack work with
        the individual message parts in the message list.

        Parameters
        ----------
        msg : dict or Message
            The nexted message dict as returned by the self.msg method.

        Returns
        -------
        msg_list : list
            The list of bytes objects to be sent with the format:
            [ident1,ident2,...,DELIM,HMAC,p_header,p_parent,p_content,
             buffer1,buffer2,...]. In this list, the p_* entities are
            the packed or serialized versions, so if JSON is used, these
            are utf8 encoded JSON strings.