Esempio n. 1
0
            private void ReadPacketHeader()
            {
                ProtocolVersion     = m_Reader.ReadByte();
                NetworkMessageFlags = m_Reader.ReadByte();
                PublisherId         = m_Reader.ReadGuid();
                SecurityTokenId     = m_Reader.ReadUInt32();
                NonceLength         = m_Reader.ReadByte();
                Nonce = new byte[NonceLength];
                for (int i = 0; i < NonceLength; i++)
                {
                    Nonce[i] = m_Reader.ReadByte();
                }
                m_MessageCount = m_Reader.ReadByte();
                List <ushort> _ids = new List <ushort>();

                for (int i = 0; i < MessageCount; i++)
                {
                    _ids.Add(m_Reader.ReadUInt16());
                }
                m_DataSetWriterIds = new ReadOnlyCollection <ushort>(_ids);
            }
        /// <summary>
        /// Reads an instance of <see cref="IVariant" /> from UA Binary encoded stream.
        /// </summary>
        /// <param name="decoder">The decoder <see cref="IBinaryDecoder" /> to be used to read form the stream.</param>
        /// <returns>The <see cref="IVariant" /> decoded from the UA binary stream of bytes.</returns>
        public IVariant ReadVariant(IBinaryDecoder decoder)
        {
            byte encodingByte = decoder.ReadByte(); //Read the EncodingMask

            if (encodingByte == 0x0)
            {
                return(null);
            }
            Variant     value       = null;
            BuiltInType builtInType = (BuiltInType)(encodingByte & (byte)VariantEncodingMask.TypeIdMask);

            if ((encodingByte & (byte)VariantEncodingMask.IsArray) == 0)
            {
                value = ReadValue(decoder, builtInType);
            }
            else
            {
                Array array = DecodeArray(decoder, builtInType, ((encodingByte & (byte)VariantEncodingMask.ArrayDimensionsPresents) != 0));
                value = new Variant(array, builtInType);
            }
            return(value);
        }
        //methods
        private Variant ReadValue(IBinaryDecoder encoder, BuiltInType encodingByte)
        {
            switch (encodingByte)
            {
            case BuiltInType.Boolean:
                return(new Variant(encoder.ReadBoolean(), encodingByte));

            case BuiltInType.SByte:
                return(new Variant(encoder.ReadSByte(), encodingByte));

            case BuiltInType.Byte:
                return(new Variant(encoder.ReadByte(), encodingByte));

            case BuiltInType.Int16:
                return(new Variant(encoder.ReadInt16(), encodingByte));

            case BuiltInType.UInt16:
                return(new Variant(encoder.ReadUInt16(), encodingByte));

            case BuiltInType.Int32:
            case BuiltInType.Enumeration:
                return(new Variant(encoder.ReadInt32(), encodingByte));

            case BuiltInType.UInt32:
                return(new Variant(encoder.ReadUInt32(), encodingByte));

            case BuiltInType.Int64:
                return(new Variant(encoder.ReadInt64(), encodingByte));

            case BuiltInType.UInt64:
                return(new Variant(encoder.ReadUInt64(), encodingByte));

            case BuiltInType.Float:
                return(new Variant(encoder.ReadSingle(), encodingByte));

            case BuiltInType.Double:
                return(new Variant(encoder.ReadDouble(), encodingByte));

            case BuiltInType.String:
                return(new Variant(ReadString(encoder), encodingByte));

            case BuiltInType.DateTime:
                return(new Variant(ReadDateTime(encoder), encodingByte));

            case BuiltInType.Guid:
                return(new Variant(ReadGuid(encoder), encodingByte));

            case BuiltInType.ByteString:
                return(new Variant(ReadByteString(encoder), encodingByte));

            case BuiltInType.XmlElement:
                return(new Variant(ReadXmlElement(encoder), encodingByte));

            case BuiltInType.NodeId:
                return(new Variant(ReadNodeId(encoder), encodingByte));

            case BuiltInType.ExpandedNodeId:
                return(new Variant(ReadExpandedNodeId(encoder), encodingByte));

            case BuiltInType.StatusCode:
                return(new Variant(ReadStatusCode(encoder), encodingByte));

            case BuiltInType.QualifiedName:
                return(new Variant(ReadQualifiedName(encoder), encodingByte));

            case BuiltInType.LocalizedText:
                return(new Variant(ReadLocalizedText(encoder), encodingByte));

            case BuiltInType.ExtensionObject:
                return(new Variant(ReadExtensionObject(encoder), encodingByte));

            case BuiltInType.DataValue:
                return(new Variant(ReadDataValue(encoder), encodingByte));

            default:
                throw new ArgumentOutOfRangeException($"Cannot decode unknown type in Variant object (0x{encodingByte:X}).");
            }
        }