Class BinaryField


  • public class BinaryField
    extends Field
    A binary field holds an arbitrary sequence of bytes whose length is determined by the 4-byte big-endian integer that follows the type tag.
    Author:
    James Elliott
    • Constructor Summary

      Constructors 
      Constructor Description
      BinaryField​(byte[] bytes)
      Constructor for code.
      BinaryField​(DataInputStream is)
      Constructor for reading from the network.
    • 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.
      ByteBuffer getValue()
      Get the bytes which represent the payload of this field, without the leading type tag and length header.
      byte[] getValueAsArray()
      Get the bytes which represent the payload of this field, without the leading type tag and length header, as a newly-allocated byte array.
      String toString()  
      • Methods inherited from class org.deepsymmetry.beatlink.dbserver.Field

        read, write
    • Constructor Detail

      • BinaryField

        public BinaryField​(DataInputStream is)
                    throws IOException
        Constructor for reading from the network.
        Parameters:
        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.
      • BinaryField

        public BinaryField​(byte[] bytes)
        Constructor for code.
        Parameters:
        bytes - the value that this field will convey.
    • Method Detail

      • getValue

        public ByteBuffer getValue()
        Get the bytes which represent the payload of this field, without the leading type tag and length header.
        Returns:
        the bytes whose purpose this field exists to convey.
      • getValueAsArray

        public byte[] getValueAsArray()
        Get the bytes which represent the payload of this field, without the leading type tag and length header, as a newly-allocated byte array.
        Returns:
        a new byte array containing a copy of the bytes 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.
      • 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.
      • 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.