public TagList AddList(ETagType genericType) { TagList l = new TagList(null, genericType); Add(l); return(l); }
public TagList CreateList(string name, ETagType type) { TagList res = new TagList(name, type); Set(name, res); return(res); }
public override object ParsePayload(Stream stream, INamedBinaryTag iTag) { TagList list = iTag as TagList; byte generic_b = stream.ReadSingleByte(); ETagType generic = (ETagType)generic_b; list.GenericType = generic; //if (generic == ETagType.End) //{ // throw new Exception("TagList cannot consist End tags."); //} byte[] count_b = new byte[4]; stream.Read(count_b, 0, 4); count_b = count_b.ReverseIfLittleEndian(); int count = BitConverter.ToInt32(count_b, 0); TagParserBase parser = Parsers[generic]; for (int i = 0; i < count; i++) { INamedBinaryTag tag = generic.MakeTag(null); parser.ParsePayload(stream, tag); list.Add(tag); } return(list.Children); }
public override object ParsePayload(Stream stream, INamedBinaryTag iTag) { TagCompound tag = iTag as TagCompound; while (true) { byte b = stream.ReadSingleByte(); ETagType type = (ETagType)b; if (type == ETagType.End) { break; } string key = ParseName(stream); INamedBinaryTag inner = type.MakeTag(key); TagParserBase parser = Parsers[type]; parser.ParsePayload(stream, inner); tag.Set(key, inner); } return(tag.Values); }
public static INamedBinaryTag ParseBytes(byte[] rawData, ETagType rootTagType) { INamedBinaryTag nbt = null; using (MemoryStream stream = new MemoryStream(rawData, false)) { nbt = TagParserBase.Parsers[rootTagType].Parse(stream); } return(nbt); }
// probably shouldn't override this. public virtual INamedBinaryTag Parse(Stream stream) { byte b = stream.ReadSingleByte(); ETagType type = (ETagType)b; string name = ParseName(stream); INamedBinaryTag result = type.MakeTag(name); ParsePayload(stream, result); return(result); }
public static Type GetUnderlyingType(this ETagType tagType) { switch (tagType) { case ETagType.End: return(typeof(void)); case ETagType.Byte: return(typeof(sbyte)); case ETagType.Short: return(typeof(short)); case ETagType.Int: return(typeof(int)); case ETagType.Long: return(typeof(long)); case ETagType.Float: return(typeof(float)); case ETagType.Double: return(typeof(double)); case ETagType.Byte_Array: return(typeof(byte[])); case ETagType.String: return(typeof(string)); case ETagType.List: return(typeof(object[])); case ETagType.Compound: return(typeof(Dictionary <string, INamedBinaryTag>)); case ETagType.Int_Array: return(typeof(int[])); default: return(null); } }
public static INamedBinaryTag MakeTag(this ETagType type, string name) { switch (type) { case ETagType.End: return(new TagEnd()); case ETagType.Byte: return(new TagByte(name)); case ETagType.Short: return(new TagShort(name)); case ETagType.Int: return(new TagInt(name)); case ETagType.Long: return(new TagLong(name)); case ETagType.Float: return(new TagFloat(name)); case ETagType.Double: return(new TagDouble(name)); case ETagType.Byte_Array: return(new TagByteArray(name)); case ETagType.String: return(new TagString(name)); case ETagType.List: return(new TagList(name)); case ETagType.Compound: return(new TagCompound(name)); case ETagType.Int_Array: return(new TagIntArray(name)); default: throw new ArgumentOutOfRangeException(nameof(type)); } }
public Tags(string aXml) { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(aXml); XmlNodeList nodeList = xmlDoc.DocumentElement.SelectNodes("/Tags"); if (nodeList.Count != 1) { throw new XmlError("bad xml"); } try { nodeList = xmlDoc.DocumentElement.SelectNodes("/Tags/Entry"); foreach (XmlNode entryNode in nodeList) { string tag = ParseXml(entryNode, "Tag"); uint key = uint.Parse(ParseXml(entryNode, "Key")); string desc = ParseXml(entryNode, "Desc"); ETagType type = StringToTagType(ParseXml(entryNode, "Type")); Entry entry = new Entry(tag, type, key, desc, 1); iTagToEntry[entry.iTag] = entry; iKeyToEntry[entry.iKey] = entry; } nodeList = xmlDoc.DocumentElement.SelectNodes("/Tags/Group"); foreach (XmlNode groupNode in nodeList) { string tag = ParseXml(groupNode, "Tag"); uint key = uint.Parse(ParseXml(groupNode, "Key")); string desc = ParseXml(groupNode, "Desc"); ETagType type = StringToTagType(ParseXml(groupNode, "Type")); uint count = uint.Parse(ParseXml(groupNode, "Count")); Entry entry = new Entry(tag, type, key, desc, count); iGroupList.Add(entry); } } catch (Exception) { throw new XmlError("bad xml"); } }
public Entry(string aTag, ETagType aType, uint aKey, string aDesc, uint aCount) { if ((aTag[0] != 'u') || aTag.Substring(1, 1) != aTag.Substring(1, 1).ToUpper()) { throw new XmlError("bad tag name " + aTag); } for (int i = 0; i < aTag.Length; i++) { if (Char.IsLetterOrDigit(aTag[i]) == false) { throw new XmlError("bad tag name " + aTag); } } iTag = aTag; iKey = aKey; iType = aType; iDesc = aDesc; iCount = aCount; }
public ETag(ETagType type, string value) { Type = type; Value = value; }
public static string GetNotchName(this ETagType type) { return("TAG_" + type.ToString()); }
public static INamedBinaryTag Parse(Stream stream, ETagType rootTagType) { return(TagParserBase.Parsers[rootTagType].Parse(stream)); }
public TagList(string name, ETagType genericType) { Children = new List <INamedBinaryTag>(); Name = name; GenericType = genericType; }
public ETag(ETagType eTagType, string value) { ETagType = eTagType; Value = new StringSegment($"\"{value}\""); }
public ETag(ETagType eTagType, string value) { ETagType = eTagType; Value = value; }
public DefaultETagGenerator(IStoreKeyGenerator storeKeyGenerator, ETagType eTagType = ETagType.Strong) { _storeKeyGenerator = storeKeyGenerator; _eTagType = eTagType; }