java.lang.Object
org.refcodes.numerical.CrcAlgorithmImpl
- All Implemented Interfaces:
org.refcodes.mixin.NameAccessor
,CrcAlgorithm
,CrcWidthAccessor
Implementation of the
CrcAlgorithm
interface. Credits to [Anton
Isakov (http://crccalc.com) of the "Online CRC-8 CRC-16 CRC-32 Calculator"
(https://crccalc.com)'s GitHub (https://github.com/meetanthony/crcjava.git)
repository.-
Nested Class Summary
Nested classes/interfaces inherited from interface org.refcodes.numerical.CrcWidthAccessor
CrcWidthAccessor.CrcWidthBuilder<B extends CrcWidthAccessor.CrcWidthBuilder<B>>, CrcWidthAccessor.CrcWidthMutator, CrcWidthAccessor.CrcWidthProperty
Nested classes/interfaces inherited from interface org.refcodes.mixin.NameAccessor
org.refcodes.mixin.NameAccessor.NameBuilder<B extends org.refcodes.mixin.NameAccessor.NameBuilder<B>>, org.refcodes.mixin.NameAccessor.NameMutator, org.refcodes.mixin.NameAccessor.NameProperty
-
Constructor Summary
ConstructorDescriptionCrcAlgorithmImpl
(String aName, int aCrcBitWidth, long aPolynomial, long aInitCrc, boolean aRefIn, boolean aRefOut, long aXorOut) Constructs aCrcAlgorithm
instance. -
Method Summary
Modifier and TypeMethodDescriptionReturns theCrcSize
(describing the checksum's "CRC byte length" for thisCrcStandard
.int
Retrieves the value from the CRC byte width (number of bytes used to store a CRC checksum) property.getName()
byte[]
toCrcBytes
(byte[] aData, int aOffset, int aLength, Endianess aEndianess) Calculates the according checksum from the supplied data data and returns the according byte array of the CRC checksum.byte[]
toCrcBytes
(byte[] aData, Endianess aEndianess) Calculates the according checksum from the supplied data data and returns the according byte array of the CRC checksum.byte[]
toCrcBytes
(byte aData, Endianess aEndianess) Calculates the according checksum from the supplied data and returns the according byte array of the CRC checksum.byte[]
toCrcBytes
(long aCrc, byte[] aData, int aOffset, int aLength, Endianess aEndianess) Updates the according checksum with he supplied data data and returns the according byte array of the CRC checksum.byte[]
toCrcBytes
(long aCrc, byte[] aData, Endianess aEndianess) Updates the according checksum with he supplied data data and returns the according byte array of the CRC checksum.byte[]
toCrcBytes
(long aCrc, byte aData, Endianess aEndianess) Updates the according checksum with he supplied data data and returns the according byte array of the CRC checksum.long
toCrcChecksum
(byte aData) Calculates the according checksum from the supplied data.long
toCrcChecksum
(byte[] aData) Calculates the according checksum from the supplied data.long
toCrcChecksum
(byte[] aData, int aOffset, int aLength) Calculates the according checksum from the supplied data.long
toCrcChecksum
(long aCrc, byte aData) Updates the according checksum with he supplied data.long
toCrcChecksum
(long aCrc, byte[] aData) Updates the according checksum with he supplied data.long
toCrcChecksum
(long aCrc, byte[] aData, int aOffset, int aLength) Updates the according checksum with he supplied data.
-
Constructor Details
-
CrcAlgorithmImpl
public CrcAlgorithmImpl(String aName, int aCrcBitWidth, long aPolynomial, long aInitCrc, boolean aRefIn, boolean aRefOut, long aXorOut) Constructs aCrcAlgorithm
instance. For sound init arguments please use predefinedCrcAlgorithm
instances defined in theCrcStandard
enumeration.- Parameters:
aName
- The descriptive name of the algorithm.aCrcBitWidth
- "This is hash size." [Anton Isakov http://crccalc.com]aPolynomial
- "This parameter is the poly. This is a binary value that should be specified as a hexadecimal number.The top bit of the poly should be omitted.For example, if the poly is 10110, you should specify 06. An important aspect of this parameter is that it represents the unreflected poly; the bottom bit of this parameter is always the LSB of the divisor during the division regardless of whether the algorithm being modelled is reflected." [Anton Isakov http://crccalc.com]aInitCrc
- "This parameter specifies the initial value of the register when the algorithm starts.This is the value that is to be assigned to the register in the direct table algorithm. In the table algorithm, we may think of the register always commencing with the value zero, and this value being XORed into the register after the N'th bit iteration. This parameter should be specified as a hexadecimal number." [Anton Isakov http://crccalc.com]aRefIn
- "This parameter is the poly. This is a binary value that should be specified as a hexadecimal number.The top bit of the poly should be omitted.For example, if the poly is 10110, you should specify 06. An important aspect of this parameter is that it represents the unreflected poly; the bottom bit of this parameter is always the LSB of the divisor during the division regardless of whether the algorithm being modelled is reflected." [Anton Isakov http://crccalc.com]aRefOut
- "This is a boolean parameter. If it is set to FALSE, the final value in the register is fed into the XOROUT stage directly, otherwise, if this parameter is TRUE, the final register value is reflected first." [Anton Isakov http://crccalc.com]aXorOut
- "This is an W-bit value that should be specified as a hexadecimal number.It is XORed to the final register value (after the REFOUT) stage before the value is returned as the official checksum." [Anton Isakov http://crccalc.com]
-
-
Method Details
-
toCrcChecksum
public long toCrcChecksum(byte aData) Calculates the according checksum from the supplied data.- Specified by:
toCrcChecksum
in interfaceCrcAlgorithm
- Parameters:
aData
- The data for which to calculate the checksum.- Returns:
- The according checksum.
-
toCrcChecksum
public long toCrcChecksum(long aCrc, byte aData) Updates the according checksum with he supplied data.- Specified by:
toCrcChecksum
in interfaceCrcAlgorithm
- Parameters:
aCrc
- The CRC checksum to be updated.aData
- The data for which to calculate the checksum.- Returns:
- The accordingly updated checksum.
-
toCrcChecksum
public long toCrcChecksum(byte[] aData) Calculates the according checksum from the supplied data.- Specified by:
toCrcChecksum
in interfaceCrcAlgorithm
- Parameters:
aData
- The data for which to calculate the checksum.- Returns:
- The according checksum.
-
toCrcChecksum
public long toCrcChecksum(long aCrc, byte[] aData) Updates the according checksum with he supplied data.- Specified by:
toCrcChecksum
in interfaceCrcAlgorithm
- Parameters:
aCrc
- The CRC checksum to be updated.aData
- The data for which to calculate the checksum.- Returns:
- The accordingly updated checksum.
-
toCrcChecksum
public long toCrcChecksum(byte[] aData, int aOffset, int aLength) Calculates the according checksum from the supplied data.- Specified by:
toCrcChecksum
in interfaceCrcAlgorithm
- Parameters:
aData
- The data for which to calculate the checksum.aOffset
- The offset from where to start.aLength
- The number of bytes to cover.- Returns:
- The according checksum.
-
toCrcChecksum
public long toCrcChecksum(long aCrc, byte[] aData, int aOffset, int aLength) Updates the according checksum with he supplied data.- Specified by:
toCrcChecksum
in interfaceCrcAlgorithm
- Parameters:
aCrc
- The CRC checksum to be updated.aData
- The data for which to calculate the checksum.aOffset
- The offset from where to start.aLength
- The number of bytes to cover.- Returns:
- The accordingly updated checksum.
-
toCrcBytes
Calculates the according checksum from the supplied data and returns the according byte array of the CRC checksum.- Specified by:
toCrcBytes
in interfaceCrcAlgorithm
- Parameters:
aData
- The data for which to calculate the checksum.aEndianess
- TheEndianess
(big endian or little endian) of the resulting bytes representing the CRC checksum.- Returns:
- The according checksum.
-
toCrcBytes
Updates the according checksum with he supplied data data and returns the according byte array of the CRC checksum.- Specified by:
toCrcBytes
in interfaceCrcAlgorithm
- Parameters:
aCrc
- The CRC checksum to be updated.aData
- The data for which to calculate the checksum.aEndianess
- TheEndianess
(big endian or little endian) of the resulting bytes representing the CRC checksum.- Returns:
- The accordingly updated checksum.
-
toCrcBytes
Calculates the according checksum from the supplied data data and returns the according byte array of the CRC checksum.- Specified by:
toCrcBytes
in interfaceCrcAlgorithm
- Parameters:
aData
- The data for which to calculate the checksum.aEndianess
- TheEndianess
(big endian or little endian) of the resulting bytes representing the CRC checksum.- Returns:
- The according checksum.
-
toCrcBytes
Updates the according checksum with he supplied data data and returns the according byte array of the CRC checksum.- Specified by:
toCrcBytes
in interfaceCrcAlgorithm
- Parameters:
aCrc
- The CRC checksum to be updated.aData
- The data for which to calculate the checksum.aEndianess
- TheEndianess
(big endian or little endian) of the resulting bytes representing the CRC checksum.- Returns:
- The accordingly updated checksum.
-
toCrcBytes
Calculates the according checksum from the supplied data data and returns the according byte array of the CRC checksum.- Specified by:
toCrcBytes
in interfaceCrcAlgorithm
- Parameters:
aData
- The data for which to calculate the checksum.aOffset
- The offset from where to start.aLength
- The number of bytes to cover.aEndianess
- TheEndianess
(big endian or little endian) of the resulting bytes representing the CRC checksum.- Returns:
- The according checksum.
-
toCrcBytes
Updates the according checksum with he supplied data data and returns the according byte array of the CRC checksum.- Specified by:
toCrcBytes
in interfaceCrcAlgorithm
- Parameters:
aCrc
- The CRC checksum to be updated.aData
- The data for which to calculate the checksum.aOffset
- The offset from where to start.aLength
- The number of bytes to cover.aEndianess
- TheEndianess
(big endian or little endian) of the resulting bytes representing the CRC checksum.- Returns:
- The accordingly updated checksum.
-
getCrcWidth
public int getCrcWidth()Retrieves the value from the CRC byte width (number of bytes used to store a CRC checksum) property.- Specified by:
getCrcWidth
in interfaceCrcWidthAccessor
- Returns:
- The name stored by the CRC byte width (number of bytes used to store a CRC checksum) property.
-
getCrcSize
Returns theCrcSize
(describing the checksum's "CRC byte length" for thisCrcStandard
.- Specified by:
getCrcSize
in interfaceCrcAlgorithm
- Returns:
- The according
CrcSize
.
-
getName
- Specified by:
getName
in interfaceorg.refcodes.mixin.NameAccessor
-