Package org.whiteflagprotocol.java.core
Class WfMessageSegment
java.lang.Object
org.whiteflagprotocol.java.core.WfMessageSegment
Whiteflag message segment class
This is a class representing a segment of a Whiteflag message, i.e. the
message header or the message body. A message segment contains a number of
WfMessageField
s, depending on the segment and the type of the
message. The fields in the segment must be ordered, without missing or
overlapping bytes.
- Since:
- 1.0
- Whiteflag standard x-reference:
- 4.2 Message Header, 4.3 Message Body
-
Constructor Summary
ConstructorDescriptionWfMessageSegment
(WfMessageField[] fields) Constructs a new Whiteflag message segment from an array of message fields, without copying the fields' valuesWfMessageSegment
(WfMessageSegment segment) Constructs a new Whiteflag message segment from another message segment, also copying the fields' values -
Method Summary
Modifier and TypeMethodDescriptionprotected final WfMessageSegment
append
(WfMessageSegment segment) Appends additional fields to this message segment if constructing complex message bodiesfinal int
Returns the bit length of this segment, excluding the last variable length field if not setfinal int
bitLength
(int fieldIndex) Returns the bit length up to and including the specified field, excluding the last variable length field if not setfinal int
Returns the bit length of this segment, excluding the last variable length field if not setfinal int
Returns the byte length of this segment, excluding the last variable length field if not setint
byteLength
(int fieldIndex) Returns the byte length of this segment up to and including the specified field, excluding the last variable length field if not setfinal int
byteLength
(String fieldName) Returns the byte length of this segment, excluding the last variable length field if not setprotected final void
decode
(WfBinaryBuffer buffer, int startBit, int fieldIndex) Decodes this message segment from the provided encoded messageprotected final void
deserialize
(String messageStr, int fieldIndex) Deserializes this message segment from the provided serialized messageprotected final WfBinaryBuffer
encode()
Encodes this message segmentfinal String
get
(int fieldIndex) Gets the value of the field specified by indexfinal String
Gets the value of the field specified by nameprotected final WfMessageField[]
Gets all fields from this message segmentprotected final WfMessageField
getField
(int fieldIndex) Gets the field specified by indexprotected final WfMessageField
Gets the field specified by nameprotected final int
getFieldIndex
(String fieldName) Gets the index of the field specified by nameReturns the field names of the message segmentfinal int
Gets the number of fields in this message segmentfinal boolean
isValid()
Checks if all fields of this message segment contain valid datafinal boolean
Checks if the specified field contains valid datafinal boolean
Checks if the provided data is valid for the specified fieldprotected final String
Serializes this message segmentfinal Boolean
Sets the value of the field specified by its index in the message segmentfinal Boolean
Sets the value of the specified field in the message segmentfinal Boolean
Sets all field values of this segment with values from an arrayfinal Boolean
Sets all field values of this segment with values from an arrayfinal Boolean
Sets all field values of this segment from a fieldname-to-value mappingtoMap()
Gets a fieldname-to-value mapping of this message segmentfinal String
toString()
Returns the message segment as a concatinated string of field values
-
Constructor Details
-
WfMessageSegment
Constructs a new Whiteflag message segment from an array of message fields, without copying the fields' values- Parameters:
fields
- an array of message fields
-
WfMessageSegment
Constructs a new Whiteflag message segment from another message segment, also copying the fields' values- Parameters:
segment
- the message segment to create the new segment from
-
-
Method Details
-
toString
Returns the message segment as a concatinated string of field values -
isValid
public final boolean isValid()Checks if all fields of this message segment contain valid data- Returns:
- TRUE if message segment contains valid data, else FALSE
-
isValid
Checks if the specified field contains valid data- Parameters:
fieldname
- the name of the field- Returns:
- TRUE if the field contains valid data, else FALSE
-
isValid
Checks if the provided data is valid for the specified field- Parameters:
fieldname
- the name of the fielddata
- the value to be checked- Returns:
- TRUE if the field contains valid data, else FALSE
-
bitLength
public final int bitLength()Returns the bit length of this segment, excluding the last variable length field if not set- Returns:
- the bit length of this segment
-
bitLength
Returns the bit length of this segment, excluding the last variable length field if not set- Parameters:
fieldName
- the name of the field up to which the segment length is calculated; negative index counts back from last field- Returns:
- the bit length of this segment, or 0 if the field does not exist
-
bitLength
public final int bitLength(int fieldIndex) Returns the bit length up to and including the specified field, excluding the last variable length field if not set- Parameters:
fieldIndex
- the index of the field up to which the segment length is calculated; negative index counts back from last field- Returns:
- the bit length of this segment up to and including the specified field, or 0 if the field does not exist
-
byteLength
public final int byteLength()Returns the byte length of this segment, excluding the last variable length field if not set- Returns:
- the byte length of this segment
-
byteLength
Returns the byte length of this segment, excluding the last variable length field if not set- Parameters:
fieldName
- the name of the field up to which the segment length is calculated; negative index counts back from last field- Returns:
- the byte length of this segment, or 0 if the field does not exist
-
byteLength
public int byteLength(int fieldIndex) Returns the byte length of this segment up to and including the specified field, excluding the last variable length field if not set- Parameters:
fieldIndex
- the index of the field up to which the segment length is calculated; negative index counts back from last field- Returns:
- the byte length of this segment, , or 0 if the field does not exist
-
getNoFields
public final int getNoFields()Gets the number of fields in this message segment- Returns:
- the number of message segment fields
-
getFieldNames
Returns the field names of the message segment- Returns:
- a string set with all field names
-
get
Gets the value of the field specified by name- Parameters:
fieldname
- the name of the requested field- Returns:
- the field value, or NULL if field does not exist
-
get
Gets the value of the field specified by index- Parameters:
fieldIndex
- the index of the requested field; negative index counts back from last field- Returns:
- the field value, or NULL if field does not exist
-
toMap
Gets a fieldname-to-value mapping of this message segment- Returns:
- a fieldname-to-value mapping
-
set
Sets the value of the specified field in the message segment- Parameters:
fieldname
- the name of the fielddata
- data to be set as the field value- Returns:
- TRUE if field value is set, FALSE if field does not exits, isalready set, or data is invalid
-
set
Sets the value of the field specified by its index in the message segment- Parameters:
fieldIndex
- the index of the requested field; negative index counts back from last fielddata
- data to be set as the field value- Returns:
- TRUE if the data was valid and the field value is set, else FALSE
-
setAll
Sets all field values of this segment from a fieldname-to-value mapping- Parameters:
map
- a fieldname-to-value mapping- Returns:
- TRUE if all field values in this segment were correctly set, else FALSE
-
setAll
Sets all field values of this segment with values from an array- Parameters:
data
- array with the data to be set as the field values- Returns:
- TRUE if the data was valid and all field values are set
- Throws:
WfCoreException
- if the provided data is invalid- Since:
- 1.1
-
setAll
Sets all field values of this segment with values from an array- Parameters:
data
- array with the data to be set as the field valuesstartIndex
- starting position in the array- Returns:
- TRUE if the data was valid and all field values are set
- Throws:
WfCoreException
- if the provided data is invalid- Since:
- 1.1
-
serialize
Serializes this message segment- Returns:
- the serialized message segment
- Throws:
WfCoreException
- if the segment cannot be serialized
-
deserialize
Deserializes this message segment from the provided serialized message- Parameters:
messageStr
- the serialized messagefieldIndex
- the index of the next field to be deserialized- Throws:
WfCoreException
- if the message cannot be deserialized- Since:
- 1.1
-
encode
Encodes this message segment- Returns:
- a binary buffer with the binary encoded message segment
- Throws:
WfCoreException
- if the message cannot be encoded- Since:
- 1.1
-
decode
protected final void decode(WfBinaryBuffer buffer, int startBit, int fieldIndex) throws WfCoreException Decodes this message segment from the provided encoded message- Parameters:
buffer
- the binary buffer with the binary encoded messagestartBit
- the bit position where this segment starts in the encoded messagefieldIndex
- the index of the next field to be decoded- Throws:
WfCoreException
- if the message cannot be decoded- Since:
- 1.1
-
append
Appends additional fields to this message segment if constructing complex message bodies- Parameters:
segment
- the segment to be added to the message segment- Returns:
- this message segment
-
getField
Gets the field specified by name- Parameters:
fieldName
- the name of the requested field- Returns:
- the requested message field, or NULL if it does not exist
-
getFieldIndex
Gets the index of the field specified by name- Parameters:
fieldName
- the name of the requested field- Returns:
- the index of the requested field, or the number of fields if the specified field does not exist
-
getField
Gets the field specified by index- Parameters:
fieldIndex
- the index of the requested field; negative index counts back from last field- Returns:
- the requested message field, or NULL if it does not exist
-
getAllFields
Gets all fields from this message segment- Returns:
- an array with all message fields
-