コード例 #1
0
        public XElement CreateXmlElement(NomadObject obj, XElement parent = null)
        {
            Context.State = ContextStateType.Object;
            Context.ObjectIndex++;

            var name = XName.Get(obj.Id);
            var elem = new XElement(name);

            if (parent != null)
            {
                parent.Add(elem);
            }

            foreach (var attr in obj.Attributes)
            {
                if (attr.Id == "RML_DATA")
                {
                    using (var bs = new BinaryStream(attr.Data.Buffer))
                    {
                        var rmlSize   = bs.ReadInt32();
                        var rmlBuffer = bs.ReadBytes(rmlSize);

                        using (var rs = new BinaryStream(rmlBuffer))
                        {
                            var rmlData = new NomadRmlSerializer();
                            var rml     = rmlData.Deserialize(rs);

                            var rmlRoot = new XElement("RML_DATA");
                            var rmlElem = CreateXmlElement(rml, rmlRoot);

                            elem.Add(rmlRoot);
                        }
                    }
                }
                else
                {
                    CreateXmlAttribute(attr, elem);
                }
            }

            foreach (var child in obj.Children)
            {
                CreateXmlElement(child, elem);
            }

            return(elem);
        }
コード例 #2
0
        protected NomadObject ReadObject_FmtA(BinaryStream stream, NomadObject parent = null)
        {
            Context.State = ContextStateType.Object;
            Context.ObjectIndex++;

            var ptr       = (int)stream.Position;
            var nChildren = DescriptorTag.Read(stream, ReferenceType.Index);

            if (nChildren.Type == DescriptorType.Reference)
            {
                throw new InvalidOperationException("Cannot deserialize an object reference directly!");
            }

            var hash = stream.ReadInt32();
            var id   = StringId.Parse(hash);

            var result = new NomadObject(id);

            Context.AddRef(result, ptr);

            if (result.IsRml)
            {
                var next = DescriptorTag.Read(stream, ReferenceType.Index);

                var rmlBase = (int)stream.Position;

                var rmlSize   = stream.ReadInt32();
                var rmlBuffer = stream.ReadBytes(rmlSize);

                using (var bs = new BinaryStream(rmlBuffer))
                {
                    var rmlData = new NomadRmlSerializer();
                    var rml     = rmlData.Deserialize(bs);

                    result.Children.Add(rml);
                }

                stream.Position = (rmlBase + next);
            }
            else
            {
                var nAttrs = DescriptorTag.Read(stream, ReferenceType.Index);

                for (int i = 0; i < nAttrs; i++)
                {
                    ReadAttribute_FmtA(stream, result);
                }

                for (int i = 0; i < nChildren; i++)
                {
                    var cP = (int)stream.Position;
                    var cD = DescriptorTag.Read(stream, ReferenceType.Index);

                    // rip
                    if (cD.IsIndex)
                    {
                        var idx      = cD.Value;
                        var childRef = Context.GetRefByIdx(idx) as NomadObject;

                        result.Children.Add(childRef);
                    }
                    else
                    {
                        // move back
                        stream.Position = cP;

                        ReadObject_FmtA(stream, result);
                    }
                }
            }

            if (parent != null)
            {
                parent.Children.Add(result);
            }

            return(result);
        }