Esempio n. 1
0
        /// <summary>
        /// Creates an EmberSet object with the passed BerType. Convenience method
        /// to be called from an overridden CreateNodeFromReader method.
        /// </summary>
        protected EmberNode CreateSet(uint type, BerReaderBase reader)
        {
            var tag  = reader.Tag;
            var node = new EmberSet(tag, null);

            node.BerTypeNumber = type;
            return(node);
        }
Esempio n. 2
0
        /// <summary>
        /// Creates a container of an application-defined type with Set semantics
        /// </summary>
        /// <param name="type">Application-defined type. BerType.ApplicationFlag can be omitted.</param>
        public static EmberSet CreateApplicationDefinedSet(BerTag tag, uint type, EmberContainer parent)
        {
            var set = new EmberSet(tag, parent)
            {
                BerTypeNumber = type | BerType.ApplicationFlag
            };

            return(set);
        }
Esempio n. 3
0
        /// <summary>
        /// Creates an EmberSet object with the passed BerType. Convenience method
        /// to be called from an overridden CreateNodeFromXml method.
        /// </summary>
        protected EmberNode CreateSet(uint type, BerTag tag, XmlReader reader)
        {
            var node = new EmberSet(tag, null, true)
            {
                BerTypeNumber = type
            };

            return(node);
        }
Esempio n. 4
0
        /// <summary>
        /// Creates a new EmberNode from the TLV the passed BER reader is currently positioned on.
        /// </summary>
        /// <param name="reader">The BER reader to create the node from.</param>
        /// <param name="application">The application interface responsible for creating nodes
        /// with application-defined types.</param>
        /// <returns>A new instance of EmberNode representing the read TLV or null
        /// if the TLV could not be decoded into an EmberNode.
        /// This happens if the TLV has an unsupported type.</returns>
        internal static EmberNode FromReader(BerReaderBase reader, EmberApplicationInterface application)
        {
            var node = null as EmberNode;
            var type = reader.Type;
            var tag  = reader.Tag;

            if (reader.IsContainer)
            {
                switch (type)
                {
#pragma warning disable 618 // EmberFrame is obsolete
                case BerType.Sequence:
                    node = tag == Legacy.EmberFrame.FrameTag
                         ? new Legacy.EmberFrame()
                         : new EmberSequence(tag, null);
                    break;
#pragma warning restore 618

                case BerType.Set:
                    node = new EmberSet(tag);
                    break;

                default:
                {
                    if (application != null)
                    {
                        node = application.CreateNodeFromReader(type, reader);
                    }

                    if (node == null)
                    {
                        Debug.WriteLine("WARNING: Unknown BER container type: " + type);

                        node = new EmberContainer(tag, null, type);
                    }
                    break;
                }
                }
            }
            else
            {
                switch (type)
                {
                case BerType.Boolean:
                    node = new BooleanEmberLeaf(tag, reader.GetBoolean());
                    break;

                case BerType.Integer:
                    if (reader.Length > 4)
                    {
                        node = new LongEmberLeaf(tag, reader.GetLong());
                    }
                    else
                    {
                        node = new IntegerEmberLeaf(tag, reader.GetInteger());
                    }
                    break;

                case BerType.Real:
                    node = new RealEmberLeaf(tag, reader.GetReal());
                    break;

                case BerType.UTF8String:
                    node = new StringEmberLeaf(tag, reader.GetString());
                    break;

                case BerType.OctetString:
                    node = new OctetStringEmberLeaf(tag, reader.GetOctetString());
                    break;

                case BerType.RelativeOid:
                    node = new RelativeOidEmberLeaf(tag, reader.GetRelativeOid());
                    break;

                case BerType.ObjectIdentifier:
                    node = new ObjectIdentifierEmberLeaf(tag, reader.GetObjectIdentifier());
                    break;

                case BerType.Null:
                    node = new NullEmberLeaf(tag);
                    break;

                default:
                    Debug.WriteLine("Unknown BER value type: " + type);
                    break;
                }
            }

            return(node);
        }