public override void WriteStartTag(string name, TagType type) { var currentState = _state.StartTag(type); if (type != TagType.End && (currentState == null || currentState.ContainerType != TagType.List)) { WriteValue((byte)type); WriteValue(name); } }
public override void WriteStartTag(string name, TagType type) { var currentState = _state.StartTag(type); if (string.IsNullOrEmpty(name)) { name = "tag"; } if (XmlConvert.EncodeName(name) == name) { _writer.WriteStartElement(name); } else { _writer.WriteStartElement("tag"); _writer.WriteAttributeString("name", name); } if (type != TagType.End && (currentState == null || currentState.ContainerType != TagType.List)) { _writer.WriteAttributeString("type", type.ToString()); } }
public override TagCollection ReadList() { var listType = (TagType)ReadByte(); if (listType < TagType.End || listType > TagType.IntArray) { throw new InvalidDataException($"Unexpected list type '{listType}' found."); } var tags = new TagCollection(listType); var length = ReadInt(); for (var i = 0; i < length; i++) { Tag tag; _state.StartTag(listType); switch (listType) { case TagType.Byte: tag = TagFactory.CreateTag(ReadByte()); break; case TagType.ByteArray: tag = TagFactory.CreateTag(ReadByteArray()); break; case TagType.Compound: tag = TagFactory.CreateTag(ReadCompound()); break; case TagType.Double: tag = TagFactory.CreateTag(ReadDouble()); break; case TagType.Float: tag = TagFactory.CreateTag(ReadFloat()); break; case TagType.Int: tag = TagFactory.CreateTag(ReadInt()); break; case TagType.IntArray: tag = TagFactory.CreateTag(ReadIntArray()); break; case TagType.List: tag = TagFactory.CreateTag(ReadList()); break; case TagType.Long: tag = TagFactory.CreateTag(ReadLong()); break; case TagType.Short: tag = TagFactory.CreateTag(ReadShort()); break; case TagType.String: tag = TagFactory.CreateTag(ReadString()); break; default: tag = null; break; } _state.EndTag(); if (tag != null) { tags.Add(tag); } } return(tags); }
private Tag ReadTag(TagType defaultTagType) { string name; var type = ReadTagType(defaultTagType); var state = _state.StartTag(type); if (type != TagType.End && (state == null || state.ContainerType != TagType.List)) { name = _reader.GetAttribute("name"); if (string.IsNullOrEmpty(name)) { name = ReadTagName(); } } else { name = string.Empty; } Tag result = null; switch (type) { case TagType.Byte: result = TagFactory.CreateTag(name, ReadByte()); break; case TagType.Short: result = TagFactory.CreateTag(name, ReadShort()); break; case TagType.Int: result = TagFactory.CreateTag(name, ReadInt()); break; case TagType.Long: result = TagFactory.CreateTag(name, ReadLong()); break; case TagType.Float: result = TagFactory.CreateTag(name, ReadFloat()); break; case TagType.Double: result = TagFactory.CreateTag(name, ReadDouble()); break; case TagType.ByteArray: result = TagFactory.CreateTag(name, ReadByteArray()); break; case TagType.String: result = TagFactory.CreateTag(name, ReadString()); break; case TagType.List: result = TagFactory.CreateTag(name, ReadList()); break; case TagType.Compound: result = TagFactory.CreateTag(name, ReadCompound()); break; case TagType.IntArray: result = TagFactory.CreateTag(name, ReadIntArray()); break; // Can't be hit as ReadTagType will throw // an exception for unsupported types // default: // throw new InvalidDataException($"Unrecognized tag type: {type}"); } _state.EndTag(); return(result); }