Documentation
¶
Overview ¶
Package lrc implements two simple hash algorithms, confusingly known under the same name, Longitudinal Redundancy Check (LRC). The hash sum of both algorithms is just a single byte.
The first algorithm, also known as BCC (for block check character) calculates its single sum byte simply as the XOR of all input bytes. This is the algorithm defined in ISO 1155.
The second algorithm calculates its single sum byte as the 2's complement of the arithmetic sum (mod 2⁸) of the input bytes. This is the algorithm used by the popular Modbus standard, as specified in Modbus over Serial Line, section 6.2.1.
The BCC and LRC types in this package implement the hash.Hash, encoding.BinaryMarshaler and encoding.BinaryUnmarshaler interfaces.
Index ¶
- type BCC
- type LRC
- func (LRC) BlockSize() int
- func (b LRC) HexSum(buf []byte) []byte
- func (b LRC) MarshalBinary() ([]byte, error)
- func (b *LRC) Reset()
- func (LRC) Size() int
- func (b LRC) Sum(buf []byte) []byte
- func (b LRC) Sum8() uint8
- func (b *LRC) UnmarshalBinary(data []byte) error
- func (b *LRC) Write(buf []byte) (int, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BCC ¶
type BCC byte
BCC implements the block check character hash, which is simply the XOR of all input bytes. The zero value is ready to use.
func (BCC) MarshalBinary ¶
MarshalBinary implements encoding.BinaryMarshaler.MarshalBinary.
func (*BCC) UnmarshalBinary ¶
UnmarshalBinary implements encoding.BinaryUnmarshaler.UnmarshalBinary.
type LRC ¶
type LRC byte
LRC implements the Modbus longitudinal redundancy check hash, which is simply the 2's complements of the sum (mod 2⁸) of all input bytes. The zero value is ready to use.
func (LRC) HexSum ¶
HexSum appends the current hash to buf in hexadecimal format and returns the resulting slice. It does not change the underlying hash state. The hexadecimal representation is high-nibble first, using upper case hexadecimal digits. This format conforms to the specification of the ASCII transmission mode in the Modbus over serial line specification (section 2.5.2).
func (LRC) MarshalBinary ¶
MarshalBinary implements encoding.BinaryMarshaler.MarshalBinary.
func (*LRC) UnmarshalBinary ¶
UnmarshalBinary implements encoding.BinaryUnmarshaler.UnmarshalBinary.