(self, data)
return encoder.encode(chunks)
Encode a single FEC object

        Args:
            data : Data to encode (bytes array)

        Note:
            Unlike method encode(), this method must take a data object that
            fits within 256 chunks with overhead so that it fits into a single
            FEC object. Furthermore, while encode() returns FEC packets,
            this method returns FEC chunks.

        Returns:
            List of FEC-encoded chunks.
Encode a single FEC object
Encode a single FEC object
def _encode_obj(self, data):
        """Encode a single FEC object

        Args:
            data : Data to encode (bytes array)

        Note:
            Unlike method encode(), this method must take a data object that
            fits within 256 chunks with overhead so that it fits into a single
            FEC object. Furthermore, while encode() returns FEC packets,
            this method returns FEC chunks.

        Returns:
            List of FEC-encoded chunks.

        """
        assert (isinstance(data, bytes))

        n_chunks = ceil(len(data) / CHUNK_SIZE)
        n_overhead_chunks = ceil(self.overhead * n_chunks)
        n_fec_chunks = n_chunks + n_overhead_chunks

        assert (n_fec_chunks <= MAX_FEC_CHUNKS)
        logger.debug("Original Chunks: {} / "
                     "Overhead Chunks: {} / "
                     "Total: {}".format(n_chunks, n_overhead_chunks,
                                        n_fec_chunks))

        # Split the given data array into chunks
        chunks = []
        for i_chunk in range(n_chunks):
            # Byte range of the next chunk:
            s_byte = i_chunk * CHUNK_SIZE  # starting byte
            e_byte = (i_chunk + 1) * CHUNK_SIZE  # ending byte
            chunk = data[s_byte:e_byte]

            # The last chunk may need zero-padding
            if (i_chunk + 1 == n_chunks and len(chunk) < CHUNK_SIZE):
                chunk += bytes(CHUNK_SIZE - len(chunk))

            assert (len(chunk) == CHUNK_SIZE)
            chunks.append(chunk)

        # Generate the corresponding FEC chunks
        encoder = zfec.Encoder(n_chunks, n_fec_chunks)
        return encoder.encode(chunks)
def _encode_obj ( self , data ) : assert ( isinstance ( data , bytes ) ) n_chunks = ceil ( len ( data ) / CHUNK_SIZE ) n_overhead_chunks = ceil ( self . overhead * n_chunks ) n_fec_chunks = n_chunks + n_overhead_chunks assert ( n_fec_chunks <= MAX_FEC_CHUNKS ) logger . debug ( "Original Chunks: {} / " "Overhead Chunks: {} / " "Total: {}" . format ( n_chunks , n_overhead_chunks , n_fec_chunks ) ) # Split the given data array into chunks chunks = [ ] for i_chunk in range ( n_chunks ) : # Byte range of the next chunk: s_byte = i_chunk * CHUNK_SIZE # starting byte e_byte = ( i_chunk + 1 ) * CHUNK_SIZE # ending byte chunk = data [ s_byte : e_byte ] # The last chunk may need zero-padding if ( i_chunk + 1 == n_chunks and len ( chunk ) < CHUNK_SIZE ) : chunk += bytes ( CHUNK_SIZE - len ( chunk ) ) assert ( len ( chunk ) == CHUNK_SIZE ) chunks . append ( chunk ) # Generate the corresponding FEC chunks encoder = zfec . Encoder ( n_chunks , n_fec_chunks ) return encoder . encode ( chunks )