|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objecteap.freeciv.Field
eap.freeciv.BinaryField
Constructor Summary | |
BinaryField()
|
Method Summary | |
void |
addIndex(int index)
Alter the way this field references its data, so as to append an index. |
int |
getSize(Packet packet)
Returns the size of this field in bytes, given the values stored in a paket. |
boolean |
isSet(Packet packet)
Returns true if the value(s) for this field are set in the given packet |
void |
read(Packet packet,
PacketSource source)
Read the field from the given source and write its contents to the given packet. |
void |
removeIndex()
Reverse the effects of the last call to addIndex(int) |
void |
setName(String name)
|
void |
setSize(String size)
|
void |
write(Packet packet,
OutputStream out)
Write this field to the given stream, taking values from the given packet. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public BinaryField()
Method Detail |
public void setName(String name)
public void addIndex(int index)
Field
Field.removeIndex()
. Multiple calls to this
method are cumulative - i.e. a field can have multiple indices.
This is used by arrays. The typical procedure is to iterate over array elements, set the index in each component field, perform some operation, and then remove the index. The nice thing about this way of doing things is that an array can contain any type of field, including other arrays. The drawback is that you have to be very careful that the indices always get removed after use. Otherwise the structure could get into an invalid state. A related problem is that it violates the rule that packet structures are reusable, since two separate threads could be trying to add indices to the same field at the same time. So far this hasn't been a problem, since the indices stay on the field for a very short time. Also, in practice one thread handles client to server trafic and the other handles server to client trafic, and these generally use different packet types. Initially I set the index in the packet, but I ripped that out because it set the array for all fields. But to be thread safe I would have to go back to something like that, but specific to one keyword.
addIndex
in class Field
ArrayField
public void removeIndex()
Field
Field.addIndex(int)
removeIndex
in class Field
public boolean isSet(Packet packet)
Field
isSet
in class Field
public void setSize(String size)
public void read(Packet packet, PacketSource source) throws IOException
Field
read
in class Field
IOException
public void write(Packet packet, OutputStream out) throws IOException
Field
write
in class Field
IOException
public int getSize(Packet packet)
Field
getSize
in class Field
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |