Skip to content

Predicting RS encoded bytes size #75

Description

@Cioscos

I need for the sake of the function of my software to predict the size of the encoded block of data generated by RSCodec.encode().

This is an extract of my code:

while start_idx < file_size:
      end_idx = min(start_idx + max_data_size - len(header_bytes), file_size)
      data_chunk = file_bytes[start_idx:end_idx]

      # Create header with size information for each chunk
      header_with_size = header_bytes + data_chunk

      # Add padding to make the size equal to max_data_size
      if len(header_with_size) < max_data_size:
          padding_length = max_data_size - len(header_with_size)
          header_with_size += bytes([0] * padding_length)

      # Encode file data with Reed-Solomon error correction
      encoded_data = rs.encode(header_with_size)

      # Append encoded data to the buffer
      data_buffer.extend(encoded_data)

      start_idx = end_idx

As you can see I've a if statement that add some padding to the header_with_size bytearray if its size is littler than max_data_size.
If this if is triggered it makes header_with_size 1024 bytes long. After the rs.encode function, the encoded_data becomes 1074 bytes long.
If I comment out the padding if statement, I had cases where header_with_size's was of 300 bytes and the encoded_data's size was 310 which should be correct because I've initialized the RSCodec in this way "rs = RSCodec(ecc_bytes)" where ecc_bytes is 10.
So I thought that the encoded_data size is always 10 byte longer than the original size but it doesn't seem to be like this since when the bytearray is 1024 bytes long the encoding function adds 50 bytes, and I would like to understand if it's possible to predict this behaviour.

Thank you in advance

Metadata

Metadata

Assignees

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions