me.edwards.des.net.packet
Class Packet

java.lang.Object
  extended by me.edwards.des.net.packet.Packet
Direct Known Subclasses:
PacketAddr, PacketBallot, PacketBlock, PacketGetAddr, PacketGetBlocks, PacketGetData, PacketInv, PacketNotFound, PacketPing, PacketPong, PacketVerack, PacketVersion

public abstract class Packet
extends java.lang.Object

Handles packaging and unpackaging of Packets sent between Nodes in the DES system.

Created on: Oct 17, 2015 at 9:08:41 AM

Author:
Matthew Edwards

Nested Class Summary
static class Packet.PacketTypes
          Enumerates all the types of Packets and their ID's.

Created on: Jan 4, 2015 at 10:50:45 AM
 
Field Summary
private static java.lang.String CHARS
           
private static char[] HEX
           
private  byte id
           
private static int total
          Value used to automatically assign unique integer ID's to Packet Types.
 
Constructor Summary
Packet(byte id)
          Initializes a new Packet using an ID defined in Packet.PacketTypes.
 
Method Summary
abstract  byte[] getBinary()
          Returns the binary payload of this Packet as a byte array.
 byte getID()
          Returns this Packet's ID.
static Packet.PacketTypes lookup(byte id)
          Returns the Packet Type from a numeric Type ID.
static java.lang.String toHex(byte b)
          Returns a byte as a 2-digit hexadecimal String
 java.lang.String toString()
           
static java.lang.String toString(byte[] data)
          Returns the String representation of a Packet's binary data.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

HEX

private static final char[] HEX

CHARS

private static final java.lang.String CHARS
See Also:
Constant Field Values

id

private byte id

total

private static int total
Value used to automatically assign unique integer ID's to Packet Types.

Constructor Detail

Packet

public Packet(byte id)
Initializes a new Packet using an ID defined in Packet.PacketTypes.

Parameters:
id - ID of Packet
Method Detail

getID

public byte getID()
Returns this Packet's ID.

Returns:
Packet Type ID
See Also:
Packet.PacketTypes

getBinary

public abstract byte[] getBinary()
Returns the binary payload of this Packet as a byte array.

Returns:
Binary payload as a byte array

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

toString

public static java.lang.String toString(byte[] data)
Returns the String representation of a Packet's binary data.

Parameters:
data - Packet binary payload as byte array
Returns:
String representation of binary payload (Byte dump)

toHex

public static java.lang.String toHex(byte b)
Returns a byte as a 2-digit hexadecimal String

Parameters:
b - Byte to convert
Returns:
2-digit hexadecimal String representation of converted byte

lookup

public static Packet.PacketTypes lookup(byte id)
Returns the Packet Type from a numeric Type ID.

Parameters:
id - Packet Type ID
Returns:
PacketTypes object corresponding to the Packet Type ID. If the ID can not be found, the Invalid Packet Type is returned