/// <summary> /// Recursively builds a node tree from the specified reader, advancing the reader in the process. /// Throws an exception if the first node on the reader (which will become the tree's root cannot /// be decoded or is not a container. /// </summary> /// <param name="reader">The BER reader to build the tree from.</param> /// <param name="application">The application interface responsible for creating nodes /// with application-defined types. If null, containers with application-defined types /// will be decoded to objects of type EmberContainer.</param> /// <returns>The root node of the decoded tree.</returns> public static EmberNode Decode(EmberReader reader, EmberApplicationInterface application) { var root = null as EmberContainer; if (reader.Read()) { root = FromReader(reader, application) as EmberContainer; if (root == null) { throw new BerException(4, "Root node is not a container"); } var childReader = new EmberReader(reader); Decode_Recurse(childReader, root, application); } return(root); }
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); } } }
void EmberToXml(EmberReader reader, XmlWriter writer) { if(reader.Read()) EmberToXml_ProcessNode(reader, writer, 0); }
void EmberToXml_Recurse(EmberReader reader, XmlWriter writer, int indent) { while(reader.Read()) EmberToXml_ProcessNode(reader, writer, indent); }