/// <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); }
/// <summary> /// Creates a new instance of EmberContainer. /// </summary> /// <param name="tag">The tag of the new node.</param> /// <param name="parent">The parent to insert the new node into.</param> /// <param name="type">The BerType of the new node.</param> public EmberContainer(BerTag tag, EmberContainer parent, uint type) : base(tag) { BerTypeNumber = type; if (parent != null) { parent.InsertChildNode(this); } }
static void Decode_Recurse(EmberReader reader, EmberContainer parent, EmberApplicationInterface application) { while (reader.Read()) { var node = FromReader(reader, application); if (node != null) { var container = node as EmberContainer; if (container != null) { var childReader = new EmberReader(reader); Decode_Recurse(childReader, container, application); } node.ValidateAfterDecode(); parent.InsertChildNode(node); } } }
/// <summary> /// Creates a new instance of EmberSequence. /// </summary> /// <param name="tag">The tag for the newly created node.</param> /// <param name="parent">The parent container to insert this node into.</param> public EmberSequence(BerTag tag, EmberContainer parent = null) : base(tag, parent, BerType.Sequence) { }
/// <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); }
/// <summary> /// Creates a container of an application-defined type with Sequence semantics /// </summary> /// <param name="type">Application-defined type. BerType.ApplicationFlag can be omitted.</param> public static EmberSequence CreateApplicationDefinedSequence(BerTag tag, uint type, EmberContainer parent, bool isOrdered = false) { var sequence = new EmberSequence(tag, parent) { BerTypeNumber = type | BerType.ApplicationFlag, IsOrdered = isOrdered, }; return(sequence); }
/// <summary> /// Creates a new instance of EmberSet, turning on safe mode. /// </summary> /// <param name="tag">The tag for the newly created node.</param> /// <param name="parent">The parent container to insert this node into. /// It is usually better to use one of the other constructors /// and insert the sequence into its parent container only when /// all children have been added to the sequence.</param> public EmberSet(BerTag tag, EmberContainer parent) : this(tag, parent, true) { }
/// <summary> /// Creates a new instance of EmberSet. /// </summary> /// <param name="tag">The tag for the newly created node.</param> /// <param name="parent">The parent container to insert this node into. /// It is usually better to use one of the other constructors /// and insert the sequence into its parent container only when /// all children have been added to the sequence.</param> /// <param name="isSafeMode">If true, multiple occurrences of one tag /// are disallowed for the children of the EmberSet. If a node with /// an already existing tag is inserted into the set, an exception is /// thrown.</param> public EmberSet(BerTag tag, EmberContainer parent, bool isSafeMode) : base(tag, parent, BerType.Set) { IsMapUsed = isSafeMode; }