# Path: pq/utils/serializers.py
# def serializer(cls):
#     def __new__(cls, name, bases, attrs):
#     def consumer(cls):
#     def get(self, name):
#     def tojson(self):
#     def __init__(self, *args, **kwargs):
#     def decode(cls, data):
#     def encode(cls, message):
#         def decode(cls, data):
#         def encode(cls, message):
# def queue_message(d, type=None):
#     def default(self, o):
# def as_message(o):
# class MessageMetaClass(type):
# class Message(metaclass=MessageMetaClass):
# class MessageDict(Message):
# class Json:
#     class MsgPack:
# class JSONEncoder(json.JSONEncoder):


from abc import ABC, abstractmethod
from asyncio import Future, ensure_future
from collections import OrderedDict
from pulsar.api import chain_future, ImproperlyConfigured
from pulsar.apps.http import HttpClient
from pulsar.apps.greenio import GreenPool
from pulsar.apps.data.channels import Connector
from pulsar.utils.importer import module_attribute
from .utils.serializers import serializers


async def _wait(task_future):
    await task_future.backend.channels.connect()
    result = await task_future
    return result


class BaseComponent:

    def __init__(self, backend):
        self.backend = backend
        self.logger = self.backend.logger

    @property
    def cfg(self):
        return self.backend.cfg

    @property
    def _loop(self):
        return self.backend._loop

    def encode(self, message, serializer=None):
        """Encode a message"""
        serializer = serializer or self.cfg.message_serializer
        return serializers[serializer].encode(message)

    def decode(self, data, serializer=None):
        """Decode a message"""
        serializer = serializer or self.cfg.message_serializer

# Path: pq/utils/serializers.py
# def serializer(cls):
#     def __new__(cls, name, bases, attrs):
#     def consumer(cls):
#     def get(self, name):
#     def tojson(self):
#     def __init__(self, *args, **kwargs):
#     def decode(cls, data):
#     def encode(cls, message):
#         def decode(cls, data):
#         def encode(cls, message):
# def queue_message(d, type=None):
#     def default(self, o):
# def as_message(o):
# class MessageMetaClass(type):
# class Message(metaclass=MessageMetaClass):
# class MessageDict(Message):
# class Json:
#     class MsgPack:
# class JSONEncoder(json.JSONEncoder):


# Path: pq/mq.py
from abc import ABC, abstractmethod
from asyncio import Future, ensure_future
from collections import OrderedDict
from pulsar.api import chain_future, ImproperlyConfigured
from pulsar.apps.http import HttpClient
from pulsar.apps.greenio import GreenPool
from pulsar.apps.data.channels import Connector
from pulsar.utils.importer import module_attribute
from .utils.serializers import serializers



async def _wait(task_future):
    await task_future.backend.channels.connect()
    result = await task_future
    return result


class BaseComponent:

    def __init__(self, backend):
        self.backend = backend
        self.logger = self.backend.logger

    @property
    def cfg(self):
        return self.backend.cfg

    @property
    def _loop(self):
        return self.backend._loop

    def encode(self, message, serializer=None):
        """Encode a message"""
        serializer = serializer or self.cfg.message_serializer
        return serializers[serializer].encode(message)

    def decode(self, data, serializer=None):
        """Decode a message"""
        serializer = serializer or self.cfg.message_serializer

        return serializers[serializer].decode(data)