org.refcodes.mixin.NameAccessor
, CrcAlgorithm
, CrcWidthAccessor
public class CrcAlgorithmImpl extends Object implements CrcAlgorithm
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.CrcWidthAccessor.CrcWidthBuilder<B extends CrcWidthAccessor.CrcWidthBuilder<B>>, CrcWidthAccessor.CrcWidthMutator, CrcWidthAccessor.CrcWidthProperty
Constructor | Description |
---|---|
CrcAlgorithmImpl(String aName,
int aCrcBitWidth,
long aPolynomial,
long aInitCrc,
boolean aRefIn,
boolean aRefOut,
long aXorOut) |
Constructs a
CrcAlgorithm instance. |
Modifier and Type | Method | Description |
---|---|---|
CrcSize |
getCrcSize() |
Returns the
CrcSize (describing the checksum's "CRC byte length"
for this CrcAlgorithmConfig . |
int |
getCrcWidth() |
Retrieves the value from the CRC byte width (number of bytes used to
store a CRC checksum) property.
|
String |
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.
|
public CrcAlgorithmImpl(String aName, int aCrcBitWidth, long aPolynomial, long aInitCrc, boolean aRefIn, boolean aRefOut, long aXorOut)
CrcAlgorithm
instance. For sound init arguments
please use predefined CrcAlgorithm
instances defined in the
CrcAlgorithmConfig
enumeration.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]public long toCrcChecksum(byte aData)
toCrcChecksum
in interface CrcAlgorithm
aData
- The data for which to calculate the checksum.public long toCrcChecksum(long aCrc, byte aData)
toCrcChecksum
in interface CrcAlgorithm
aCrc
- The CRC checksum to be updated.aData
- The data for which to calculate the checksum.public long toCrcChecksum(byte[] aData)
toCrcChecksum
in interface CrcAlgorithm
aData
- The data for which to calculate the checksum.public long toCrcChecksum(long aCrc, byte[] aData)
toCrcChecksum
in interface CrcAlgorithm
aCrc
- The CRC checksum to be updated.aData
- The data for which to calculate the checksum.public long toCrcChecksum(byte[] aData, int aOffset, int aLength)
toCrcChecksum
in interface CrcAlgorithm
aData
- The data for which to calculate the checksum.aOffset
- The offset from where to start.aLength
- The number of bytes to cover.public long toCrcChecksum(long aCrc, byte[] aData, int aOffset, int aLength)
toCrcChecksum
in interface CrcAlgorithm
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.public byte[] toCrcBytes(byte aData, Endianess aEndianess)
toCrcBytes
in interface CrcAlgorithm
aData
- The data for which to calculate the checksum.aEndianess
- The Endianess
(big endian or little endian) of
the resulting bytes representing the CRC checksum.public byte[] toCrcBytes(long aCrc, byte aData, Endianess aEndianess)
toCrcBytes
in interface CrcAlgorithm
aCrc
- The CRC checksum to be updated.aData
- The data for which to calculate the checksum.aEndianess
- The Endianess
(big endian or little endian) of
the resulting bytes representing the CRC checksum.public byte[] toCrcBytes(byte[] aData, Endianess aEndianess)
toCrcBytes
in interface CrcAlgorithm
aData
- The data for which to calculate the checksum.aEndianess
- The Endianess
(big endian or little endian) of
the resulting bytes representing the CRC checksum.public byte[] toCrcBytes(long aCrc, byte[] aData, Endianess aEndianess)
toCrcBytes
in interface CrcAlgorithm
aCrc
- The CRC checksum to be updated.aData
- The data for which to calculate the checksum.aEndianess
- The Endianess
(big endian or little endian) of
the resulting bytes representing the CRC checksum.public byte[] toCrcBytes(byte[] aData, int aOffset, int aLength, Endianess aEndianess)
toCrcBytes
in interface CrcAlgorithm
aData
- The data for which to calculate the checksum.aOffset
- The offset from where to start.aLength
- The number of bytes to cover.aEndianess
- The Endianess
(big endian or little endian) of
the resulting bytes representing the CRC checksum.public byte[] toCrcBytes(long aCrc, byte[] aData, int aOffset, int aLength, Endianess aEndianess)
toCrcBytes
in interface CrcAlgorithm
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
- The Endianess
(big endian or little endian) of
the resulting bytes representing the CRC checksum.public int getCrcWidth()
getCrcWidth
in interface CrcWidthAccessor
public CrcSize getCrcSize()
CrcSize
(describing the checksum's "CRC byte length"
for this CrcAlgorithmConfig
.getCrcSize
in interface CrcAlgorithm
CrcSize
.public String getName()
getName
in interface org.refcodes.mixin.NameAccessor
Copyright © 2021. All rights reserved.