Ejemplo n.º 1
0
        public override void WriteEndTag()
        {
            var currentTag = _state.CurrentTag;

            if ((currentTag == TagType.ByteArray || currentTag == TagType.IntArray) && _arraySb != null &&
                _arraySb.Length != 0)
            {
                _writer.WriteValue(_arraySb.ToString());
                _arraySb.Length = 0;
            }

            _state.EndTag();

            _writer.WriteEndElement();
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
 public override void WriteEndTag()
 {
     _state.EndTag(WriteEnd);
 }
Ejemplo n.º 4
0
        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);
        }