Documentation
¶
Index ¶
- Constants
- Variables
- func AllocAligned(shards, each int) [][]byte
- func GaloisAdd(a, b byte) byte
- func GaloisDivide(a, b byte) byte
- func GaloisExp(a byte, n int) byte
- func GaloisMultiply(a, b byte) byte
- func SetLogger(l Logger)
- type Extensions
- type Logger
- type ReedSolomon
- type StreamEncoder8
- type StreamEncoder16
- type StreamReadError
- type StreamWriteError
Constants ¶
View Source
const ( LogLevelNone = iota LogLevelError LogLevelWarn LogLevelInfo LogLevelDebug )
日志级别定义
Variables ¶
View Source
var ( ErrInvShardNum = errors.New("无效的分片数量") ErrMaxShardNum = errors.New("分片数量超过最大支持数") ErrTooFewShards = errors.New("可用分片数量不足,无法重建数据") ErrShardNoData = errors.New("分片中没有数据") ErrShardSize = errors.New("分片大小不一致") ErrEmptyShards = errors.New("空分片数组") ErrInvalidShards = errors.New("无效的分片数据") ErrInvalidInput = errors.New("无效的输入数据") ErrInvalidOutput = errors.New("无效的输出缓冲区") ErrReconstructRequired = errors.New("需要先进行数据重建") ErrInvalidShardSize = errors.New("分片大小不满足要求,通常是N的倍数") ErrShortData = errors.New("数据不足,无法填充请求的分片数量") ErrNotSupported = errors.New("operation not supported") // 流式操作相关错误 ErrReconstructMismatch = errors.New("一个分片不能同时是输入和输出") ErrNilWriter = errors.New("目标写入器不能为nil") ErrSize = errors.New("无效的大小参数") )
错误定义
View Source
var GF8Bridge = newGF8Bridge()
创建全局包装实例供适配器使用
Functions ¶
func AllocAligned ¶
AllocAligned allocates 'shards' slices, with 'each' bytes. Each slice will start on a 64 byte aligned boundary.
func GaloisDivide ¶
GaloisDivide 执行Galois域除法 在实际集成时,这将使用原始galois.go中的galDivide函数
func GaloisMultiply ¶
GaloisMultiply 执行Galois域乘法 在实际集成时,这将使用原始galois.go中的galMultiply函数
Types ¶
type Extensions ¶
type Extensions interface {
// ShardSizeMultiple will return the size the shard sizes must be a multiple of.
ShardSizeMultiple() int
// DataShards will return the number of data shards.
DataShards() int
// ParityShards will return the number of parity shards.
ParityShards() int
// TotalShards will return the total number of shards.
TotalShards() int
// AllocAligned will allocate TotalShards number of slices,
// aligned to reasonable memory sizes.
// Provide the size of each shard.
AllocAligned(each int) [][]byte
}
Extensions is an optional interface. All returned instances will support this interface.
type Logger ¶
type Logger interface {
Error(msg string, args ...interface{})
Warn(msg string, args ...interface{})
Info(msg string, args ...interface{})
Debug(msg string, args ...interface{})
SetLevel(level int)
}
Logger 接口定义了日志系统
type ReedSolomon ¶
type ReedSolomon interface {
// 获取配置信息
DataShards() int // 返回数据分片数量
ParityShards() int // 返回奇偶校验分片数量
TotalShards() int // 返回总分片数量(数据分片+奇偶校验分片)
// 内存操作
Encode(shards [][]byte) error // 对数据分片编码,生成奇偶校验分片
Verify(shards [][]byte) (bool, error) // 验证分片数据的一致性
Reconstruct(shards [][]byte) error // 重建丢失的分片(数据和奇偶校验)
ReconstructData(shards [][]byte) error // 只重建丢失的数据分片
Split(data []byte) ([][]byte, error) // 将数据拆分成多个分片
Join(dst io.Writer, shards [][]byte, outSize int) error // 将分片合并成单个数据块
// 流式操作
StreamEncode(inputs []io.Reader, outputs []io.Writer) error // 流式编码
StreamVerify(shards []io.Reader) (bool, error) // 流式验证
StreamReconstruct(inputs []io.Reader, outputs []io.Writer) error // 流式重建
StreamReconstructData(inputs []io.Reader, outputs []io.Writer) error // 流式重建数据分片
StreamSplit(data io.Reader, dst []io.Writer, size int64) error // 流式拆分
StreamJoin(dst io.Writer, shards []io.Reader, outSize int64) error // 流式合并
// 内存管理
AllocAligned(shards, each int) [][]byte // 分配对齐的内存
ShardSizeMultiple() int // 返回分片大小需要满足的倍数
// 并发控制
WithConcurrency(n int) ReedSolomon // 设置并发级别
}
ReedSolomon 接口定义了Reed-Solomon编解码器的通用操作 支持内存操作和流式操作
func New ¶
func New(dataShards, parityShards int) (ReedSolomon, error)
New 创建一个新的Reed-Solomon编解码器 如果总分片数 <= 256,将使用GF(2^8)实现,否则使用GF(2^16)实现
func New8 ¶
func New8(dataShards, parityShards int) (ReedSolomon, error)
New8 创建一个基于GF(2^8)的Reed-Solomon编解码器,最多支持256个分片
func New16 ¶
func New16(dataShards, parityShards int) (ReedSolomon, error)
New16 创建一个基于GF(2^16)的Reed-Solomon编解码器,最多支持65535个分片
type StreamEncoder8 ¶
type StreamEncoder8 interface {
// Encode 为一组数据分片生成奇偶校验分片
Encode(inputs []io.Reader, outputs []io.Writer) error
// Verify 验证奇偶校验分片的正确性
Verify(shards []io.Reader) (bool, error)
// Reconstruct 重建丢失的分片
Reconstruct(inputs []io.Reader, outputs []io.Writer) error
// Split 将输入流分割成多个分片
Split(data io.Reader, dst []io.Writer, size int64) error
// Join 将分片连接起来并将数据段写入dst
Join(dst io.Writer, shards []io.Reader, outSize int64) error
}
StreamEncoder8 是一个基于GF(2^8)的Reed-Solomon流式编码器接口
type StreamEncoder16 ¶
type StreamEncoder16 interface {
// Encode 为一组数据分片生成奇偶校验分片
Encode(inputs []io.Reader, outputs []io.Writer) error
// Verify 验证奇偶校验分片的正确性
Verify(shards []io.Reader) (bool, error)
// Reconstruct 重建丢失的分片
Reconstruct(inputs []io.Reader, outputs []io.Writer) error
// Split 将输入流分割成多个分片
Split(data io.Reader, dst []io.Writer, size int64) error
// Join 将分片连接起来并将数据段写入dst
Join(dst io.Writer, shards []io.Reader, outSize int64) error
}
StreamEncoder16 是一个基于GF(2^16)的Reed-Solomon流式编码器接口
type StreamWriteError ¶
流写入错误
func (StreamWriteError) Error ¶
func (e StreamWriteError) Error() string
Source Files
¶
Click to show internal directories.
Click to hide internal directories.