Exemplo n.º 1
0
 public ChunkInd(Chunk4 c)
 {
     Code = (DnaID)c.Code;
     Length = c.Length;
     OldPtr = c.UniqueInt1;
     StructIndex = c.StructIndex;
     NumBlocks = c.NumBlocks;
 }
Exemplo n.º 2
0
 public ChunkInd(Chunk4 c)
 {
     Code        = (DnaID)c.Code;
     Length      = c.Length;
     OldPtr      = c.UniqueInt1;
     StructIndex = c.StructIndex;
     NumBlocks   = c.NumBlocks;
 }
Exemplo n.º 3
0
        public override void FinishSerialization()
        {
            WriteDna();

            //if we didn't pre-allocate a buffer, we need to create a contiguous buffer now
            if (_totalSize == 0)
            {
                if (_buffer != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(_buffer);
                }

                _currentSize += 12;                 // header
                _buffer       = Marshal.AllocHGlobal(_currentSize);

                IntPtr currentPtr = _buffer;
                WriteHeader(_buffer);
                currentPtr += 12;
                foreach (Chunk chunk in _chunks)
                {
                    if (IntPtr.Size == 8)
                    {
                        var chunkPtr = new Chunk8();
                        Marshal.PtrToStructure(chunk._native, chunkPtr);
                        Marshal.StructureToPtr(chunkPtr, currentPtr, false);
                    }
                    else
                    {
                        var chunkPtr = new Chunk4();
                        Marshal.PtrToStructure(chunk._native, chunkPtr);
                        Marshal.StructureToPtr(chunkPtr, currentPtr, false);
                    }
                    currentPtr += ChunkInd.Size + chunk.Length;
                }
            }

            foreach (IntPtr ptr in _nameMap.Values)
            {
                Marshal.FreeHGlobal(ptr);
            }

            _chunkP.Clear();
            _nameMap.Clear();
            _uniquePointers.Clear();
            _chunks.Clear();
        }
Exemplo n.º 4
0
        protected ChunkInd GetNextBlock(BinaryReader reader)
        {
            bool swap   = (Flags & FileFlags.EndianSwap) != 0;
            bool varies = (Flags & FileFlags.BitsVaries) != 0;

            if (swap)
            {
                throw new NotImplementedException();
            }

            if (IntPtr.Size == 8)
            {
                if (varies)
                {
                    Chunk4 c = new Chunk4(reader);
                    return(new ChunkInd(c));
                }
                else
                {
                    Chunk8 c = new Chunk8(reader);
                    return(new ChunkInd(c));
                }
            }
            else
            {
                if (varies)
                {
                    Chunk8 c = new Chunk8(reader);
                    if (c.UniqueInt1 == c.UniqueInt2)
                    {
                        c.UniqueInt2 = 0;
                    }
                    else
                    {
                        throw new NotImplementedException();
                    }
                    return(new ChunkInd(c));
                }
                else
                {
                    Chunk4 c = new Chunk4(reader);
                    return(new ChunkInd(c));
                }
            }
        }
Exemplo n.º 5
0
        protected ChunkInd GetNextBlock(BinaryReader reader)
        {
            bool swap = (Flags & FileFlags.EndianSwap) != 0;
            bool varies = (Flags & FileFlags.BitsVaries) != 0;

            if (swap)
            {
                throw new NotImplementedException();
            }

            if (IntPtr.Size == 8)
            {
                if (varies)
                {
                    Chunk4 c = new Chunk4(reader);
                    return new ChunkInd(c);
                }
                else
                {
                    Chunk8 c = new Chunk8(reader);
                    return new ChunkInd(c);
                }
            }
            else
            {
                if (varies)
                {
                    Chunk8 c = new Chunk8(reader);
                    if (c.UniqueInt1 == c.UniqueInt2)
                    {
                        c.UniqueInt2 = 0;
                    }
                    else
                    {
                        throw new NotImplementedException();
                    }
                    return new ChunkInd(c);
                }
                else
                {
                    Chunk4 c = new Chunk4(reader);
                    return new ChunkInd(c);
                }
            }
        }
Exemplo n.º 6
0
        public override void FinishSerialization()
        {
            WriteDna();

            //if we didn't pre-allocate a buffer, we need to create a contiguous buffer now
            if (_totalSize == 0)
            {
                if (_buffer != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(_buffer);
                }

                _currentSize += 12; // header
                _buffer = Marshal.AllocHGlobal(_currentSize);

                IntPtr currentPtr = _buffer;
                WriteHeader(_buffer);
                currentPtr += 12;
                foreach (Chunk chunk in _chunks)
                {
                    if (IntPtr.Size == 8)
                    {
                        var chunkPtr = new Chunk8();
                        Marshal.PtrToStructure(chunk._native, chunkPtr);
                        Marshal.StructureToPtr(chunkPtr, currentPtr, false);
                    }
                    else
                    {
                        var chunkPtr = new Chunk4();
                        Marshal.PtrToStructure(chunk._native, chunkPtr);
                        Marshal.StructureToPtr(chunkPtr, currentPtr, false);
                    }
                    currentPtr += ChunkInd.Size + chunk.Length;
                }
            }

            foreach (IntPtr ptr in _nameMap.Values)
            {
                Marshal.FreeHGlobal(ptr);
            }

            _chunkP.Clear();
            _nameMap.Clear();
            _uniquePointers.Clear();
            _chunks.Clear();
        }