# Path: pycoinnet/message.py
# def parse_from_data(message_name, data):
#     message_stream = io.BytesIO(data)
#     parser = MESSAGE_PARSERS.get(message_name)
#     if parser:
#         d = parser(message_stream)
#         fixup = MESSAGE_FIXUPS.get(message_name)
#         if fixup:
#             d = fixup(d, message_stream)
#     else:
#         logging.error("unknown message: %s %s", message_name, binascii.hexlify(data))
#         d = {}
#     return d
# 
# def pack_from_data(message_name, **kwargs):
#     the_struct = MESSAGE_STRUCTURES[message_name]
#     if not the_struct:
#         return b''
#     f = io.BytesIO()
#     the_fields = the_struct.split(" ")
#     pairs = [t.split(":") for t in the_fields]
#     for name, type in pairs:
#         if type[0] == '[':
#             bitcoin_streamer.BITCOIN_STREAMER.stream_struct("I", f, len(kwargs[name]))
#             for v in kwargs[name]:
#                 if not isinstance(v, (tuple, list)):
#                     v = [v]
#                 bitcoin_streamer.BITCOIN_STREAMER.stream_struct(type[1:-1], f, *v)
#         else:
#             bitcoin_streamer.BITCOIN_STREAMER.stream_struct(type, f, kwargs[name])
#     return f.getvalue()


import asyncio
import binascii
import logging
import struct
import time
import weakref
from pycoin import encoding
from pycoinnet.message import parse_from_data, pack_from_data
        q.filter_f = filter_f
        self.message_queues.add(q)

        @asyncio.coroutine
        def get_next_message():
            msg_name, data = yield from q.get()
            if msg_name is None:
                raise EOFError
            return msg_name, data

        if self._run_handle:
            if self._run_handle.done():
                q.put_nowait((None, None))
        else:
            self._run_handle = asyncio.Task(run(self))
        return get_next_message

    def add_task(self, task):
        """
        Some Task objects are associated with the peer. This method
        gives an easy way to keep a strong reference to a Task that won't
        disappear until the peer does.
        """
        try:
            self._tasks.add(asyncio.ensure_future(task))
        except AttributeError:
            # compatibility for very old versions of python 3
            self._tasks.add(getattr(asyncio, 'async')(task))

    def send_msg(self, message_name, **kwargs):

# Path: pycoinnet/message.py
# def parse_from_data(message_name, data):
#     message_stream = io.BytesIO(data)
#     parser = MESSAGE_PARSERS.get(message_name)
#     if parser:
#         d = parser(message_stream)
#         fixup = MESSAGE_FIXUPS.get(message_name)
#         if fixup:
#             d = fixup(d, message_stream)
#     else:
#         logging.error("unknown message: %s %s", message_name, binascii.hexlify(data))
#         d = {}
#     return d
# 
# def pack_from_data(message_name, **kwargs):
#     the_struct = MESSAGE_STRUCTURES[message_name]
#     if not the_struct:
#         return b''
#     f = io.BytesIO()
#     the_fields = the_struct.split(" ")
#     pairs = [t.split(":") for t in the_fields]
#     for name, type in pairs:
#         if type[0] == '[':
#             bitcoin_streamer.BITCOIN_STREAMER.stream_struct("I", f, len(kwargs[name]))
#             for v in kwargs[name]:
#                 if not isinstance(v, (tuple, list)):
#                     v = [v]
#                 bitcoin_streamer.BITCOIN_STREAMER.stream_struct(type[1:-1], f, *v)
#         else:
#             bitcoin_streamer.BITCOIN_STREAMER.stream_struct(type, f, kwargs[name])
#     return f.getvalue()


# Path: pycoinnet/peer/BitcoinPeerProtocol.py
import asyncio
import binascii
import logging
import struct
import time
import weakref
from pycoin import encoding
from pycoinnet.message import parse_from_data, pack_from_data

        q.filter_f = filter_f
        self.message_queues.add(q)

        @asyncio.coroutine
        def get_next_message():
            msg_name, data = yield from q.get()
            if msg_name is None:
                raise EOFError
            return msg_name, data

        if self._run_handle:
            if self._run_handle.done():
                q.put_nowait((None, None))
        else:
            self._run_handle = asyncio.Task(run(self))
        return get_next_message

    def add_task(self, task):
        """
        Some Task objects are associated with the peer. This method
        gives an easy way to keep a strong reference to a Task that won't
        disappear until the peer does.
        """
        try:
            self._tasks.add(asyncio.ensure_future(task))
        except AttributeError:
            # compatibility for very old versions of python 3
            self._tasks.add(getattr(asyncio, 'async')(task))

    def send_msg(self, message_name, **kwargs):

        message_data = pack_from_data(message_name, **kwargs)