private void Parse(Stream s) { if (s == null) { s = this.UnParse(); } s.Position = 0; BinaryReader r = new BinaryReader(s); uint magic = r.ReadUInt32(); if (checking) { if (magic != FOURCC("STBL")) { throw new InvalidDataException( string.Format("Expected magic tag 0x{0:X8}; read 0x{1:X8}; position 0x{2:X8}", FOURCC("STBL"), magic, s.Position)); } } this.version = r.ReadUInt16(); if (checking) { if (this.version != 0x05) { throw new InvalidDataException( string.Format("Expected version 0x05; read 0x{0:X2}; position 0x{1:X8}", this.version, s.Position)); } } this.isCompressed = r.ReadByte(); this.numEntries = r.ReadUInt64(); this.reserved = r.ReadBytes(2); this.stringLength = r.ReadUInt32(); this.entries = new StringEntryList(this.OnResourceChanged, s, this.numEntries); }
protected override Stream UnParse() { Stream memoryStream = new MemoryStream(); BinaryWriter writer = new BinaryWriter(memoryStream); writer.Write((uint)FOURCC("STBL")); writer.Write(this.version); writer.Write(this.isCompressed); if (this.entries == null) { this.entries = new StringEntryList(this.OnResourceChanged); } writer.Write((ulong)this.entries.Count); if (this.reserved == null) { this.reserved = new byte[2]; } writer.Write(this.reserved); long sizePosition = writer.BaseStream.Position; writer.Write(0x00000000); uint actualSize = 0; foreach (StringEntry entry in this.entries) { entry.UnParse(memoryStream); actualSize += entry.EntrySize; } writer.BaseStream.Position = sizePosition; writer.Write(actualSize); memoryStream.Position = 0; return(memoryStream); }