/**
* Returns the first byte from the byte array
- * @param byte[] data
* @return byte value
*/
public static byte getByte(byte[] data) {
/**
* Returns the short value for the byte array passed.
* Size of byte array is restricted to Short.SIZE
- * @param byte[] data
* @return short value
*/
public static short getShort(byte[] data) {
/**
* Returns the int value for the byte array passed.
* Size of byte array is restricted to Integer.SIZE
- * @param byte[] data
* @return int - the integer value of byte array
*/
public static int getInt(byte[] data) {
/**
* Returns the long value for the byte array passed.
* Size of byte array is restricted to Long.SIZE
- * @param byte[] data
* @return long - the integer value of byte array
*/
public static long getLong(byte[] data) {
/**
* Returns the short value for the last numBits of the byte array passed.
* Size of numBits is restricted to Short.SIZE
- * @param byte[] data
- * @param int - numBits
* @return short - the short value of byte array
*/
public static short getShort(byte[] data, int numBits) {
/**
* Returns the int value for the last numBits of the byte array passed.
* Size of numBits is restricted to Integer.SIZE
- * @param byte[] data
- * @param int - numBits
* @return int - the integer value of byte array
*/
public static int getInt(byte[] data, int numBits) {
/**
* Returns the long value for the last numBits of the byte array passed.
* Size of numBits is restricted to Long.SIZE
- * @param byte[] data
- * @param int - numBits
* @return long - the integer value of byte array
*/
public static long getLong(byte[] data, int numBits) {
* 0101000010 | 0000101 | 1111001010010101011
* will be returned as {0,0,0,0,0,1,0,1}
*
- * @param byte[] data
- * @param int startOffset - offset to start fetching bits from data from
- * @param int numBits - number of bits to be fetched from data
+ * @param startOffset - offset to start fetching bits from data from
+ * @param numBits - number of bits to be fetched from data
* @return byte [] - LSB aligned bits
*
* @throws BufferException
/**
* Bits are expected to be stored in the input byte array from LSB
- * @param byte[] - data to set the input byte
- * @param byte - input byte to be inserted
- * @param startOffset - offset of data[] to start inserting byte from
- * @param numBits - number of bits of input to be inserted into data[]
+ * @param data to set the input byte
+ * @param input byte to be inserted
+ * @param startOffset offset of data[] to start inserting byte from
+ * @param numBits number of bits of input to be inserted into data[]
*
* @throws BufferException
* when the input, startOffset and numBits are not congruent
/**
* Bits are expected to be stored in the input byte array from LSB
- * @param byte[] - data to set the input byte
- * @param byte[] - input bytes to be inserted
- * @param startOffset - offset of data[] to start inserting byte from
- * @param numBits - number of bits of input to be inserted into data[]
- * @return void
+ * @param data to set the input byte
+ * @param input bytes to be inserted
+ * @param startOffset offset of data[] to start inserting byte from
+ * @param numBits number of bits of input to be inserted into data[]
* @throws BufferException
* when the startOffset and numBits parameters are not congruent
* with data and input buffers' size
/**
* Returns numBits 1's in the MSB position
- *
- * @param numBits
- * @return
*/
public static int getMSBMask(int numBits) {
int mask = 0;
/**
* Returns numBits 1's in the LSB position
- *
- * @param numBits
- * @return
*/
public static int getLSBMask(int numBits) {
int mask = 0;
/**
* Returns the numerical value of the byte array passed
*
- * @param byte[] - array
* @return long - numerical value of byte array passed
*/
static public long toNumber(byte[] array) {
* Returns the numerical value of the last numBits (LSB bits) of the byte
* array passed
*
- * @param byte[] - array
- * @param int - numBits
* @return long - numerical value of byte array passed
*/
static public long toNumber(byte[] array, int numBits) {
* Accepts a number as input and returns its value in byte form in LSB
* aligned form example: input = 5000 [1001110001000] bytes = 19, -120
* [00010011] [10001000]
- *
- * @param Number
- * @return byte[]
- *
*/
-
public static byte[] toByteArray(Number input) {
Class<? extends Number> dataType = input.getClass();
short size = 0;
* aligned form example: input = 5000 [1001110001000] bytes = -114, 64
* [10011100] [01000000]
*
- * @param Number
- * input
- * @param int numBits - the number of bits to be returned
+ * @param numBits - the number of bits to be returned
* @return byte[]
*
*/
/**
* Takes an LSB aligned byte array and returned the LSB numBits in a MSB
- * aligned byte array
- *
- * @param inputbytes
- * @param numBits
- * @return
- */
- /**
+ * aligned byte array.
+ * <p>
* It aligns the last numBits bits to the head of the byte array following
* them with numBits % 8 zero bits.
*
* Example: For inputbytes = [00000111][01110001] and numBits = 12 it
* returns: shiftedBytes = [01110111][00010000]
*
- * @param byte[] inputBytes
- * @param int numBits - number of bits to be left aligned
+ * @param numBits - number of bits to be left aligned
* @return byte[]
*/
public static byte[] shiftBitsToMSB(byte[] inputBytes, int numBits) {
* Example: For inputbytes = [01110111][00010000] and numBits = 12 it
* returns: shiftedBytes = [00000111][01110001]
*
- * @param byte[] inputBytes
- * @param int numBits - number of bits to be right aligned
+ * @param inputBytes
+ * @param numBits - number of bits to be right aligned
* @return byte[]
*/
public static byte[] shiftBitsToLSB(byte[] inputBytes, int numBits) {
* Insert in the data buffer at position dictated by the offset the number
* of bits specified from the input data byte array. The input byte array
* has the bits stored starting from the LSB
- *
- * @param byte[] data
- * @param byte[] inputdata
- * @param int startOffset
- * @param int numBits
*/
public static void insertBits(byte[] data, byte[] inputdataLSB,
int startOffset, int numBits) {
/**
* Checks for overflow and underflow exceptions
- * @param data
- * @param startOffset
- * @param numBits
- * @throws PacketException when the startOffset and numBits parameters
+ * @throws BufferException when the startOffset and numBits parameters
* are not congruent with the data buffer's size
*/
public static void checkExceptions(byte[] data, int startOffset, int numBits)
* This method deserializes the data bits obtained from the wire into the
* respective header and payload which are of type Packet
*
- * @param byte[] data - data from wire to deserialize
- * @param int bitOffset bit position where packet header starts in data
+ * @param data - data from wire to deserialize
+ * @param bitOffset bit position where packet header starts in data
* array
- * @param int size of packet in bits
+ * @param size size of packet in bits
* @return Packet
* @throws PacketException
*/
* normal Packet.serialize() path. An example is the checksum computation
* for IPv4
*
- * @param byte[] - serialized bytes
+ * @param myBytes serialized bytes
* @throws PacketException
*/
protected void postSerializeCustomOperation(byte[] myBytes)
* Currently only IPv4 and ICMP do checksum computation and validation. TCP
* and UDP need to implement these if required.
*
- * @param byte[] data The byte stream representing the Ethernet frame
- * @param int startBitOffset The bit offset from where the byte array corresponding to this Packet starts in the frame
+ * @param data The byte stream representing the Ethernet frame
+ * @param startBitOffset The bit offset from where the byte array corresponding to this Packet starts in the frame
* @throws PacketException
*/
protected void postDeserializeCustomOperation(byte[] data, int startBitOffset)
* 'fieldname'. The offset is present in the hdrFieldCoordMap of the
* respective packet class
*
- * @param String
- * fieldName
* @return Integer - startOffset of the requested field
*/
public int getfieldOffset(String fieldName) {
* 'fieldname'. The numBits are present in the hdrFieldCoordMap of the
* respective packet class
*
- * @param String
- * fieldName
* @return Integer - number of bits of the requested field
*/
public int getfieldnumBits(String fieldName) {