# Path: opendiamond/rpc.py
# class RPCError(Exception):
#     '''Base class for RPC error codes.'''
#     code = None
# 
#     # pylint doesn't know about __subclasses__
#     # pylint: disable=no-member
#     @classmethod
#     def get_class(cls, code):
#         '''Return the error subclass for the specified code.'''
#         for c in cls.__subclasses__():
#             if c.code == code:
#                 return c
#             try:
#                 return c.get_class(code)
#             except KeyError:
#                 pass
#         raise KeyError('Error code %d' % code)
#     # pylint: enable=no-member
# 
# Path: opendiamond/xdr.py
# class XDR(object):
#     '''Class containing static factory functions for XDR type handlers.'''
#     def __init__(self):
#         raise RuntimeError('Class cannot be instantiated')
# 
#     @staticmethod
#     def int():
#         return _XDRPrimitiveHandler('int')
# 
#     @staticmethod
#     def uint():
#         return _XDRPrimitiveHandler('uint')
# 
#     @staticmethod
#     def hyper():
#         return _XDRPrimitiveHandler('hyper')
# 
#     @staticmethod
#     def double():
#         return _XDRPrimitiveHandler('double')
# 
#     @staticmethod
#     def string():
#         return _XDRStringHandler()
# 
#     @staticmethod
#     def opaque():
#         return _XDRPrimitiveHandler('opaque')
# 
#     @staticmethod
#     def fopaque(length):
#         return _XDRFOpaqueHandler(length)
# 
#     @staticmethod
#     def array(item_handler):
#         return _XDRArrayHandler(item_handler)
# 
#     @staticmethod
#     def optional(item_handler):
#         return _XDROptionalHandler(item_handler)
# 
#     @staticmethod
#     def constant(item_handler, value):
#         return _XDRConstantHandler(item_handler, value)
# 
#     @staticmethod
#     def struct(struct_class):
#         return _XDRStructHandler(struct_class)
# 
# class XDRStruct(object):
#     '''Base class for an XDR struct.'''
# 
#     members = ()
# 
#     def __init__(self, *args, **kwargs):
#         attrs = [a for a, _h in self._members() if a is not None]
#         for attr in attrs:
#             setattr(self, attr, None)
#         for attr, arg in zip(attrs, args):
#             setattr(self, attr, arg)
#         for k, v in kwargs.items():
#             if k not in attrs:
#                 raise TypeError('No such keyword argument: %s' % k)
#             setattr(self, k, v)
# 
#     @classmethod
#     def _members(cls):
#         '''cls.members, converted into a list of 2-tuples (attr, handler).'''
#         return list(zip(cls.members[::2], cls.members[1::2]))
# 
#     def encode(self):
#         '''Return the serialized bytes for the object.'''
#         with _convert_exceptions():
#             xdr = Packer()
#             self.encode_xdr(xdr)
#             return xdr.get_buffer()
# 
#     @classmethod
#     def decode(cls, data):
#         '''Deserialize the data and return an object.'''
#         with _convert_exceptions():
#             xdr = Unpacker(data)
#             ret = cls.decode_xdr(xdr)
#             xdr.done()
#             return ret
# 
#     def encode_xdr(self, xdr):
#         '''Serialize the object into an XDR stream.'''
#         for attr, handler in self._members():
#             if attr is not None:
#                 value = getattr(self, attr)
#             else:
#                 value = None
#             try:
#                 handler.pack(xdr, value)
#             except Exception as e:
#                 raise XDREncodingError('Failed to encode attr {}'.format(attr)) from e
# 
#     @classmethod
#     def decode_xdr(cls, xdr):
#         '''Deserialize the object from an XDR stream.'''
#         kwargs = {}
#         for attr, handler in cls._members():
#             value = handler.unpack(xdr)
#             if attr is not None:
#                 kwargs[attr] = value
#         return cls(**kwargs)


from opendiamond.rpc import RPCError
from opendiamond.xdr import XDR, XDRStruct
#
#  This software is distributed under the terms of the Eclipse Public
#  License, Version 1.0 which can be found in the file named LICENSE.
#  ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS SOFTWARE CONSTITUTES
#  RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT
#

'''XDR serialization/deserialization for the Diamond wire protocol.'''

# XDR classes are oddly named for consistency with OpenDiamond-Java
# pylint: disable=invalid-name


# Default port
PORT = 5872
# Nonce details
NONCE_LEN = 16
NULL_NONCE = b'\x00' * NONCE_LEN


class DiamondRPCFailure(RPCError):
    '''Generic Diamond RPC failure.'''
    code = 500


class DiamondRPCFCacheMiss(RPCError):
    '''Filter code or blob argument missed in the blob cache.'''
    code = 501



