public static string CompressMemory2Hex(object obj, AcedCompressionLevel level) { if (null == obj) { return(string.Empty); } return(ConverService.Bytes2Hex(MemoryCompress(obj, level))); }
public static byte[] MemoryCompress(object obj, AcedCompressionLevel level) { byte[] objs = SerializerService.Serialize(obj); AcedDeflator instance = new AcedDeflator(); byte[] bytes = instance.Compress(objs, 0, objs.Length, level, 0, 0); return(bytes); }
public static string CompressMemory2Hex(object obj, AcedCompressionLevel level) { if (null == obj) { return string.Empty; } return ConverService.Bytes2Hex(MemoryCompress(obj, level)); }
private void SetupCompressionLevel(AcedCompressionLevel compressionLevel) { switch (compressionLevel) { case AcedCompressionLevel.Fastest: _hashSize = hashSizeFastest; _hashMask = hashMaskFastest; _prevSize = prevSizeFastest; _prevMask = prevMaskFastest; _maxChain = chainFastest; _shift = shiftFastest; break; case AcedCompressionLevel.Fast: _hashSize = hashSizeFast; _hashMask = hashMaskFast; _prevSize = prevSizeFast; _prevMask = prevMaskFast; _maxChain = chainFast; _shift = shiftFast; break; case AcedCompressionLevel.Normal: _hashSize = hashSizeNormal; _hashMask = hashMaskNormal; _prevSize = prevSizeNormal; _prevMask = prevMaskNormal; _maxChain = chainNormal; _shift = shiftNormal; break; case AcedCompressionLevel.Maximum: _hashSize = hashSizeMaximum; _hashMask = hashMaskMaximum; _prevSize = prevSizeMaximum; _prevMask = prevMaskMaximum; _maxChain = chainMaximum; _shift = shiftMaximum; break; } }
public unsafe int Compress(byte[] sourceBytes, int sourceIndex, int sourceLength, AcedCompressionLevel compressionLevel, byte[] destinationBytes, int destinationIndex) { _tryMode = false; if (destinationBytes != null) _dstBreak = destinationBytes.Length - destinationIndex - 4; else { _tryMode = true; destinationBytes = _fakeDestinationBytes; destinationIndex = 0; _dstBreak = sourceLength; } if (sourceLength == 0) { if (!_tryMode) { if (_dstBreak < 0) AcedMCException.ThrowNoPlaceToStoreCompressedDataException(); fixed (byte* pDstBytes = &destinationBytes[destinationIndex]) *((int*)pDstBytes) = 0; } return 4; } if (sourceBytes == null) AcedMCException.ThrowArgumentNullException("sourceBytes"); _growMode = false; if (sourceLength < _dstBreak) _dstBreak = sourceLength; _breakOffset = sourceLength; fixed (byte* pSrcBytes = &sourceBytes[sourceIndex], pDstBytes = &destinationBytes[destinationIndex]) { _pSrcBytes = pSrcBytes; _pDstBytes = pDstBytes; int result = -1; if (sourceLength > 3 && compressionLevel != AcedCompressionLevel.Store) { SetupCompressionLevel(compressionLevel); if (!_tryMode) { if (_dstBreak < 0) AcedMCException.ThrowNoPlaceToStoreCompressedDataException(); *((int*)_pDstBytes) = sourceLength; _pDstBytes += 4; } result = CompressCore(); } if (result < 0) { if (!_tryMode) { if (_dstBreak < sourceLength) AcedMCException.ThrowNoPlaceToStoreCompressedDataException(); *((int*)pDstBytes) = -sourceLength; Buffer.BlockCopy(sourceBytes, sourceIndex, destinationBytes, destinationIndex + 4, sourceLength); } result = sourceLength; } return result + 4; } }
public unsafe byte[] Compress(byte[] sourceBytes, int sourceIndex, int sourceLength, AcedCompressionLevel compressionLevel, int beforeGap, int afterGap) { if (sourceLength == 0) return new byte[beforeGap + afterGap + 4]; if (sourceBytes == null) AcedMCException.ThrowArgumentNullException("sourceBytes"); _growMode = true; _tryMode = false; _chunkList = null; _chunk = new uint[AcedConsts.ChunkCapacity]; _chunkLength = 0; _dstBreak = sourceLength; _breakOffset = sourceLength; _pDstBytes = null; byte[] result; fixed (byte* pSrcBytes = &sourceBytes[sourceIndex]) { _pSrcBytes = pSrcBytes; int outSize = -1; if (sourceLength > 3 && compressionLevel != AcedCompressionLevel.Store) { SetupCompressionLevel(compressionLevel); outSize = CompressCore(); } if (outSize > 0) { result = new byte[beforeGap + 4 + outSize + afterGap]; fixed (byte* pResult = &result[beforeGap]) *((int*)pResult) = sourceLength; beforeGap += 4; outSize--; int n = outSize >> AcedConsts.ChunkShift; for (int i = 0; i < n; i++) { Buffer.BlockCopy((uint[])_chunkList[i], 0, result, beforeGap, AcedConsts.ChunkCapacity * 4); beforeGap += AcedConsts.ChunkCapacity * 4; } Buffer.BlockCopy(_chunk, 0, result, beforeGap, (outSize & ((AcedConsts.ChunkCapacity * 4) - 1)) + 1); _chunkList = null; _chunk = null; } else { _chunkList = null; _chunk = null; result = new byte[beforeGap + 4 + sourceLength + afterGap]; fixed (byte* pResult = &result[beforeGap]) *((int*)pResult) = -sourceLength; Buffer.BlockCopy(sourceBytes, sourceIndex, result, beforeGap + 4, sourceLength); } } return result; }
public static byte[] MemoryCompress(object obj, AcedCompressionLevel level) { byte[] objs = SerializerService.Serialize(obj); AcedDeflator instance = new AcedDeflator(); byte[] bytes = instance.Compress(objs, 0, objs.Length, level, 0, 0); return bytes; }