Class WfMessageField

java.lang.Object
org.whiteflagprotocol.java.core.WfMessageField

public final class WfMessageField extends Object
Whiteflag message field class

This class represents a Whiteflag message field. Instances of this class represent specific fields in specific message types. A field is defined by a number of properties: name, allowed values, encoding, starting byte and ending byte. The field is considered set if it contains a valid value. Its value cannot be changed once set.

Since:
1.0
Whiteflag standard x-reference:
4.1 Message Structure
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    The encoding of the field
    final int
    The ending byte (not included) of the field in a serialized / uncompressed message
    final String
    The name of the field
    final Pattern
    The regex pattern defining allowed values
    final int
    The starting byte of the field in a serialized / uncompressed message
  • Method Summary

    Modifier and Type
    Method
    Description
    final int
    Gets the bit length of the encoded field
    final int
    Gets the byte length of the unencoded field value
    protected final String
    Gives debug information of the field
    final String
    decode(byte[] data)
    Decodes the compressed binary data and sets field value
    static final WfMessageField
    define(String name, String pattern, WfMessageCodec.Encoding encoding, int startByte, int endByte)
    Defines a new Whiteflag message field
    final byte[]
    Encodes the message field into compressed binary data
    static final WfMessageField
    Creates a new Whiteflag message field from an existing field, without copying the value
    static final WfMessageField
    from(WfMessageField field, int shift)
    Creates a new Whiteflag message field from an existing field, without copying the value
    final String
    get()
    Gets the value of the message field
    final boolean
    Checks if the message field value has been set
    final boolean
    Checks if the message field contains a valid value
    final boolean
    Checks if the provided data is a valid value for this field
    final Boolean
    set(String data)
    Sets the value of the message field if not already set
    final String
    Returns the message field as a string

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • name

      public final String name
      The name of the field
    • pattern

      public final Pattern pattern
      The regex pattern defining allowed values
    • encoding

      public final WfMessageCodec.Encoding encoding
      The encoding of the field
    • startByte

      public final int startByte
      The starting byte of the field in a serialized / uncompressed message
    • endByte

      public final int endByte
      The ending byte (not included) of the field in a serialized / uncompressed message
  • Method Details

    • define

      public static final WfMessageField define(String name, String pattern, WfMessageCodec.Encoding encoding, int startByte, int endByte)
      Defines a new Whiteflag message field
      Parameters:
      name - the name of the message field
      pattern - the regex pattern defining allowed values; if null the generic encoding regex is used
      encoding - the encoding of the field
      startByte - the starting byte of the field in a serialized / uncompressed message
      endByte - the ending byte (not included) of the field in a serialized / uncompressed message; ignored if encoding requires a fixed field length
      Returns:
      a new message field
      Since:
      1.1
      Whiteflag standard x-reference:
      4.1.2 Encoding
    • from

      public static final WfMessageField from(WfMessageField field)
      Creates a new Whiteflag message field from an existing field, without copying the value
      Parameters:
      field - the message field to copy
      Returns:
      a new message field
    • from

      public static final WfMessageField from(WfMessageField field, int shift)
      Creates a new Whiteflag message field from an existing field, without copying the value
      Parameters:
      field - the message field to copy
      shift - number of bytes to shift the field
      Returns:
      a new message field
    • toString

      public final String toString()
      Returns the message field as a string
      Overrides:
      toString in class Object
      Returns:
      the value of the message field
      See Also:
    • isSet

      public final boolean isSet()
      Checks if the message field value has been set
      Returns:
      TRUE if the field has been set, else FALSE
    • isValid

      public final boolean isValid()
      Checks if the message field contains a valid value
      Returns:
      TRUE if the field contains a valid value, else FALSE
    • isValid

      public final boolean isValid(String data)
      Checks if the provided data is a valid value for this field
      Parameters:
      data - The data to be checked
      Returns:
      TRUE if data is a valid value for this field
    • byteLength

      public final int byteLength()
      Gets the byte length of the unencoded field value
      Returns:
      the byte length of the unencoded field value
    • bitLength

      public final int bitLength()
      Gets the bit length of the encoded field
      Returns:
      the bit length of the compressed encoded field value
    • get

      public final String get()
      Gets the value of the message field
      Returns:
      the field value
    • set

      public final Boolean set(String data)
      Sets the value of the message field if not already set
      Parameters:
      data - the data representing the field value
      Returns:
      TRUE if field value is set, FALSE if field already set or data is invalid
    • encode

      public final byte[] encode() throws WfCoreException
      Encodes the message field into compressed binary data
      Returns:
      a byte array with the compressed binary encoded field value
      Throws:
      WfCoreException - if the field cannot be encoded
      Since:
      1.1
    • decode

      public final String decode(byte[] data) throws WfCoreException
      Decodes the compressed binary data and sets field value
      Parameters:
      data - a byte array with the compressed binary encoded field value
      Returns:
      TRUE is the field could be correctly decoded and set, else FALSE
      Throws:
      WfCoreException - if decoding is not possible
      Since:
      1.1
    • debugInfo

      protected final String debugInfo()
      Gives debug information of the field
      Returns:
      field name, value and pattern and validity check