# Path: zircon/transformers/common.py
# class Pickler(Transformer):
#     """ Pickle messages with the latest protocol.
#     """
#     def push(self, msg):
#         serialized_msg = pickle.dumps(msg)
#         from pympler.asizeof import asizeof
#         print('unpickled: {}, pickled: {}'.format(
#             asizeof(msg),
#             asizeof(serialized_msg)
#         ))
#         self.output(serialized_msg)
# 
# Path: zircon/publishers/zeromq.py
# class ZMQPublisher(BasePublisher):
# 
#     def __init__(self, host='*', port=8811, zmq_type=zmq.PUB):
# 
#         self.host = host
#         self.port = port
#         self.zmq_type = zmq_type
#         self.URI = 'tcp://{}:{}'.format(self.host, self.port)
# 
#         self.context = zmq.Context()
#         self.sock = self.context.socket(self.zmq_type)
# 
#         self.count = 0
# 
#     def open(self):
#         self.sock.bind(self.URI)
#         return True
# 
#     def close(self):
#         self.sock.close()
#         return True
# 
#     def send(self, msg):
# 
#         try:
#             self.sock.send(msg)
#             self.count += 1
#             print('[SENT] {}'.format(self.count))
#         except TypeError:
#             print('[ERROR] Message fed to Publisher must be serialized!')
#             return False
# 
#         return True


from zircon.transformers.common import Pickler
from zircon.publishers.zeromq import ZMQPublisher
    When creating a Reporter, you supply instances of a Transceiver,
    one or more Transformers, and a Publisher. If not specified,
    a pickling Transformer and the default Publisher are used.

    **Usage**::

        reporter = Reporter(
            transceiver=MyTransceiver(),
            transformers=[MyDecoder(), MyCompressor(), ...],
            publisher=MyPublisher()
        )

    A Reporter can be run as its own process::

        reporter.run()

    Or stepped through by an external engine::

        reporter.open()
        while not done:
            reporter.step()
    """

    def __init__(self, transceiver, transformers=None, publisher=None):

        self.transceiver = transceiver

        if transformers:
            self.transformers = transformers
        else:

# Path: zircon/transformers/common.py
# class Pickler(Transformer):
#     """ Pickle messages with the latest protocol.
#     """
#     def push(self, msg):
#         serialized_msg = pickle.dumps(msg)
#         from pympler.asizeof import asizeof
#         print('unpickled: {}, pickled: {}'.format(
#             asizeof(msg),
#             asizeof(serialized_msg)
#         ))
#         self.output(serialized_msg)
# 
# Path: zircon/publishers/zeromq.py
# class ZMQPublisher(BasePublisher):
# 
#     def __init__(self, host='*', port=8811, zmq_type=zmq.PUB):
# 
#         self.host = host
#         self.port = port
#         self.zmq_type = zmq_type
#         self.URI = 'tcp://{}:{}'.format(self.host, self.port)
# 
#         self.context = zmq.Context()
#         self.sock = self.context.socket(self.zmq_type)
# 
#         self.count = 0
# 
#     def open(self):
#         self.sock.bind(self.URI)
#         return True
# 
#     def close(self):
#         self.sock.close()
#         return True
# 
#     def send(self, msg):
# 
#         try:
#             self.sock.send(msg)
#             self.count += 1
#             print('[SENT] {}'.format(self.count))
#         except TypeError:
#             print('[ERROR] Message fed to Publisher must be serialized!')
#             return False
# 
#         return True


# Path: zircon/reporters/base.py
from zircon.transformers.common import Pickler
from zircon.publishers.zeromq import ZMQPublisher

    When creating a Reporter, you supply instances of a Transceiver,
    one or more Transformers, and a Publisher. If not specified,
    a pickling Transformer and the default Publisher are used.

    **Usage**::

        reporter = Reporter(
            transceiver=MyTransceiver(),
            transformers=[MyDecoder(), MyCompressor(), ...],
            publisher=MyPublisher()
        )

    A Reporter can be run as its own process::

        reporter.run()

    Or stepped through by an external engine::

        reporter.open()
        while not done:
            reporter.step()
    """

    def __init__(self, transceiver, transformers=None, publisher=None):

        self.transceiver = transceiver

        if transformers:
            self.transformers = transformers
        else:

            self.transformers = [Pickler()]