def _decode_addr_key(self, obj_dict):
        """
        Callback function to handle the decoding of the 'Addr' field.

        Serf msgpack 'Addr' as an IPv6 address, and the data needs to be unpack
        using socket.inet_ntop().

        See: https://github.com/KushalP/serfclient-py/issues/20

        :param obj_dict: A dictionary containing the msgpack map.
        :return: A dictionary with the correct 'Addr' format.
        """
        key = b'Addr'
        if key in obj_dict:
            try:
                # Try to convert a packed IPv6 address.
                # Note: Call raises ValueError if address is actually IPv4.
                ip_addr = socket.inet_ntop(socket.AF_INET6, obj_dict[key])

                # Check if the address is an IPv4 mapped IPv6 address:
                # ie. ::ffff:xxx.xxx.xxx.xxx
                if ip_addr.startswith('::ffff:'):
                    ip_addr = ip_addr.lstrip('::ffff:')

                obj_dict[key] = ip_addr.encode('utf-8')
            except ValueError:
                # Try to convert a packed IPv4 address.
                ip_addr = socket.inet_ntop(socket.AF_INET, obj_dict[key])
                obj_dict[key] = ip_addr.encode('utf-8')

        return obj_dict
def _decode_addr_key ( self , obj_dict ) : key = b'Addr' if key in obj_dict : try : ip_addr = socket . inet_ntop ( socket . AF_INET6 , obj_dict [ key ] ) if ip_addr . startswith ( '::ffff:' ) : ip_addr = ip_addr . lstrip ( '::ffff:' ) obj_dict [ key ] = ip_addr . encode ( 'utf-8' ) except ValueError : ip_addr = socket . inet_ntop ( socket . AF_INET , obj_dict [ key ] ) obj_dict [ key ] = ip_addr . encode ( 'utf-8' ) return obj_dict
Callback function to handle the decoding of the 'Addr' field.

        Serf msgpack 'Addr' as an IPv6 address, and the data needs to be unpack
        using socket.inet_ntop().

        See: https://github.com/KushalP/serfclient-py/issues/20

        :param obj_dict: A dictionary containing the msgpack map.
        :return: A dictionary with the correct 'Addr' format.