Пример #1
0
        private static Pure3D.BaseNode DeserializeNode(Stream input, Endian endian, Pure3D.BaseNode parent)
        {
            var start = input.Position;

            var typeId     = input.ReadValueU32(endian);
            var headerSize = input.ReadValueU32(endian);
            var totalSize  = input.ReadValueU32(endian);

            var current = Pure3D.NodeFactory.CreateNode(typeId);

            if (current != null)
            {
                current.Deserialize(input);
            }
            else
            {
                var unknown = new Pure3D.Unknown(typeId);
                unknown.Data = input.ReadBytes(headerSize - 12);
                current      = unknown;
            }

            current.ParentNode = parent;

            if (input.Position != start + headerSize)
            {
                throw new FormatException();
            }

            var end = start + totalSize;

            while (input.Position < end)
            {
                var child = DeserializeNode(input, endian, current);
                current.Children.Add(child);
            }

            if (input.Position != end)
            {
                throw new FormatException();
            }

            return(current);
        }
Пример #2
0
        private void SerializeNode(Stream output, Pure3D.BaseNode node)
        {
            Stream childrenStream = new MemoryStream();

            foreach (Pure3D.BaseNode child in node.Children)
            {
                this.SerializeNode(childrenStream, child);
            }

            Stream nodeStream = new MemoryStream();

            node.Serialize(nodeStream);

            output.WriteValueU32(node.TypeId);
            output.WriteValueU32((UInt32)(12 + nodeStream.Length));
            output.WriteValueU32((UInt32)(12 + nodeStream.Length + childrenStream.Length));

            nodeStream.Seek(0, SeekOrigin.Begin);
            output.WriteFromStream(nodeStream, nodeStream.Length);

            childrenStream.Seek(0, SeekOrigin.Begin);
            output.WriteFromStream(childrenStream, childrenStream.Length);
        }