encoded size function is now public + some janitor duty

This commit is contained in:
Anand Babu (AB) Periasamy
2015-03-22 17:17:53 -07:00
parent 537870ec4f
commit 3a76229551
4 changed files with 40 additions and 35 deletions

View File

@@ -39,10 +39,10 @@ func (e *Encoder) Decode(chunks [][]byte, length int) ([]byte, error) {
k := int(e.k)
n := int(e.k + e.m)
if len(chunks) != n {
if len(chunks) != int(n) {
return nil, errors.New(fmt.Sprintf("chunks length must be %d", n))
}
chunk_size := getChunkSize(k, length)
chunk_size := GetEncodedChunkLen(length, k)
error_index := make([]int, n+1)
var err_count int = 0
@@ -58,7 +58,7 @@ func (e *Encoder) Decode(chunks [][]byte, length int) ([]byte, error) {
err_count++
// Too many missing chunks, cannot be more than parity `m`
if err_count-1 > (n - k) {
if err_count-1 > int(n-k) {
return nil, errors.New("too many erasures requested, can't decode")
}
@@ -90,8 +90,8 @@ func (e *Encoder) Decode(chunks [][]byte, length int) ([]byte, error) {
C.ec_encode_data(C.int(chunk_size), e.k, C.int(err_count-1), decode_tbls,
source, target)
recovered_output := make([]byte, 0, chunk_size*k)
for i := 0; i < k; i++ {
recovered_output := make([]byte, 0, chunk_size*int(k))
for i := 0; i < int(k); i++ {
recovered_output = append(recovered_output, chunks[i]...)
}