private void DumpTemplate(ref byte *r)
        {
            var entry = (TemplateEntry *)r;

            VerifyMagic(0, entry->Magic, CrimsonTags.TEMP);

            writer.PushDictScope(
                "Template(params={0}, props={1}, id={2}, flags={3})",
                entry->NumParams, entry->NumProperties, entry->TemplateId, entry->Flags);

            XDocument doc = BinXmlReader.Read(buffer.mappedFile.CreateViewStream((byte *)&entry[1] - begin, entry->Length, MemoryMappedFileAccess.Read));

            writer.WriteStringBlock("BinXml", doc.ToString());

            writer.PushListScope("Properties");
            var properties       = (PropertyEntry *)(begin + entry->PropertyOffset);
            var structProperties = (PropertyEntry *)(begin + entry->PropertyOffset + entry->NumParams * Marshal.SizeOf <PropertyEntry>());

            for (uint i = 0; i < entry->NumParams; ++i)
            {
                DumpProperty(&properties[i], &structProperties);
            }

            writer.PopScope();

            writer.PopScope();
        }
        public void ReadSimple()
        {
            var substitutionTypes = new List <BinXmlType>();
            var input             = CreateInput(new byte[] {
                // FragmentHeader
                Token.FragmentHeaderToken,
                Constants.MajorVersion,
                Constants.MinorVersion,
                0, /*flags*/

                Token.EndOfFragmentToken
            });

            var doc = BinXmlReader.Read(input, substitutionTypes);

            Assert.Equal("", doc.ToString());
        }
        public void FragmentHeader_UnsupportedFlags()
        {
            var substitutionTypes = new List <BinXmlType>();
            var input             = CreateInput(new byte[] {
                // FragmentHeader
                Token.FragmentHeaderToken,
                Constants.MajorVersion,
                Constants.MinorVersion,
                1, /*flags*/

                Token.EndOfFragmentToken
            });

            var ex = Assert.Throws <InvalidOperationException>(
                () => BinXmlReader.Read(input, substitutionTypes));

            Assert.Contains("Unsupported flags", ex.Message);
        }
Beispiel #4
0
        private Template ReadTemplate(BinaryReader r)
        {
            long offset = r.BaseStream.Position;

            ReadMagic(r, CrimsonTags.TEMP);
            uint length         = r.ReadUInt32();
            uint paramCount     = r.ReadUInt32();
            uint dataCount      = r.ReadUInt32();
            uint propertyOffset = r.ReadUInt32();
            uint flags          = r.ReadUInt32();
            Guid guid           = r.ReadGuid();

            var       types = new List <BinXmlType>();
            XDocument doc   = BinXmlReader.Read(r.BaseStream, types);

            r.BaseStream.Position = propertyOffset;

            string id = string.Format(
                CultureInfo.InvariantCulture, "template{0:X16}", offset);
            var template = new Template(id);

            long structPropertyOffset = propertyOffset + paramCount * Marshal.SizeOf <PropertyEntry>();

            for (uint i = 0; i < paramCount; ++i)
            {
                r.BaseStream.Position = propertyOffset + i * Marshal.SizeOf <PropertyEntry>();
                template.Properties.Add(ReadProperty(r, ref structPropertyOffset, true));
            }

            ResolvePropertyRefs(in guid, template.Properties);

            r.BaseStream.Position = offset + length;

            MarkObject(offset, template);
            return(template);
        }