Package org.opennms.protocols.ip
Class OC16ChecksumProducer
java.lang.Object
org.opennms.protocols.ip.OC16ChecksumProducer
Produces a one's compliment 16-bit checksum from data that is "added" to the
sum. The producer handles objects from 8-bits to 64-bit values.
- Author:
- Brian Weaver
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(byte b) Adds the specified 8-bit value to the checksum.voidadd(byte a, byte b) Adds the specified 8-bit values to the checksum.voidadd(int i) Adds the specified 32-bit value to the checksum.voidadd(long l) Adds the specified 64-bit value to the checksum.voidadd(short s) Adds the specified 16-bit value to the checksum total.shortReturns the current checksum value that has been computed for the object.voidreset()Resets the object to a zero state.
-
Constructor Details
-
OC16ChecksumProducer
public OC16ChecksumProducer()Default constructor.
-
-
Method Details
-
add
public void add(byte b) Adds the specified 8-bit value to the checksum. Since the checksum must be in 16-bits, the byte is copied to the upper 8-bits of the 16-bit value. The lower 8-bits are set to zero.- Parameters:
b- The 8-bit value to add to the checksum.
-
add
public void add(byte a, byte b) Adds the specified 8-bit values to the checksum. The checksum is performed using 16-bit values, thus the first byte is places into the high 8-bits of the word. The second byte is placed into the lower 8-bits of the 16-bit word. Then the result is added to the 16-bit checksum.- Parameters:
a- The high order 8-bitsb- The low order 8-bits
-
add
public void add(short s) Adds the specified 16-bit value to the checksum total.- Parameters:
s- The 16-bit value to add
-
add
public void add(int i) Adds the specified 32-bit value to the checksum. The 32-bit value is broken into two 16-bit values for the purpose of computing the checksum.- Parameters:
i- The 32-bit value.
-
add
public void add(long l) Adds the specified 64-bit value to the checksum. The 64-bit value is split into 4 16-bit quantities and added to the checksum.- Parameters:
l- The 64-bit value to add
-
reset
public void reset()Resets the object to a zero state. -
getChecksum
public short getChecksum()Returns the current checksum value that has been computed for the object.- Returns:
- The 16-bit ones compliment checksum
-