bch

package module
v0.0.0-...-59cfada Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 6, 2020 License: MIT Imports: 2 Imported by: 2

README

bch

GoDoc

An implementation of binary Bose-Chaudhuri-Hocquenghem (BCH) codes and error-checking in Go.

Using the package

To include it in a project, simply use:

import "github.com/zedseven/bch"

See the GoDoc manual for documentation.

An important note

Please note I did not write the basis of this package - I ported it over from an excellent example in C on ECCPage. I did, however, clean it up and build the rest of the package around the rudimentary example. Credit goes to Robert Morelos-Zaragoza for the base code.

Documentation

Overview

Package bch facilitates the use of Bose-Chaudhuri-Hocquenghem (BCH) codes and error checking. Note that the basis of this package is ported from the example at http://www.eccpage.com/bch3.c.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decode

func Decode(config *EncodingConfig, buf *[]uint8) (recd []uint8, errors int, err error)

Decode decodes a buffer of bits according to an EncodingConfig.

func Encode

func Encode(config *EncodingConfig, buf *[]uint8) (recd []uint8, err error)

Encode encodes the first k bits of the data in buf based on how many parity bits are required to satisfy the maximum correctable number of errors specified by correctableErrors. Note that the maximum correctable errors does not scale linearly with the number of parity bits required for the task.

func IsDataCorrupted

func IsDataCorrupted(config *EncodingConfig, data []uint8) bool

IsDataCorrupted determines whether or not provided data is corrupted.

func StorageBitsForConfig

func StorageBitsForConfig(codeLength, correctableErrors int) (int, error)

StorageBitsForConfig determines the number of bits able to be used for storage with a given configuration.

func TotalBitsForConfig

func TotalBitsForConfig(dataLength, correctableErrors int) (int, error)

TotalBitsForConfig is a naïve approach to finding the number of total bits required for a specific number of data bits and correctable errors. The function caches it's results.

Types

type DataTooCorruptError

type DataTooCorruptError struct{}

DataTooCorruptError is thrown when the data provided to Decode() has been corrupted too much to be able to recover.

func (DataTooCorruptError) Error

func (e DataTooCorruptError) Error() string

Error returns a string that explains the DataTooCorruptError.

type EncodingConfig

type EncodingConfig struct {
	// MaxCorrectableErrors is the maximum number of correctable errors allowed by the configuration.
	MaxCorrectableErrors int
	// The length (in bits) of the encoded data.
	CodeLength int
	// The number of bits of CodeLength that are able to store data.
	StorageBits int // k
	// contains filtered or unexported fields
}

EncodingConfig stores all the computed values from encoding that are necessary for decoding later.

func CreateConfig

func CreateConfig(codeLength, correctableErrors int) (config *EncodingConfig, err error)

CreateConfig creates an EncodingConfig to be re-used for multiple encoding operations with the same configuration.

func (EncodingConfig) ChecksumBits

func (c EncodingConfig) ChecksumBits() int

ChecksumBits simply returns the number of checksum bits in the config.

func (EncodingConfig) ECCRatio

func (c EncodingConfig) ECCRatio() float64

ECCRatio simply returns the ratio of maximum correctable errors to number of bits used.

func (EncodingConfig) String

func (c EncodingConfig) String() string

String returns the standard notation for a binary BCH code configuration of the EncodingConfig.

type InvalidInputError

type InvalidInputError struct {
	// Additional information about the problem.
	AdditionalInfo string
}

InvalidInputError is thrown when Encode() is asked to encode with settings that are invalid.

func (InvalidInputError) Error

func (e InvalidInputError) Error() string

Error returns a string that explains the InvalidInputError.

type UnachievableConfigError

type UnachievableConfigError struct {
	// Additional information about the problem.
	AdditionalInfo string
}

UnachievableConfigError is thrown when Encode() is asked to encode with settings that are either useless or unachievable.

func (UnachievableConfigError) Error

func (e UnachievableConfigError) Error() string

Error returns a string that explains the UnachievableConfigError.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL