public abstract class ChannelAccessMessage extends Object
Modifier and Type | Field and Description |
---|---|
protected ChannelAccessCommand |
command
Command (message type) for this message.
|
protected ChannelAccessMessageHeader |
originalMessageHeader
Message header that has been used to construct this message.
|
Modifier and Type | Method and Description |
---|---|
protected static void |
addByteArrayToStringBuilder(StringBuilder sb,
byte[] byteArray)
Creates a string representing a byte array and adds it to a string
builder.
|
protected static int |
calculatePaddingSize(int payloadSize)
Calculates the number of extra padding bytes that are needed to make a
message with the specified payload size aligned to the alignment required
for all Channel Access messages.
|
boolean |
equals(Object obj)
Tells whether the specified object represents the same message.
|
ChannelAccessCommand |
getCommand()
Returns the command for this Channel Access message.
|
protected ChannelAccessMessageHeader |
getOriginalMessageHeader()
Returns the original header that has been used to construct this message.
|
int |
hashCode()
Returns a hash code value for this message.
|
protected boolean |
hasOriginalMessageHeader()
Returns
true if and only if this message has been
constructed from a serialized form and the original message header is
available. |
protected abstract void |
serialize(ByteSink byteSink,
ChannelAccessVersion version,
int maxPayloadSize,
Charset charset)
Serializes this message to a byte sink.
|
protected void |
serializeHeader(ByteSink byteSink,
int payloadSize,
short dataType,
int count,
int cid,
int contextSpecific,
ChannelAccessVersion version,
int maxPayloadSize)
Serializes the header of the message.
|
String |
toString()
Returns a string representation of this message.
|
protected void |
verify(ChannelAccessVersion version,
int maxPayloadSize,
Charset charset)
Verifies that this message can be serialized.
|
protected void |
verifyHeader(int payloadSize,
int count,
ChannelAccessVersion version,
int maxPayloadSize)
Verifies that the message header can be serialized.
|
protected ChannelAccessCommand command
protected ChannelAccessMessageHeader originalMessageHeader
null
if this message has been constructed explicitly instead
of deserializing it from a byte source.protected abstract void serialize(ByteSink byteSink, ChannelAccessVersion version, int maxPayloadSize, Charset charset)
ChannelAccessMessageCodec
.byteSink
- byte sink that is used for writing the serialized data.version
- protocol version to stay compatible with. This is the protocol
version of the peer the message is sent to.maxPayloadSize
- maximum size of the payload.charset
- encoding to use for serializing the string data (e.g. channel
names, error strings, string data-values).SerializedPayloadTooLargeException
- if the payload of the message is larger than
maxPayloadSize
or is larger than 65535 bytes
when a protocol version older than Channel Access version 4.9
is used.SerializedChannelNameTooLargeException
- if the channel name in a CA_PROTO_SEARCH
message
is too large.UnsupportedInThisVersionException
- if this message is not support in the protocol version
specified by version
.UnsupportedOperationException
- if this message has been constructed by deserializing it from
headers only and thus it is incomplete.UnsupportedProtocolVersionException
- if the specified version
is older than the
oldest supported protocol version for this message. In
general, all Channel Access versions since version 4.4 should
be supported.protected ChannelAccessMessageHeader getOriginalMessageHeader()
ChannelAccessMessageCodec
. Calling this method on a message that
has been constructed directly will result in an
UnsupportedOperationException
. You can use
hasOriginalMessageHeader()
to check whether an original
message-header is available. This method is intended to be used by
ChannelAccessErrorMessage
in order to serialize the header of the
message that caused the error.UnsupportedOperationException
- if this message has been constructed from scratch instead of
deserializing it from a byte source.protected void verify(ChannelAccessVersion version, int maxPayloadSize, Charset charset)
ChannelAccessMessageCodec
.version
- protocol version to stay compatible with. This is the protocol
version of the peer the message is sent to.maxPayloadSize
- maximum size of the payload.charset
- encoding to use for serializing the string data (e.g. channel
names, error strings, string data-values).SerializedPayloadTooLargeException
- if the payload of the message is larger than
maxPayloadSize
or is larger than 65535 bytes
when a protocol version older than Channel Access version 4.9
is used.SerializedChannelNameTooLargeException
- if the channel name in a CA_PROTO_SEARCH
message
is too large.UnsupportedInThisVersionException
- if this message is not support in the protocol version
specified by version
.UnsupportedOperationException
- if this message has been constructed by deserializing it from
headers only and thus it is incomplete.UnsupportedProtocolVersionException
- if the specified version
is older than the
oldest supported protocol version for this message. In
general, all Channel Access versions since version 4.4 should
be supported.protected void verifyHeader(int payloadSize, int count, ChannelAccessVersion version, int maxPayloadSize)
payloadSize
- size of the payload. Payload sizes greater than 0xfff8 are
only supported since Channel Access version 4.9.count
- "count" field. The meaning depends on the message type. Counts
greater than 0xffff are only supported since ChannelAccess
version 4.9 and are only valid if the value of the count field
is actually an element count.version
- version of the Channel Access protocol. The protocol version
defines the available features. In particular, message with a
payload or count greater than 0xfff are only supported since
Channel Access version 4.9.maxPayloadSize
- the maximum payload size to use. This method ensures that the
payload size is not larger than this value.IllegalArgumentException
- if payloadSize
or count
are
negative or if payloadSize
is not a multiple of
8.SerializedPayloadTooLargeException
- if payloadSize
is larger than
maxPayloadSize
or if payloadSize
or
count
are larger than 0xffff and
version
is not at least
ChannelAccessVersion.V4_9
.protected boolean hasOriginalMessageHeader()
true
if and only if this message has been
constructed from a serialized form and the original message header is
available. This means that a call to getOriginalMessageHeader()
will return a valid object.true
if the original message header is available,
false
otherwise.protected void serializeHeader(ByteSink byteSink, int payloadSize, short dataType, int count, int cid, int contextSpecific, ChannelAccessVersion version, int maxPayloadSize)
byteSink
- byte sink that is used for serializing the message header.payloadSize
- size of the payload. Payload sizes greater than 0xfff8 are
only supported since Channel Access version 4.9.dataType
- "data-type" field. The meaning of this field depends on the
message type.count
- "count" field. The meaning depends on the message type. Counts
greater than 0xffff are only supported since ChannelAccess
version 4.9 and are only valid if the value of the count field
is actually an element count.cid
- "cid" field. The meaning of this field depends on the message
type.contextSpecific
- "available" field. The meaning of this field depends on the
message type.version
- version of the Channel Access protocol. The protocol version
defines the available features. In particular, message with a
payload or count greater than 0xfff are only supported since
Channel Access version 4.9.maxPayloadSize
- the maximum payload size to use. This method ensures that the
payload size is not larger than this value.IllegalArgumentException
- if payloadSize
or count
are
negative or if payloadSize
is not a multiple of
8.SerializedPayloadTooLargeException
- if payloadSize
is larger than
maxPayloadSize
or if payloadSize
or
count
are larger than 0xffff and
version
is not at least
ChannelAccessVersion.V4_9
.protected static int calculatePaddingSize(int payloadSize)
payloadSize
- payload size (in bytes) that is actually needed for the data.public ChannelAccessCommand getCommand()
null
).public boolean equals(Object obj)
Tells whether the specified object represents the same message.
Two messages are considered equal if they are of the same type and have the same headers and payload. For comparing the types, the actual Java type and not just the Channel Access command is compared.
equals
in class Object
obj
- reference object with which this object is compared.true
if obj
is a message that is of the
same type and has the same headers and payload as this message.
false
if obj
is null
or of
a different type than this message or differs in the headers or
payload.public int hashCode()
Returns a hash code value for this message. This method is supported for the benefit of hash tables. The hash code is calculated as a combination of the hash codes of this messages headers (including the Channel Access command) and its payload (if present).
If two messages are equal (as indicated by the return value of
equals(Object)
), they also have the same hash code. However, the
fact that two messages have the same hash code does not imply that they
are equal.
public String toString()
protected static void addByteArrayToStringBuilder(StringBuilder sb, byte[] byteArray)
sb
- string builder to which the string representation of the byte
array should be appended.byteArray
- byte array that should be printed.Copyright © 2014–2017 aquenos GmbH. All rights reserved.