How to use the msgpack.Packer function in msgpack

To help you get started, we’ve selected a few msgpack examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nuclio / nuclio / pkg / processor / runtime / python / py / test_wrapper.py View on Github external
def _send_event(self, event):
        if not isinstance(event, dict):
            event = self._event_to_dict(event)

        # event to a msgpack body message
        body = msgpack.Packer().pack(event)

        # big endian body len
        body_len = struct.pack(">I", len(body))

        # first write body length
        self._unix_stream_server._connection_socket.sendall(body_len)

        # then write body content
        self._unix_stream_server._connection_socket.sendall(body)
github jakm / txmsgpackrpc / tests / test_protocol.py View on Github external
def setUp(self):
        factory = EchoServerFactory(True)
        self.proto = factory.buildProtocol(("127.0.0.1", 0))
        self.transport = proto_helpers.StringTransport()
        self.proto.makeConnection(self.transport)
        self.packer = msgpack.Packer(encoding="utf-8")
github msgpack / msgpack-python / test / test_pack.py View on Github external
def testPackUnicode():
    test_data = ["", "abcd", ["defgh"], "Русский текст"]
    for td in test_data:
        re = unpackb(packb(td), use_list=1, raw=False)
        assert re == td
        packer = Packer()
        data = packer.pack(td)
        re = Unpacker(BytesIO(data), raw=False, use_list=1).unpack()
        assert re == td
github marcusklang / docria / py / docria / storage.py View on Github external
def __init__(self, outputio: RawIOBase, num_docs_per_block=128, codec=get_codec("zip"), **kwargs):
        """
        Primary constructor

        :param outputio: the underlying I/O device to write to.
        :param num_docs_per_block: the number of documents to cache before
                                   compressing the entire block and write to underlying storage.
        :param codec: the compression codec to use for blocks
        """
        self.outputio = outputio
        self.packer = Packer(use_bin_type=True)

        self.outputio.write(b"Dmf1")
        self.outputio.write(self.packer.pack(codec.name))
        self.outputio.write(self.packer.pack(num_docs_per_block))
        self.outputio.write(self.packer.pack(False))

        if isinstance(self.outputio, _BoundaryWriter):
            self.outputio.split()

        self.currentblock = BytesIO()
        self.current_block_count = 0
        self.codec_name = codec.name
        self.codec = codec.compress  # type: Callable[[bytes], bytes]
        self.num_docs_per_block = num_docs_per_block
github treasure-data / pandas-td / pandas_td / td.py View on Github external
def _pack(self, chunk):
        packer = msgpack.Packer(autoreset=False)
        for _, row in chunk.iterrows():
            # row.dtype can be non-object (such as numpy.int64 or numpy.float64)
            # when column types are homogeneous.  In this case, packer.pack raises
            # an exception because it doesn't know how to encode those data types.
            if row.dtype.name != 'object':
                row = row.astype('object')
            row.dropna(inplace=True)
            packer.pack(dict(row))
        return packer.bytes()
github spotify / crtauth / crtauth / msgpack_protocol.py View on Github external
def __init__(self, data_type, size=None, binary=False):
        self._data_type = data_type
        self._size = size
        self._packer = msgpack.Packer(use_bin_type=binary)
github guyingbo / cowfish / cowfish / kinesis.py View on Github external
def __init__(self, *args, **kw):
        import msgpack

        super().__init__(*args, **kw)
        self.buffer = bytearray()
        self.packer = msgpack.Packer()
        self.bufmax = 1024 * 25
github psychopy / psychopy / psychopy / app / _psychopyApp.py View on Github external
Use this when force quiting the experiment script process so iohub
        knows to exit as well.

        If message is not sent within 1 second, or the iohub server
        address in incorrect,the issue is logged.
        """
        sock = None
        try:
            logging.debug('PsychoPyApp: terminateHubProcess called.')
            import socket
            sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
            sock.settimeout(1.0)
            iohub_address = '127.0.0.1', 9034
            import msgpack
            tx_data = msgpack.Packer().pack(('STOP_IOHUB_SERVER',))
            return sock.sendto(tx_data, iohub_address)
        except socket.error as e:
            msg = 'PsychoPyApp: terminateHubProcess socket.error: %s'
            logging.debug(msg % str(e))
        except socket.herror as e:
            msg = 'PsychoPyApp: terminateHubProcess socket.herror: %s'
            logging.debug(msg % str(e))
        except socket.gaierror as e:
            msg = 'PsychoPyApp: terminateHubProcess socket.gaierror: %s'
            logging.debug(msg % str(e))
        except socket.timeout as e:
            msg = 'PsychoPyApp: terminateHubProcess socket.timeout: %s'
            logging.debug(msg % str(e))
        except Exception as e:
            msg = 'PsychoPyApp: terminateHubProcess exception: %s'
            logging.debug(msg % str(e))
github psychopy / psychopy / psychopy / iohub / net.py View on Github external
def __init__(self,local_host=None,local_port=None,remote_host=None,remote_port=None,rcvBufferLength=1492, broadcast=False, blocking=0, timeout=0):
        self._local_port= local_port
        self._local_host = local_host
        self._remote_host= remote_host
        self._remote_port = remote_port
        self._rcvBufferLength=rcvBufferLength
        self.lastAddress=None
        self.sock=None
        self.initSocket(broadcast,blocking, timeout)

        self.coder=msgpack
        self.packer=msgpack.Packer()
        self.unpacker=msgpack.Unpacker(use_list=True)
        self.pack=self.packer.pack
        self.feed=self.unpacker.feed
        self.unpack=self.unpacker.unpack
github neovim / pynvim / neovim / msgpack_stream.py View on Github external
def __init__(self, stream):
        def default(obj):
            return obj._handle

        def ext_hook(code, data):
            klass = self.types[code]
            rv = klass(self.vim, msgpack.ExtType(code, data))
            klass.initialize(rv)
            return rv

        self.types = None
        self.vim = None
        self.packer = msgpack.Packer(use_bin_type=True, default=default)
        self.unpacker = msgpack.Unpacker(ext_hook=ext_hook)
        self.stream = stream