private void SaveDefinitionFixups(IList <ResourceDefinitionFixup> fixups, StructureValueCollection values, IStream stream, ReflexiveCache <ResourceDefinitionFixup> cache) { var oldCount = (int)values.GetIntegerOrDefault("number of definition fixups", 0); uint oldAddress = values.GetIntegerOrDefault("definition fixup table address", 0); StructureLayout layout = _buildInfo.Layouts.GetLayout("definition fixup entry"); uint newAddress; if (!cache.TryGetAddress(fixups, out newAddress)) { // Write a new reflexive IEnumerable <StructureValueCollection> entries = fixups.Select(f => SerializeDefinitionFixup(f)); newAddress = ReflexiveWriter.WriteReflexive(entries, oldCount, oldAddress, fixups.Count, layout, _metaArea, _allocator, stream); cache.Add(newAddress, fixups); } else if (oldAddress != 0 && oldCount > 0) { // Reflexive was cached - just free it _allocator.Free(oldAddress, oldCount * layout.Size); } values.SetInteger("number of definition fixups", (uint)fixups.Count); values.SetInteger("definition fixup table address", newAddress); }
private void SaveBitArray(BitArray bits, string countName, string addressName, MetaAllocator allocator, IStream stream, ReflexiveCache <int> cache, StructureValueCollection values) { if (bits.Length == 0) { values.SetInteger(countName, 0); values.SetInteger(addressName, 0); return; } var ints = new int[((bits.Length + 31) & ~31) / 32]; bits.CopyTo(ints, 0); // If the address isn't cached, then allocate space and write a new array uint newAddress; if (!cache.TryGetAddress(ints, out newAddress)) { newAddress = allocator.Allocate(ints.Length * 4, stream); stream.SeekTo(_metaArea.PointerToOffset(newAddress)); foreach (int i in ints) { stream.WriteInt32(i); } cache.Add(newAddress, ints); } values.SetInteger(countName, (uint)ints.Length); values.SetInteger(addressName, newAddress); }
private void SaveSizeParts(IList <ResourceSizePart> parts, StructureValueCollection values, IStream stream, ReflexiveCache <ResourceSizePart> cache) { var oldCount = (int)values.GetIntegerOrDefault("number of size parts", 0); uint oldAddress = (uint)values.GetIntegerOrDefault("size part table address", 0); long expand = _expander.Expand(oldAddress); StructureLayout layout = _buildInfo.Layouts.GetLayout("size part table entry"); long newAddress; if (!cache.TryGetAddress(parts, out newAddress)) { // Write a new reflexive IEnumerable <StructureValueCollection> entries = parts.Select(p => SerializeSizePart(p)); newAddress = ReflexiveWriter.WriteReflexive(entries, oldCount, expand, parts.Count, layout, _metaArea, _allocator, stream); cache.Add(newAddress, parts); } else if (oldAddress != 0 && oldCount > 0) { // Reflexive was cached - just free it _allocator.Free(expand, oldCount * layout.Size); } uint cont = _expander.Contract(newAddress); values.SetInteger("number of size parts", (uint)parts.Count); values.SetInteger("size part table address", cont); }
private void SaveBitArray(BitArray bits, string countName, string addressName, MetaAllocator allocator, IStream stream, ReflexiveCache<int> cache, StructureValueCollection values) { if (bits.Length == 0) { values.SetInteger(countName, 0); values.SetInteger(addressName, 0); return; } var ints = new int[((bits.Length + 31) & ~31)/32]; bits.CopyTo(ints, 0); // If the address isn't cached, then allocate space and write a new array uint newAddress; if (!cache.TryGetAddress(ints, out newAddress)) { newAddress = allocator.Allocate(ints.Length*4, stream); stream.SeekTo(_metaArea.PointerToOffset(newAddress)); foreach (int i in ints) stream.WriteInt32(i); cache.Add(newAddress, ints); } values.SetInteger(countName, (uint)ints.Length); values.SetInteger(addressName, newAddress); }
private void SaveResourceFixups(IList<ResourceFixup> fixups, StructureValueCollection values, IStream stream, ReflexiveCache<ResourceFixup> cache) { var oldCount = (int) values.GetIntegerOrDefault("number of resource fixups", 0); uint oldAddress = values.GetIntegerOrDefault("resource fixup table address", 0); StructureLayout layout = _buildInfo.Layouts.GetLayout("resource fixup entry"); uint newAddress; if (!cache.TryGetAddress(fixups, out newAddress)) { // Write a new reflexive IEnumerable<StructureValueCollection> entries = fixups.Select(f => SerializeResourceFixup(f)); newAddress = ReflexiveWriter.WriteReflexive(entries, oldCount, oldAddress, fixups.Count, layout, _metaArea, _allocator, stream); cache.Add(newAddress, fixups); } else if (oldAddress != 0 && oldCount > 0) { // Reflexive was cached - just free it _allocator.Free(oldAddress, oldCount*layout.Size); } values.SetInteger("number of resource fixups", (uint) fixups.Count); values.SetInteger("resource fixup table address", newAddress); }