Documentation
¶
Overview ¶
Package reedsolomon implements a pure-Go, dependency-free Reed-Solomon erasure code over GF(2^16).
The finite field uses the primitive polynomial 0x1100B and generator 2, making it byte-for-byte compatible with the field used by the PAR2 recovery format. The GF16 type is exported so that a PAR2 layer built on top of this package can reuse the exact same arithmetic core.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrShardCount is returned when the number of shards (or present flags) // does not equal dataShards+parityShards. ErrShardCount = errors.New("reedsolomon: wrong number of shards") // ErrShardSize is returned when shards are not all equal length or their // length is odd (shards are big-endian uint16 words). ErrShardSize = errors.New("reedsolomon: shards must be equal, even-length") // ErrTooFewShards is returned when fewer than dataShards shards are present // during reconstruction. ErrTooFewShards = errors.New("reedsolomon: not enough shards present to reconstruct") // ErrInvalidParams is returned by New for non-positive shard counts or when // dataShards+parityShards exceeds 65535. ErrInvalidParams = errors.New("reedsolomon: invalid data/parity shard counts") )
Errors returned by the package.
Functions ¶
This section is empty.
Types ¶
type Encoder ¶
type Encoder struct {
// contains filtered or unexported fields
}
Encoder is an (n = dataShards + parityShards) Reed-Solomon erasure coder over GF(2^16). Shards are byte slices interpreted as big-endian uint16 words; all shards must share the same even length.
func New ¶
New returns an encoder for dataShards data shards plus parityShards parity shards. It returns ErrInvalidParams if either count is non-positive or if dataShards+parityShards exceeds 65535.
func (*Encoder) DataShards ¶
DataShards returns the number of data shards.
func (*Encoder) Encode ¶
Encode fills the parity shards from the data shards. shards must have length dataShards+parityShards; the first dataShards are read and the remaining parityShards are written.
func (*Encoder) ParityShards ¶
ParityShards returns the number of parity shards.
func (*Encoder) Reconstruct ¶
Reconstruct recovers missing shards in place. present[i] == false marks shard i (data or parity) as erased; each erased shard's slice must already be allocated to the common shard length. It succeeds when at least dataShards shards are present.
type GF16 ¶
type GF16 struct {
// contains filtered or unexported fields
}
GF16 provides arithmetic over GF(2^16) with primitive polynomial 0x1100B and generator 2. It holds precomputed exponent and logarithm tables over the 65535-element multiplicative group.
func NewGF16 ¶
func NewGF16() *GF16
NewGF16 returns a GF16 with its exp/log tables built for generator 2 and primitive polynomial 0x1100B.
func (*GF16) Div ¶
Div returns a / b in GF(2^16). Dividing by zero panics; callers must ensure b is non-zero.
func (*GF16) Exp ¶
Exp returns generator^power. Negative and large powers are reduced modulo the order of the multiplicative group.
