Пример #1
0
    def __init__(self, strings):
        """
        Breaks meta data off of strings, checks metadata to make sure
        the match, then encodes

        Arguments:
        strings -- List of strings
        """

        symbols = [Metadata.fromstring(s) for s in strings]

        if not len(symbols):
            raise Exception("No symbols were provided to decode")
        
        # Make sure we have padding and k agreement between all symbols
        self.k = symbols[0][0].k
        self.padding = symbols[0][0].padding
        for meta, symbol in symbols:
            if not (meta.k == self.k):
                raise Exception("Provided symbols do not have k agreement")
            if not (meta.padding == self.padding):
                raise Exception("Provided symbols do not have padding agreement")

        # Invoke parent's init to set up raptor coding parameters
        super(StringDecoder, self).__init__(self.k)

        # Actually add symbols until decoding is possible
        for meta, symbol in symbols:
            self.symbols.append((meta.esi, numpy.fromstring(symbol, dtype=config.dtype)))

        if not self.can_decode():
            raise Exception("Unable to decode with the symbols provided.")

        # Calculate i symbols
        self.calculate_i_symbols()
 def test_bad_padding(self):
     """
     Simulates bad metadata value for padding on one symbol
     """
     size = 80
     padding = 10
     symbols = self.get_random_symbols(size, padding)
     meta, symbol = Metadata.fromstring(symbols[0])
     meta.padding = padding + 1
     symbols[0] = "%s%s" % (str(meta), symbol)
     with self.assertRaises(Exception):
         coder = StringDecoder(symbols)
Пример #3
0
    def __init__(self, strings):
        """
        Breaks meta data off of strings, checks metadata to make sure
        the match, then encodes

        Arguments:
        strings -- List of strings
        """

        symbols = [Metadata.fromstring(s) for s in strings]

        if not len(symbols):
            raise Exception("No symbols were provided to decode")

        # Make sure we have padding and k agreement between all symbols
        self.k = symbols[0][0].k
        self.padding = symbols[0][0].padding
        for meta, symbol in symbols:
            if not (meta.k == self.k):
                raise Exception("Provided symbols do not have k agreement")
            if not (meta.padding == self.padding):
                raise Exception("Provided symbols do not "
                                "have padding agreement")

        # Invoke parent's init to set up raptor coding parameters
        super(StringDecoder, self).__init__(self.k)

        # Actually add symbols until decoding is possible
        for meta, symbol in symbols:
            self.symbols.append((meta.esi,
                                 numpy.fromstring(symbol,
                                                  dtype=config.dtype)))

        if not self.can_decode():
            raise Exception("Unable to decode with the symbols provided.")

        # Calculate i symbols
        self.calculate_i_symbols()