/// <summary> /// Creates an EmberSequence object with the passed BerType. Convenience method /// to be called from an overridden CreateNodeFromReader method. /// </summary> protected EmberNode CreateSequence(uint type, BerReaderBase reader) { var tag = reader.Tag; var node = new EmberSequence(tag, null); node.BerTypeNumber = type; return(node); }
public override EmberNode CreateNodeFromReader(uint type, BerReaderBase reader) { switch (type & ~BerType.ApplicationFlag) { case 1: return(CreateSet(type, reader)); case 2: return(CreateSequence(type, reader)); } return(null); }
/// <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> /// Override this method to create custom EmberNode-derived objects. /// This method is called when a decoder encounters a TLV with an /// application-defined type. /// </summary> /// <param name="type">The type of the decoded TLV, with BerType.ApplicationFlag set.</param> /// <param name="reader">A reader positioned on the TLV. Use the Get() methods of /// BerReaderBase to retrieve the value of the TLV.</param> /// <returns>Return a new instance of a type derived from EmberNode or null /// if no application-defined type is mapped to the passed <paramref name="type"/>.</returns> public abstract EmberNode CreateNodeFromReader(uint type, BerReaderBase reader);