private void DecodeEntry(GraphNode parentNode, object newSubObject, IParserOutput output, EmbeddedFile file) { // decode the node and add it to the parent: // first determine the exact type of node if (newSubObject is Field) { parentNode.Add(ParseField(newSubObject as Field, file)); } else if (newSubObject is Align) { // align to the specified boundary parentNode.Add(ParseAlignment(newSubObject as Align, file)); } else if (newSubObject is NamedType) { GraphNode complexNode = parentNode.Add(ParseNamedType(newSubObject as NamedType, file)); // look up the specified type TypeDef definition = m_mapping.GetTypeDefByName((newSubObject as NamedType).TypeName); foreach (object subEbtry in definition.Items) { DecodeEntry(complexNode, subEbtry, output, file); } } else if (newSubObject is Vector) { GraphNode vectorNode = parentNode.Add(ParseVector(newSubObject as Vector, file)); // determine the length of the vector // this is done by examining the contents of the 'length' field // for now, we assume that all lengths are stored in a sister field of the vector, that // has appeared previously string indexFieldName = (newSubObject as Vector).Length; GraphNode amountNode = parentNode.GetNamedField(indexFieldName); if (amountNode == null) { throw new ArgumentException(string.Format("Unable to find named field {0}", indexFieldName)); } int length = Convert.ToInt32(amountNode.Value); // parse for the specified amount of times for (int i = 0; i < length; i++) { DecodeEntry(vectorNode, (newSubObject as Vector).Item, output, file); } } else { throw new Exception("Unknown type of filter object"); } }
public object Parse(JsonReader reader) { if (reader == null) throw new ArgumentNullException("reader"); // // Fault-in an AST strategy if one wasn't supplied thus far. // if (_output == null) _output = new ParserOutput(); return reader.DeserializeNext(_output); }
private object Parse() { // // Fault-in an AST strategy if one wasn't supplied thus far. // if (_output == null) _output = new ParserOutput(); // // Parse and return the next object found. // return NextObject(); }
public FileGraph ApplyFilterToFile(EmbeddedFile file, string filterName, IParserOutput output) { if (file == null || filterName == null || output == null) { throw new ArgumentException("Invalid parameters specified."); } // lookup the filter with the specified name DataFileDef filter = m_mapping.GetFilterByName(filterName); if (filter == null) { output.HandleFatalError("The specified filter does not exist."); } FileGraph graph = new FileGraph(file.FileId); try { // open the input file file.PrepareFileForReading(); // create a root node in the graph graph.RootNode = new GraphNode("Root node", NodeType.Complex, file.Position); foreach (object filterObject in filter.Items) { DecodeEntry(graph.RootNode, filterObject, output, file); } graph.RootNode.FilePositionEnd = file.Position; graph.UpdateEndPositionOfNodes(); } catch (Exception ex) { output.HandleFatalError("Unexpected exception: " + ex.Message); } finally { file.FileReadingComplete(); } return(graph); }
public DelimitedListParser(IParserOutput output) { _output = output; }
/// <summary> /// Deserializes the next object from JSON data using a give type /// system. /// </summary> public virtual object DeserializeNext(IParserOutput output) { if (output == null) output = new ParserOutput(); MoveToContent(); switch (Token) { case JsonToken.String: return output.ToStringPrimitive(Text); case JsonToken.Number: return output.ToNumberPrimitive(Text); case JsonToken.Boolean : return Text == JsonReader.FalseText ? output.FalsePrimitive : output.TruePrimitive; case JsonToken.Null : return output.NullPrimitive; case JsonToken.Array : { output.StartArray(); while (ReadToken() != JsonToken.EndArray) output.ArrayPut(DeserializeNext(output)); return output.EndArray(); } case JsonToken.Object : { output.StartObject(); while (ReadToken() != JsonToken.EndObject) { if (Token != JsonToken.Member) throw new JsonException("Expecting member."); string name = Text; Read(); output.ObjectPut(name, DeserializeNext(output)); } return output.EndObject(); } case JsonToken.EOF : throw new JsonException("Unexpected EOF."); default : throw new JsonException(string.Format("{0} not expected.", this.Token)); } }
public virtual object DeserializeNext(IParserOutput output) { if (output == null) output = new ParserOutput(); MoveToContent(); if (TokenClass == JsonTokenClass.String) { return output.ToStringPrimitive(ReadString()); } else if (TokenClass == JsonTokenClass.Number) { return output.ToNumberPrimitive(ReadNumber().ToString()); } else if (TokenClass == JsonTokenClass.Boolean) { return ReadBoolean(); } else if (TokenClass == JsonTokenClass.Null) { ReadNull(); return output.NullPrimitive; } else if (TokenClass == JsonTokenClass.Array) { Read(); output.StartArray(); while (TokenClass != JsonTokenClass.EndArray) output.ArrayPut(DeserializeNext(output)); Read(); return output.EndArray(); } else if (TokenClass == JsonTokenClass.Object) { Read(); output.StartObject(); while (TokenClass != JsonTokenClass.EndObject) { string name = ReadMember(); output.ObjectPut(name, DeserializeNext(output)); } Read(); return output.EndObject(); } else { throw new JsonException(string.Format("{0} not expected.", TokenClass)); } }
public JsonParser(IParserOutput output) { _output = output; }
public JsonParser(IParserOutput output) { _index = 0; _source = string.Empty; _output = output; }