Beispiel #1
0
        private void ReadStructure(Tag tag, IContentReaderDelegate contentDelegate)
        {
            contentDelegate.OnStructureStart(tag);

            while (true)
            {
                Tag innerTag = this.ReadTag();
                switch (innerTag.Type)
                {
                case Tag.TagType.Attribute: {
                    this.ReadAttribute(innerTag, contentDelegate);
                    break;
                }

                case Tag.TagType.StructureStart: {
                    this.ReadStructure(innerTag, contentDelegate);
                    break;
                }

                case Tag.TagType.StructureEnd: {
                    contentDelegate.OnStructureEnd(innerTag);
                    return;
                }
                }
            }
        }
Beispiel #2
0
        private void ReadAttribute(Tag tag, IContentReaderDelegate contentDelegate)
        {
            var numBytes = this.reader.Read7BitEncodedInt();

            byte[] bytes = this.reader.ReadBytes(numBytes);
            contentDelegate.OnAttribute(tag, new AttributeValue(bytes));
        }
Beispiel #3
0
        public void ReadContent(IContentReaderDelegate contentDelegate)
        {
            Tag tag = this.ReadTag();

            if (tag.Type != Tag.TagType.StructureStart)
            {
                throw new System.FormatException(System.String.Format("Root node should be structure, but tag was {0} ({1})", tag.Type, tag.Name));
            }
            this.ReadStructure(tag, contentDelegate);
        }
Beispiel #4
0
        public void ReadFile(IContentReaderDelegate contentDelegate)
        {
            var  tagSectionReader    = new TagsSectionReader(this.reader);
            long tagsSectionPosition = tagSectionReader.FindTagsSection();

            this.reader.BaseStream.Position = tagsSectionPosition;
            Tags tags = tagSectionReader.ReadTagsSection();

            var contentReader = new ContentReader(this.reader, tags);

            this.reader.BaseStream.Position = 0;
            contentReader.ReadContent(contentDelegate);

            Tag tag = contentReader.ReadTag();

            if (tag.Type != Tag.TagType.StructureEnd)
            {
                throw new System.FormatException(System.String.Format("Unexpected tag type at end of content; expected: {0}, was: {1}", Tag.TagType.StructureEnd, tag.Type));
            }
            if (this.reader.BaseStream.Position != tagsSectionPosition)
            {
                throw new System.FormatException(System.String.Format("Unexpected position at end of content; expected: {0}, was: {1}", tagSectionReader, this.reader.BaseStream.Position));
            }
        }