예제 #1
0
        public void endChunk()
        {
            //Pop chunk off stack
            int stackSize = chunkStack.Count;

            Debug.Assert(stackSize != 0);
            Chunk chunk = chunkStack[stackSize - 1];

            chunkStack.RemoveAt(stackSize - 1);

            long prevPos = stream.Position;

            //Move to chunk start
            long delta = prevPos - chunk.posBegin;

            stream.Seek(-delta, SeekOrigin.Current);

            //Write tag and size
            writer.Write(IffTag.TagByteSwap(chunk.tag));
            writer.Write((byte)chunk.type);
            writer.Write((UInt32)(prevPos - chunk.posData));

            //Move back to position
            stream.Seek(prevPos, SeekOrigin.Begin);
        }
예제 #2
0
 public void writeBytes(IffTag tag, byte[] data, UInt32 length)
 {
     writer.Write(IffTag.TagByteSwap(tag.value));
     writer.Write((byte)ChunkType.BINARY);
     writer.Write(length);
     stream.Write(data, 0, (int)length);
 }
예제 #3
0
        public bool readChunk(ref Chunk chunk)
        {
            //Find current position
            chunk.beginPos = stream.Position;
            if (chunkStack.Count != 0 && chunk.beginPos >= currentChunk.endPos)
            {
                return(false);
            }

            //Tag
            chunk.tag = IffTag.TagByteSwap(reader.ReadUInt32());

            //Type
            chunk.type = (IffWriter.ChunkType)reader.ReadByte();

            //Size
            switch (chunk.type)
            {
            case IffWriter.ChunkType.DEFAULT:
            case IffWriter.ChunkType.BINARY:
            case IffWriter.ChunkType.UTF8:
                chunk.size = reader.ReadUInt32();
                break;

            case IffWriter.ChunkType.UINT8:
            case IffWriter.ChunkType.INT8:
                chunk.size = 1;
                break;

            case IffWriter.ChunkType.UINT16:
            case IffWriter.ChunkType.INT16:
                chunk.size = 2;
                break;

            case IffWriter.ChunkType.UINT32:
            case IffWriter.ChunkType.INT32:
            case IffWriter.ChunkType.FLOAT32:
                chunk.size = 4;
                break;

            case IffWriter.ChunkType.UINT64:
            case IffWriter.ChunkType.INT64:
            case IffWriter.ChunkType.FLOAT64:
                chunk.size = 8;
                break;

            default:
                Debug.Assert(false);                 //Data malformed
                return(false);
            }

            //Metadata
            chunk.dataPos = stream.Position;
            chunk.endPos  = chunk.dataPos + chunk.size;

            //Return
            return(true);
        }
예제 #4
0
        public Double readFloat64(IffTag tag, Double defaultValue, SeekPos seekPos = SeekPos.BEGIN)
        {
            Double value = 0;

            if (findFloat64(tag, ref value, seekPos))
            {
                return(value);
            }
            else
            {
                return(defaultValue);
            }
        }
예제 #5
0
        public Single readFloat32(IffTag tag, Single defaultValue, SeekPos seekPos = SeekPos.BEGIN)
        {
            Single value = 0;

            if (findFloat32(tag, ref value, seekPos))
            {
                return(value);
            }
            else
            {
                return(defaultValue);
            }
        }
예제 #6
0
        public byte readInt8(IffTag tag, byte defaultValue, SeekPos seekPos = SeekPos.BEGIN)
        {
            byte value = 0;

            if (findInt8(tag, ref value, seekPos))
            {
                return(value);
            }
            else
            {
                return(defaultValue);
            }
        }
예제 #7
0
        public Int64 readInt64(IffTag tag, Int64 defaultValue, SeekPos seekPos = SeekPos.BEGIN)
        {
            Int64 value = 0;

            if (findInt64(tag, ref value, seekPos))
            {
                return(value);
            }
            else
            {
                return(defaultValue);
            }
        }
