Class 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.
    • 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 class Field
        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 class Field
        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).
        Specified by:
        getSize in class Field
        Returns:
        the number of bytes which will be written after the type tag (and length indicator, if present) when sending this field.
      • 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.
        Specified by:
        getBytes in class Field
        Returns:
        a freshly rewound buffer containing the full set of bytes which should be transmitted for this field.