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); }
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); }
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); }
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); } }
public void writeFloat64(IffTag tag, Double value) { writer.Write(IffTag.TagByteSwap(tag.value)); writer.Write((byte)ChunkType.FLOAT64); writer.Write(value); }
public void writeFloat32(IffTag tag, Single value) { writer.Write(IffTag.TagByteSwap(tag.value)); writer.Write((byte)ChunkType.FLOAT32); writer.Write(value); }
public void writeInt64(IffTag tag, Int64 value) { writer.Write(IffTag.TagByteSwap(tag.value)); writer.Write((byte)ChunkType.INT64); writer.Write(value); }
public void writeInt8(IffTag tag, byte value) { writer.Write(IffTag.TagByteSwap(tag.value)); writer.Write((byte)ChunkType.INT8); writer.Write(value); }
public void writeUInt32(IffTag tag, UInt32 value) { writer.Write(IffTag.TagByteSwap(tag.value)); writer.Write((byte)ChunkType.UINT32); writer.Write(value); }
public void writeBool(IffTag tag, bool value) { writer.Write(IffTag.TagByteSwap(tag.value)); writer.Write((byte)ChunkType.UINT8); writer.Write(Convert.ToByte(value)); }