- java.lang.Object
-
- org.deepsymmetry.beatlink.dbserver.Field
-
- org.deepsymmetry.beatlink.dbserver.NumberField
-
@API(status=STABLE) public class NumberField extends Field
A number field represents an integer, and can take up 1, 2, or 4 bytes, depending on the tag which introduces it.- Author:
- James Elliott
-
-
Field Summary
Fields Modifier and Type Field Description static NumberField
WORD_0
A four-byte field representing the number zero, used in many requests, so they can save the time and garbage of constructing throwaway versions.static NumberField
WORD_1
A four-byte field representing the number one, used in some requests, so they can save the time and garbage of constructing throwaway versions.
-
Constructor Summary
Constructors Constructor Description NumberField(byte typeTag, DataInputStream is)
Constructor for reading from the network.NumberField(long value)
Convenience constructor from code, for the most common case of wanting a 4-byte number field.NumberField(long value, int size)
Constructor from code.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description byte
getArgumentTag()
Get the value which identifies this type of field in a message argument list.ByteBuffer
getBytes()
Get the bytes which represent this field when sent over the network, including the leading type tag.long
getSize()
Get the size, in bytes, of the network representation of this field, excluding the leading type tag and length bytes (if any).byte
getTypeTag()
Get the value which identifies the start of this field in the network stream.long
getValue()
Get the numeric value this field represents.String
toString()
-
-
-
Field Detail
-
WORD_0
@API(status=STABLE) public static final NumberField WORD_0
A four-byte field representing the number zero, used in many requests, so they can save the time and garbage of constructing throwaway versions.
-
WORD_1
@API(status=STABLE) public static final NumberField WORD_1
A four-byte field representing the number one, used in some requests, so they can save the time and garbage of constructing throwaway versions.
-
-
Constructor Detail
-
NumberField
@API(status=STABLE) public NumberField(byte typeTag, DataInputStream is) throws IOException
Constructor for reading from the network.- Parameters:
typeTag
- the tag which identified this field as a NumberField, and which allows us to determine the proper size.is
- the stream on which the field value is to be read.- Throws:
IllegalArgumentException
- if tag is not a valid number field tag.IOException
- if there is a problem reading the value.
-
NumberField
@API(status=STABLE) public NumberField(long value, int size)
Constructor from code.- Parameters:
value
- the desired value to be represented by this field.size
- the number of bytes to be used to hold the value: 1, 2, or 4.- Throws:
IllegalArgumentException
- if the specified size is not a supported number field size.
-
NumberField
@API(status=STABLE) public NumberField(long value)
Convenience constructor from code, for the most common case of wanting a 4-byte number field.- Parameters:
value
- the desired value to be represented by this field.
-
-
Method Detail
-
getValue
@API(status=STABLE) public long getValue()
Get the numeric value this field represents.- Returns:
- the number which this field contains.
-
getTypeTag
public byte getTypeTag()
Description copied from class:Field
Get the value which identifies the start of this field in the network stream.- Specified by:
getTypeTag
in classField
- Returns:
- the tag which tells the recipient that this particular type of field is coming.
-
getArgumentTag
public byte getArgumentTag()
Description copied from class:Field
Get the value which identifies this type of field in a message argument list.- Specified by:
getArgumentTag
in classField
- Returns:
- the tag which is used instead of the type tag for some reason when putting together the argument type list for a dbserver message.
-
getSize
public long getSize()
Description copied from class:Field
Get the size, in bytes, of the network representation of this field, excluding the leading type tag and length bytes (if any).
-
getBytes
public ByteBuffer getBytes()
Description copied from class:Field
Get the bytes which represent this field when sent over the network, including the leading type tag.
-
-