public static DataElement PitParser(PitParser context, XmlNode node, DataElementContainer parent) { if (node.Name != "String") { return(null); } var str = DataElement.Generate <String>(node); if (node.hasAttr("nullTerminated")) { str.nullTerminated = node.getAttrBool("nullTerminated"); } else { str.nullTerminated = context.getDefaultAttr(typeof(String), "nullTerminated", str.nullTerminated); } string type = "ascii"; if (node.hasAttr("type")) { type = node.getAttrString("type"); } else { type = context.getDefaultAttr(typeof(String), "type", type); } StringType stringType; if (!Enum.TryParse <StringType>(type, true, out stringType)) { throw new PeachException("Error, unknown String type '" + type + "' on element '" + str.name + "'."); } str.stringType = stringType; if (node.hasAttr("padCharacter")) { str.padCharacter = node.getAttrChar("padCharacter"); } else { str.padCharacter = context.getDefaultAttr(typeof(String), "padCharacter", str.padCharacter); } if (node.hasAttr("tokens")) // This item has a default! { throw new NotSupportedException("Tokens attribute is depricated in Peach 3. Use parameter to StringToken analyzer isntead."); } if (node.hasAttr("analyzer")) // this should be passed via a child element me things! { throw new NotSupportedException("Analyzer attribute is depricated in Peach 3. Use a child element instead."); } context.handleCommonDataElementAttributes(node, str); context.handleCommonDataElementChildren(node, str); context.handleCommonDataElementValue(node, str); if (!node.hasAttr("value")) { str.DefaultValue = new Variant(""); } return(str); }
public static DataElement PitParser(PitParser context, XmlNode node, DataElementContainer parent) { if (node.Name != "Flags") { return(null); } var flags = DataElement.Generate <Flags>(node); string strSize = null; if (node.hasAttr("size")) { strSize = node.getAttrString("size"); } if (strSize == null) { strSize = context.getDefaultAttr(typeof(Flags), "size", null); } if (strSize == null) { throw new PeachException("Error, Flags elements must have 'size' attribute!"); } int size; if (!int.TryParse(strSize, out size)) { throw new PeachException("Error, " + flags.name + " size attribute is not valid number."); } if (size < 1 || size > 64) { throw new PeachException(string.Format("Error, unsupported size '{0}' for {1}.", size, flags.debugName)); } flags.lengthType = LengthType.Bits; flags.length = size; string strEndian = null; if (node.hasAttr("endian")) { strEndian = node.getAttrString("endian"); } if (strEndian == null) { strEndian = context.getDefaultAttr(typeof(Flags), "endian", null); } if (strEndian != null) { switch (strEndian.ToLower()) { case "little": flags.LittleEndian = true; break; case "big": flags.LittleEndian = false; break; case "network": flags.LittleEndian = false; break; default: throw new PeachException( string.Format("Error, unsupported value '{0}' for 'endian' attribute on {1}.", strEndian, flags.debugName)); } } context.handleCommonDataElementAttributes(node, flags); context.handleCommonDataElementChildren(node, flags); foreach (XmlNode child in node.ChildNodes) { // Looking for "Flag" element if (child.Name == "Flag") { flags.Add(Flag.PitParser(context, child, flags)); } } return(flags); }
public static DataElement PitParser(PitParser context, XmlNode node, DataElementContainer parent) { if (node.Name != "Number") { return(null); } var num = DataElement.Generate <Number>(node); if (node.hasAttr("signed")) { num.Signed = node.getAttrBool("signed"); } else { num.Signed = context.getDefaultAttr(typeof(Number), "signed", num.Signed); } if (node.hasAttr("size")) { int size = node.getAttrInt("size"); if (size < 1 || size > 64) { throw new PeachException(string.Format("Error, unsupported size '{0}' for {1}.", size, num.debugName)); } num.lengthType = LengthType.Bits; num.length = size; } string strEndian = null; if (node.hasAttr("endian")) { strEndian = node.getAttrString("endian"); } if (strEndian == null) { strEndian = context.getDefaultAttr(typeof(Number), "endian", null); } if (strEndian != null) { switch (strEndian.ToLower()) { case "little": num.LittleEndian = true; break; case "big": num.LittleEndian = false; break; case "network": num.LittleEndian = false; break; default: throw new PeachException( string.Format("Error, unsupported value '{0}' for 'endian' attribute on {1}.", strEndian, num.debugName)); } } context.handleCommonDataElementAttributes(node, num); context.handleCommonDataElementChildren(node, num); context.handleCommonDataElementValue(node, num); return(num); }