def deconstruct_packet(packet):
        """
        Replaces every bytearray in packet with a numbered placeholder.
        :param packet:
        :return: dict with packet and list of buffers
        """
        buffers = []
        packet_data = packet.get('data', None)

        def _deconstruct_packet(data):
            if type(data) is bytearray:
                place_holder = {
                    '_placeholder': True,
                    'num': len(buffers)
                }

                buffers.append(data)
                return place_holder

            if type(data) is list:
                new_data = []
                for d in data:
                    new_data.append(_deconstruct_packet(d))

                return new_data

            if type(data) is dict:
                new_data = {}

                for k, v in data.items():
                    new_data[k] = _deconstruct_packet(v)

                return new_data

            return data

        pack = copy.copy(packet)
        pack['data'] = _deconstruct_packet(packet_data)
        pack['attachments'] = len(buffers)

        return {
            'packet': pack,
            'buffers': buffers
        }