public IEncodeable DecodeMessage(System.Type expectedType)
{
long start = m_istrm.Position;
// read the node id.
NodeId typeId = ReadNodeId(null);
// convert to absolute node id.
ExpandedNodeId absoluteId = NodeId.ToExpandedNodeId(typeId, m_context.NamespaceUris);
// lookup message type.
Type actualType = m_context.Factory.GetSystemType(absoluteId);
if (actualType == null)
{
throw new ServiceResultException(StatusCodes.BadEncodingError, Utils.Format("Cannot decode message with type id: {0}.", absoluteId));
}
// read the message.
IEncodeable message = ReadEncodeable(null, actualType);
// check that the max message size was not exceeded.
if (m_context.MaxMessageSize > 0 && m_context.MaxMessageSize < (int)(m_istrm.Position - start))
{
throw ServiceResultException.Create(
StatusCodes.BadEncodingLimitsExceeded,
"MaxMessageSize {0} < {1}",
m_context.MaxMessageSize,
(int)(m_istrm.Position - start));
}
// return the message.
return message;
}