Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Can't encode all zero byte. #4

Open
1 task done
ODtian opened this issue Oct 16, 2024 · 0 comments
Open
1 task done

[Bug] Can't encode all zero byte. #4

ODtian opened this issue Oct 16, 2024 · 0 comments

Comments

@ODtian
Copy link

ODtian commented Oct 16, 2024

Checklist

  • The bug has not been reported before or it is reoccuring in a newer version

Detailed Description

All zeros bytes encoded can't be decode. And it says Unhandled exception: System.ArgumentException: Not enough shards present

Steps to Reproduce

Running example program

Console.WriteLine("Managed Example Byte");
Console.WriteLine("--------------------");
const int dataShardCount = 4;
const int parityShardCount = 2;

// Initialize Reed-Solomon with data shards and parity shards
ReedSolomon rs = new ReedSolomon(dataShardCount, parityShardCount);

// Example data to encode
byte[] data = { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
Console.WriteLine("Data:");
Console.WriteLine(string.Join(" ", data));

// Encode the data using ManagedEncode to produce shards
var shards = rs.ManagedEncode(data, dataShardCount, parityShardCount);

Console.WriteLine("Encoded Data:");
foreach (var shard in shards)
{
    Console.WriteLine(string.Join(" ", shard));
}

// Simulate loss of one shard
shards[1] = null;

Console.WriteLine("Encoded with missing Data:");
foreach (var shard in shards)
{
    if (shard == null)
    {
        Console.WriteLine("null");
    }
    else
    {
        Console.WriteLine(string.Join(" ", shard));
    }
}

// Decode the remaining shards using ManagedDecode to recover original data
var decodedData = rs.ManagedDecode(shards, dataShardCount, parityShardCount);

Console.WriteLine("Decoded data:");
Console.WriteLine(string.Join(" ", decodedData));

Related Branch or Version

version 1.1.0

Possible Fix

Further Information

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant