|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objecteap.freeciv.Field
eap.freeciv.SimpleField
Represents a field with a name and a single value. Note that "single value" means that its value is represented by a single object in a packet, so it includes things like a WorkList, where several values are encoded in a single object. This is an abstract class which handles a number of general properties of fields, but does not understand the actual data format.
A field may be optional, meaning it should be written only if it is defined in the packet, and it should be read only if there are bytes remaining in the packet.
A field may be present only if a given condition is met. The definition of
this condition is a bit nebulous - so the best way to understand it would be
to read the source code for testCondition(Packet)
. I think
there is only one field in all of freeciv which uses this.
A field may have a scale factor. Numerical valued fields should multiply the raw value by this scale factor.
Constructor Summary | |
protected |
SimpleField()
Create a new simple field. |
Method Summary | |
void |
addIndex(int index)
Adds the given index in brackets to the end of the name of this field. |
String |
getname()
Returns the name of this field. |
int |
getSize(Packet packet)
Returns the size of this field. |
abstract int |
getValueSize(Packet packet)
Returns the size of the data in this field. |
boolean |
isOptional()
Indicates whether this field is optional. |
boolean |
isSet(Packet packet)
Returns true if the packet has a value with the same name as this field. |
void |
read(Packet packet,
PacketSource source)
Read the value from the packet if it is present. |
protected abstract void |
readValue(Packet packet,
PacketSource source)
Read the data in this field from the packet. |
void |
removeIndex()
Reverse the effects of the last call to addIndex(int) |
void |
setCondition(String condition)
Set a string describing a condition for whether this field should appear in the packet. |
void |
setName(String name)
Set the name of this field. |
void |
setOptional(boolean optional)
Set whether this field is optional |
void |
setScale(double scale)
Set the scale factor for this packet. |
protected boolean |
testCondition(Packet packet)
Evaluate a test condition to see if a packets contains this field. |
void |
write(Packet packet,
OutputStream out)
Write this field if it is present in the packet. |
protected abstract void |
writeValue(Object value,
OutputStream out)
Write the data in this field. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
protected SimpleField()
Method Detail |
public void setName(String name)
public String getname()
public void addIndex(int index)
addIndex
in class Field
Field.addIndex(int)
public void removeIndex()
Field
Field.addIndex(int)
removeIndex
in class Field
public boolean isSet(Packet packet)
isSet
in class Field
public void setOptional(boolean optional)
public boolean isOptional()
public void setCondition(String condition)
testCondition(Packet)
public void setScale(double scale)
protected abstract void readValue(Packet packet, PacketSource source) throws IOException
read(eap.freeciv.Packet, eap.freeciv.PacketSource)
method
determines whether this field should appear in the packet and then calls
this method to read the actual data.
IOException
protected abstract void writeValue(Object value, OutputStream out) throws IOException
write(eap.freeciv.Packet, java.io.OutputStream)
method
determines whether this field should appear in the packet and then calls
this method to write the actual data.
IOException
public abstract int getValueSize(Packet packet)
getSize(Packet)
method determines whether the packet contains this field and then
calls this method to return its size.
public final void read(Packet packet, PacketSource source) throws IOException
readValue(Packet, PacketSource)
to specify how the data are
encoded.
read
in class Field
IOException
public final void write(Packet packet, OutputStream out) throws IOException
writeValue(Object, OutputStream)
to specify how the data are
encoded.
write
in class Field
IOException
protected boolean testCondition(Packet packet) throws IOException
IOException
public final int getSize(Packet packet)
getValueSize(Packet)
to determine the size.
getSize
in class Field
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |