Package org.whiteflagprotocol.java.core
Class WfMessageField
java.lang.Object
org.whiteflagprotocol.java.core.WfMessageField
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
Modifier and TypeFieldDescriptionfinal WfMessageCodec.Encoding
The encoding of the fieldfinal int
The ending byte (not included) of the field in a serialized / uncompressed messagefinal String
The name of the fieldfinal Pattern
The regex pattern defining allowed valuesfinal int
The starting byte of the field in a serialized / uncompressed message -
Method Summary
Modifier and TypeMethodDescriptionfinal int
Gets the bit length of the encoded fieldfinal int
Gets the byte length of the unencoded field valueprotected final String
Gives debug information of the fieldfinal String
decode
(byte[] data) Decodes the compressed binary data and sets field valuestatic final WfMessageField
define
(String name, String pattern, WfMessageCodec.Encoding encoding, int startByte, int endByte) Defines a new Whiteflag message fieldfinal byte[]
encode()
Encodes the message field into compressed binary datastatic final WfMessageField
from
(WfMessageField field) Creates a new Whiteflag message field from an existing field, without copying the valuestatic final WfMessageField
from
(WfMessageField field, int shift) Creates a new Whiteflag message field from an existing field, without copying the valuefinal String
get()
Gets the value of the message fieldfinal boolean
isSet()
Checks if the message field value has been setfinal boolean
isValid()
Checks if the message field contains a valid valuefinal boolean
Checks if the provided data is a valid value for this fieldfinal Boolean
Sets the value of the message field if not already setfinal String
toString()
Returns the message field as a string
-
Field Details
-
name
The name of the field -
pattern
The regex pattern defining allowed values -
encoding
The encoding of the field -
startByte
public final int startByteThe starting byte of the field in a serialized / uncompressed message -
endByte
public final int endByteThe 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 fieldpattern
- the regex pattern defining allowed values; if null the generic encoding regex is usedencoding
- the encoding of the fieldstartByte
- the starting byte of the field in a serialized / uncompressed messageendByte
- 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
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
Creates a new Whiteflag message field from an existing field, without copying the value- Parameters:
field
- the message field to copyshift
- number of bytes to shift the field- Returns:
- a new message field
-
toString
Returns the message field as a string -
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
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
Gets the value of the message field- Returns:
- the field value
-
set
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
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
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
Gives debug information of the field- Returns:
- field name, value and pattern and validity check
-