me.edwards.des.net.packet
Class PacketInv

java.lang.Object
  extended by me.edwards.des.net.packet.Packet
      extended by me.edwards.des.net.packet.PacketInv

public class PacketInv
extends Packet

Inventory Packet

This packet is sent to advertise knowledge of a particular piece, or pieces, of data.

Created on: Nov 3, 2015 at 9:17:44 AM

Author:
Matthew Edwards

Nested Class Summary
protected static class PacketInv.InvVector
          Inventory Vector contains the hash of the inventory object and its type.
 
Nested classes/interfaces inherited from class me.edwards.des.net.packet.Packet
Packet.PacketTypes
 
Field Summary
static int VECTOR_BALLOT
          The Vector type for a Ballot Object
static int VECTOR_BLOCK
          The Vector type for a Block Object
private  java.util.ArrayList<PacketInv.InvVector> vectors
           
 
Constructor Summary
PacketInv()
          Creates new PacketInv
PacketInv(byte[] binary)
          Creates new PacketInv from binary data
 
Method Summary
 void addInv(java.lang.Object invObject)
          Adds an inventory object to this Packet.
 byte[] getBinary()
          Returns the binary payload of this Packet as a byte array.
 java.lang.String getHash(int index)
          Returns the hash of the vector at the specified index.
 int getSize()
          Returns the number of vectors in this Packet
 int getType(int index)
          Returns the type of the vector at the specified index.
 
Methods inherited from class me.edwards.des.net.packet.Packet
getID, lookup, toHex, toString, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

VECTOR_BALLOT

public static final int VECTOR_BALLOT
The Vector type for a Ballot Object

See Also:
Constant Field Values

VECTOR_BLOCK

public static final int VECTOR_BLOCK
The Vector type for a Block Object

See Also:
Constant Field Values

vectors

private java.util.ArrayList<PacketInv.InvVector> vectors
Constructor Detail

PacketInv

public PacketInv()
Creates new PacketInv


PacketInv

public PacketInv(byte[] binary)
Creates new PacketInv from binary data

Parameters:
binary - Packet binary data as byte array
Method Detail

getSize

public int getSize()
Returns the number of vectors in this Packet

Returns:
Number of vectors in this Packet

getType

public int getType(int index)
Returns the type of the vector at the specified index.

Parameters:
index - Index of inventory vector
Returns:
Type of the specified vector if the index exists, otherwise -1.

getHash

public java.lang.String getHash(int index)
Returns the hash of the vector at the specified index.

Parameters:
index - Index of inventory vector
Returns:
Hash of the specified vector if the index exists as a String, otherwise null.

addInv

public void addInv(java.lang.Object invObject)
Adds an inventory object to this Packet.

Parameters:
invObject - Object to add to inventory
Throws:
java.lang.RuntimeException - Thrown if the invObject is not a valid type

getBinary

public byte[] getBinary()
Description copied from class: Packet
Returns the binary payload of this Packet as a byte array.

Specified by:
getBinary in class Packet
Returns:
Binary payload as a byte array