예제 #8
0
        //Read
        public bool readBool(IffTag tag, bool defaultValue, SeekPos seekPos = SeekPos.BEGIN)
        {
            bool value = false;

            if (findBool(tag, ref value, seekPos))
            {
                return(value);
            }
            else
            {
                return(defaultValue);
            }
        }
예제 #9
0
        public UInt32 readUInt32(IffTag tag, UInt32 defaultValue, SeekPos seekPos = SeekPos.BEGIN)
        {
            UInt32 value = 0;

            if (findUInt32(tag, ref value, seekPos))
            {
                return(value);
            }
            else
            {
                return(defaultValue);
            }
        }
예제 #10
0
        public bool findInt8(IffTag tag, ref byte result, SeekPos seekPos = SeekPos.BEGIN)
        {
            //Begin chunk
            if (!findChunk(tag, seekPos))
            {
                return(false);
            }

            //Parse
            result = parseNumeric()[0];

            //Return
            endChunk();
            return(true);
        }
예제 #11
0
        public bool findFloat64(IffTag tag, ref Double result, SeekPos seekPos = SeekPos.BEGIN)
        {
            //Begin chunk
            if (!findChunk(tag, seekPos))
            {
                return(false);
            }

            //Parse
            result = BitConverter.ToDouble(parseNumeric(), 0);

            //Return
            endChunk();
            return(true);
        }
예제 #12
0
 public void writeString(IffTag tag, string value)
 {
     if (!String.IsNullOrEmpty(value))
     {
         UInt32 length = (UInt32)value.Length;
         writer.Write(IffTag.TagByteSwap(tag.value));
         writer.Write((byte)ChunkType.UTF8);
         writer.Write(length);
         writer.Write(value.ToCharArray());
     }
     else
     {
         writer.Write(IffTag.TagByteSwap(tag.value));
         writer.Write((byte)ChunkType.UTF8);
         writer.Write((UInt32)0);
     }
 }
예제 #13
0
        public void beginChunk(IffTag tag, ChunkType type = IffWriter.ChunkType.DEFAULT)
        {
            //Check if this makes sense
            if (chunkStack.Count != 0 && chunkStack[chunkStack.Count - 1].type != ChunkType.DEFAULT)
            {
                Debug.Assert(false);
                return;
            }

            //Push chunk onto stack
            Chunk chunk = new Chunk();

            chunk.tag      = tag.value;
            chunk.type     = type;
            chunk.posBegin = stream.Position;
            chunk.posData  = chunk.posBegin + 9;
            chunkStack.Add(chunk);

            //Write
            stream.Seek(9, SeekOrigin.Current);
        }
예제 #14
0
 public void writeBool(IffTag tag, bool value)
 {
     writer.Write(IffTag.TagByteSwap(tag.value));
     writer.Write((byte)ChunkType.UINT8);
     writer.Write(Convert.ToByte(value));
 }
예제 #15
0
 public void writeUInt32(IffTag tag, UInt32 value)
 {
     writer.Write(IffTag.TagByteSwap(tag.value));
     writer.Write((byte)ChunkType.UINT32);
     writer.Write(value);
 }
예제 #16
0
 public void writeFloat64(IffTag tag, Double value)
 {
     writer.Write(IffTag.TagByteSwap(tag.value));
     writer.Write((byte)ChunkType.FLOAT64);
     writer.Write(value);
 }
예제 #17
0
 public void writeFloat32(IffTag tag, Single value)
 {
     writer.Write(IffTag.TagByteSwap(tag.value));
     writer.Write((byte)ChunkType.FLOAT32);
     writer.Write(value);
 }
예제 #18
0
 public void writeInt64(IffTag tag, Int64 value)
 {
     writer.Write(IffTag.TagByteSwap(tag.value));
     writer.Write((byte)ChunkType.INT64);
     writer.Write(value);
 }
예제 #19
0
 public void writeInt8(IffTag tag, byte value)
 {
     writer.Write(IffTag.TagByteSwap(tag.value));
     writer.Write((byte)ChunkType.INT8);
     writer.Write(value);
 }