Opc.Ua.BinaryDecoder.DecodeMessage C# (CSharp) Method

DecodeMessage() public method

Decodes an object from a buffer.
public DecodeMessage ( System expectedType ) : IEncodeable
expectedType System
return IEncodeable
        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;
        }

Same methods

BinaryDecoder::DecodeMessage ( Stream stream, System expectedType, ServiceMessageContext context ) : IEncodeable
BinaryDecoder::DecodeMessage ( byte buffer, System expectedType, ServiceMessageContext context ) : IEncodeable

Usage Example

コード例 #1
0
        /// <summary>
        /// Decodes a message from a buffer.
        /// </summary>
        public static IEncodeable DecodeMessage(byte[] buffer, System.Type expectedType, ServiceMessageContext context)
        {
            if (buffer  == null) throw new ArgumentNullException("buffer");
            if (context == null) throw new ArgumentNullException("context");

            BinaryDecoder decoder = new BinaryDecoder(buffer, context);

            try
            {
                return decoder.DecodeMessage(expectedType);
            }
            finally
            {
                decoder.Close();
            }
        }