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 ¶
- func Decode(config *EncodingConfig, buf *[]uint8) (recd []uint8, errors int, err error)
- func Encode(config *EncodingConfig, buf *[]uint8) (recd []uint8, err error)
- func IsDataCorrupted(config *EncodingConfig, data []uint8) bool
- func StorageBitsForConfig(codeLength, correctableErrors int) (int, error)
- func TotalBitsForConfig(dataLength, correctableErrors int) (int, error)
- type DataTooCorruptError
- type EncodingConfig
- type InvalidInputError
- type UnachievableConfigError
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 ¶
StorageBitsForConfig determines the number of bits able to be used for storage with a given configuration.
func TotalBitsForConfig ¶
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.