org.opennms.protocols.ip
Class OC16ChecksumProducer

java.lang.Object
  extended by org.opennms.protocols.ip.OC16ChecksumProducer

public final class OC16ChecksumProducer
extends java.lang.Object

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
OC16ChecksumProducer()
          Default constructor.
 
Method Summary
 void add(byte b)
          Adds the specified 8-bit value to the checksum.
 void add(byte a, byte b)
          Adds the specified 8-bit values to the checksum.
 void add(int i)
          Adds the specified 32-bit value to the checksum.
 void add(long l)
          Adds the specified 64-bit value to the checksum.
 void add(short s)
          Adds the specified 16-bit value to the checksum total.
 short getChecksum()
          Returns the current checksum value that has been computed for the object.
 void reset()
          Resets the object to a zero state.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

OC16ChecksumProducer

public OC16ChecksumProducer()
Default constructor.

Method Detail

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-bits
b - 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


Copyright © 2007. All Rights Reserved.