cse466.packets
Class CSE466Packet

java.lang.Object
  |
  +--cse466.packets.CSE466Packet
Direct Known Subclasses:
AdjustGlobalsPacket, LedsPacket, SangSongPacket, SingSongNPacket, StopAndListenPacket

public class CSE466Packet
extends java.lang.Object

The base class for all of the packets. It contains the fields that are in the TOS_Msg header. Note: The parser uses the class's fields to figure out how to parse the file, so if you add or remove fields, you will confuse the parser.


Field Summary
 int amType
          the amType of this packet
 int destination
          where this packet is headed
 int groupId
          the groupID of this packet
 
Constructor Summary
CSE466Packet()
           
 
Method Summary
protected  int bytesToInt(byte first, byte second)
          Get the int value of the two bytes.
protected  int byteToInt(byte value)
          Get the int value of the byte
protected  void copyIntoArray(byte[] intoHere, byte[] fromHere, int offsetIntoIntoHere)
          Copies the contents of fromHere into intoHere starting at an offset of offsetIntoIntoHere, and going for as long as the fromHere array is.
 boolean equals(cse466.packets.CSE466Packet other)
          Returns true if the fields of this packet match the other packet's fields
 byte[] getByteArray()
          Gives you the byte array corresponding to this packet for sending over the network.
protected  byte[] getByteArray(byte[] childPacket)
          Gives you the byte array that corresponds to this packet.
 int getProperAMType()
          Returns the proper AMType for this packet, or -1 if the packet doesn't have a proper amType.
protected  byte intToByte(int value)
          Get the byte value of the value
protected  byte intToLSB(int value)
          Get the least significant byte of the value
protected  byte intToMSB(int value)
          Get the least significant byte of the value
 void print()
          Pretty print the contents of this packet to System.out
 byte[] setFromBytes(byte[] array)
          Sets the fields in this packet from the byte array given.
protected  byte[] subArray(byte[] original, int startIndex)
          Gives you a sub array starting at startIndex in original and going to the end.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

destination

public int destination
where this packet is headed


amType

public int amType
the amType of this packet


groupId

public int groupId
the groupID of this packet

Constructor Detail

CSE466Packet

public CSE466Packet()
Method Detail

getProperAMType

public int getProperAMType()
Returns the proper AMType for this packet, or -1 if the packet doesn't have a proper amType.


setFromBytes

public byte[] setFromBytes(byte[] array)
Sets the fields in this packet from the byte array given. It assumes that this packet's fields are at the very front of the array. It then will return its payload.


getByteArray

protected byte[] getByteArray(byte[] childPacket)
Gives you the byte array that corresponds to this packet. The child packet is the payload of this packet. The returned array contains this packet including the payload

Parameters:
childPacket - the payload. This will be put on the end of the array
Returns:
an array representing this packet

getByteArray

public byte[] getByteArray()
Gives you the byte array corresponding to this packet for sending over the network.


print

public void print()
Pretty print the contents of this packet to System.out


equals

public boolean equals(cse466.packets.CSE466Packet other)
Returns true if the fields of this packet match the other packet's fields

Parameters:
other - The packet to compare to.

subArray

protected byte[] subArray(byte[] original,
                          int startIndex)
Gives you a sub array starting at startIndex in original and going to the end.


copyIntoArray

protected void copyIntoArray(byte[] intoHere,
                             byte[] fromHere,
                             int offsetIntoIntoHere)
Copies the contents of fromHere into intoHere starting at an offset of offsetIntoIntoHere, and going for as long as the fromHere array is.


intToLSB

protected byte intToLSB(int value)
Get the least significant byte of the value


intToMSB

protected byte intToMSB(int value)
Get the least significant byte of the value


intToByte

protected byte intToByte(int value)
Get the byte value of the value


bytesToInt

protected int bytesToInt(byte first,
                         byte second)
Get the int value of the two bytes.

Parameters:
first - The least significant byte
second - The most significant byte

byteToInt

protected int byteToInt(byte value)
Get the int value of the byte