|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objecteap.freeciv.PacketStructure
Describes the way a packet is encoded in a data stream.
A structure consistes of an ordered list of Field
objects.
Generally you get a structure from a PacketBroker
, which in turn reads
a configuration file. Note that the structure does not
store any of the packet data. However, the structure knows how to read the
data from a stream and store it in a Packet
. By separating storage
and structure, we can create one structure object for each packet type,
and reuse it for every packet of that type. This avoids having to re-read
the configuration for every packet.
Constructor Summary | |
PacketStructure()
Create a new structure with no fields. |
Method Summary | |
void |
addField(Field field)
Append a field to the end of this structure. |
void |
read(Packet packet,
PacketSource source)
Read the packet from the given source and store its values in the given packet. |
int |
size(Packet packet)
Calculate the size of the body of a given packet in bytes. |
void |
write(Packet packet,
OutputStream out)
Write the body of the given packet to the given output stream. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public PacketStructure()
Method Detail |
public void addField(Field field)
public void read(Packet packet, PacketSource source) throws IOException
IOException
public void write(Packet packet, OutputStream out) throws IOException
Packet.write(OutputStream)
writes the packet header and then calls this method.
IOException
public int size(Packet packet)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |