Add liberasurecode_get_fragment_size function

For get_segment_info function of PyECLib, liberasurecode should
support get_fragment_size function because if pyeclib and liberasurecode
have the calculation of fragment size each other, it might cause
the size mismatch (i.e. it'll be a bug) in the future development work.

This patch introduces liberasurecode_get_fragment_size function to return
the fragment_size calculated at liberasurecode accoring to specified
backend descriptor.

It really usefull to help caller knows how large size it have to expect
and all pyeclib has to do for retrieving fragment_size will be just calling
the liberasurecode_get_fragment_size function on get_segment_info.
This commit is contained in:
Kota Tsuyuzaki 2015-02-20 10:46:08 +09:00
parent a8c8ed9adb
commit 54da656c65
2 changed files with 22 additions and 0 deletions

View File

@ -328,6 +328,18 @@ int liberasurecode_get_aligned_data_size(int desc, uint64_t data_len);
*/
int liberasurecode_get_minimum_encode_size(int desc);
/**
* This will return the fragment size, which is each fragment data
* length the backend will allocate when encoding.
*
* @param desc - liberasurecode descriptor/handle
* from liberasurecode_instance_create()
* @param data_len - original data length in bytes
*
* @return fragment size
*/
int liberasurecode_get_fragment_size(int desc, int data_len);
/* ==~=*=~===~=*=~==~=*=~== liberasurecode Error codes =~=*=~==~=~=*=~==~== */
/* Error codes */

View File

@ -1118,6 +1118,16 @@ int liberasurecode_get_minimum_encode_size(int desc)
return liberasurecode_get_aligned_data_size(desc, 1);
}
int liberasurecode_get_fragment_size(int desc, int data_len)
{
ec_backend_t instance = liberasurecode_backend_instance_get_by_desc(desc);
// TODO: Create a common function to calculate fragment size also for preprocessing
int aligned_data_len = get_aligned_data_size(instance, data_len);
int size = (aligned_data_len / instance->args.uargs.k) + instance->common.metadata_adder;
return size;
}
/* ==~=*=~==~=*=~==~=*=~==~=*=~==~=* misc *=~==~=*=~==~=*=~==~=*=~==~=*=~== */
#if 0