# Path: opendiamond/rpc.py
# class RPCError(Exception):
#     '''Base class for RPC error codes.'''
#     code = None
# 
#     # pylint doesn't know about __subclasses__
#     # pylint: disable=no-member
#     @classmethod
#     def get_class(cls, code):
#         '''Return the error subclass for the specified code.'''
#         for c in cls.__subclasses__():
#             if c.code == code:
#                 return c
#             try:
#                 return c.get_class(code)
#             except KeyError:
#                 pass
#         raise KeyError('Error code %d' % code)
#     # pylint: enable=no-member
# 
# Path: opendiamond/xdr.py
# class XDR(object):
#     '''Class containing static factory functions for XDR type handlers.'''
#     def __init__(self):
#         raise RuntimeError('Class cannot be instantiated')
# 
#     @staticmethod
#     def int():
#         return _XDRPrimitiveHandler('int')
# 
#     @staticmethod
#     def uint():
#         return _XDRPrimitiveHandler('uint')
# 
#     @staticmethod
#     def hyper():
#         return _XDRPrimitiveHandler('hyper')
# 
#     @staticmethod
#     def double():
#         return _XDRPrimitiveHandler('double')
# 
#     @staticmethod
#     def string():
#         return _XDRStringHandler()
# 
#     @staticmethod
#     def opaque():
#         return _XDRPrimitiveHandler('opaque')
# 
#     @staticmethod
#     def fopaque(length):
#         return _XDRFOpaqueHandler(length)
# 
#     @staticmethod
#     def array(item_handler):
#         return _XDRArrayHandler(item_handler)
# 
#     @staticmethod
#     def optional(item_handler):
#         return _XDROptionalHandler(item_handler)
# 
#     @staticmethod
#     def constant(item_handler, value):
#         return _XDRConstantHandler(item_handler, value)
# 
#     @staticmethod
#     def struct(struct_class):
#         return _XDRStructHandler(struct_class)
# 
# class XDRStruct(object):
#     '''Base class for an XDR struct.'''
# 
#     members = ()
# 
#     def __init__(self, *args, **kwargs):
#         attrs = [a for a, _h in self._members() if a is not None]
#         for attr in attrs:
#             setattr(self, attr, None)
#         for attr, arg in zip(attrs, args):
#             setattr(self, attr, arg)
#         for k, v in kwargs.items():
#             if k not in attrs:
#                 raise TypeError('No such keyword argument: %s' % k)
#             setattr(self, k, v)
# 
#     @classmethod
#     def _members(cls):
#         '''cls.members, converted into a list of 2-tuples (attr, handler).'''
#         return list(zip(cls.members[::2], cls.members[1::2]))
# 
#     def encode(self):
#         '''Return the serialized bytes for the object.'''
#         with _convert_exceptions():
#             xdr = Packer()
#             self.encode_xdr(xdr)
#             return xdr.get_buffer()
# 
#     @classmethod
#     def decode(cls, data):
#         '''Deserialize the data and return an object.'''
#         with _convert_exceptions():
#             xdr = Unpacker(data)
#             ret = cls.decode_xdr(xdr)
#             xdr.done()
#             return ret
# 
#     def encode_xdr(self, xdr):
#         '''Serialize the object into an XDR stream.'''
#         for attr, handler in self._members():
#             if attr is not None:
#                 value = getattr(self, attr)
#             else:
#                 value = None
#             try:
#                 handler.pack(xdr, value)
#             except Exception as e:
#                 raise XDREncodingError('Failed to encode attr {}'.format(attr)) from e
# 
#     @classmethod
#     def decode_xdr(cls, xdr):
#         '''Deserialize the object from an XDR stream.'''
#         kwargs = {}
#         for attr, handler in cls._members():
#             value = handler.unpack(xdr)
#             if attr is not None:
#                 kwargs[attr] = value
#         return cls(**kwargs)


# Path: opendiamond/protocol.py
from opendiamond.rpc import RPCError
from opendiamond.xdr import XDR, XDRStruct

#
#  This software is distributed under the terms of the Eclipse Public
#  License, Version 1.0 which can be found in the file named LICENSE.
#  ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS SOFTWARE CONSTITUTES
#  RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT
#

'''XDR serialization/deserialization for the Diamond wire protocol.'''

# XDR classes are oddly named for consistency with OpenDiamond-Java
# pylint: disable=invalid-name


# Default port
PORT = 5872
# Nonce details
NONCE_LEN = 16
NULL_NONCE = b'\x00' * NONCE_LEN


class DiamondRPCFailure(RPCError):
    '''Generic Diamond RPC failure.'''
    code = 500


class DiamondRPCFCacheMiss(RPCError):
    '''Filter code or blob argument missed in the blob cache.'''
    code = 501



class DiamondRPCCookieExpired(RPCError):