2018-04-11 14:41:50 +01:00
|
|
|
// Copyright (C) 2018 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package eestream
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/vivint/infectious"
|
|
|
|
)
|
|
|
|
|
|
|
|
type rsScheme struct {
|
2018-09-27 12:52:18 +01:00
|
|
|
fc *infectious.FEC
|
|
|
|
erasureShareSize int
|
2018-04-11 14:41:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewRSScheme returns a Reed-Solomon-based ErasureScheme.
|
2018-09-27 12:52:18 +01:00
|
|
|
func NewRSScheme(fc *infectious.FEC, erasureShareSize int) ErasureScheme {
|
|
|
|
return &rsScheme{fc: fc, erasureShareSize: erasureShareSize}
|
2018-04-11 14:41:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *rsScheme) Encode(input []byte, output func(num int, data []byte)) (
|
|
|
|
err error) {
|
|
|
|
return s.fc.Encode(input, func(s infectious.Share) {
|
|
|
|
output(s.Number, s.Data)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *rsScheme) Decode(out []byte, in map[int][]byte) ([]byte, error) {
|
|
|
|
shares := make([]infectious.Share, 0, len(in))
|
|
|
|
for num, data := range in {
|
|
|
|
shares = append(shares, infectious.Share{Number: num, Data: data})
|
|
|
|
}
|
|
|
|
return s.fc.Decode(out, shares)
|
|
|
|
}
|
|
|
|
|
2018-09-27 12:52:18 +01:00
|
|
|
func (s *rsScheme) ErasureShareSize() int {
|
|
|
|
return s.erasureShareSize
|
2018-04-11 14:41:50 +01:00
|
|
|
}
|
|
|
|
|
2018-09-27 12:52:18 +01:00
|
|
|
func (s *rsScheme) StripeSize() int {
|
|
|
|
return s.erasureShareSize * s.fc.Required()
|
2018-04-11 14:41:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *rsScheme) TotalCount() int {
|
|
|
|
return s.fc.Total()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *rsScheme) RequiredCount() int {
|
|
|
|
return s.fc.Required()
|
|
|
|
}
|