最新消息:ww12345678 的部落格重装上线,希望大家继续支持。

Container to bindata, and back again

网络文摘 William 2631浏览 0评论

I was recently engaged in a bug where the size of container caused problems. The solution we arrived at was to implement compression of the container. The solution is trivial; but the APIs to get there took me a while to discover, and as I couldn’t find any other post on this, I’m sharing it.

How to implement compression/decompression of pack/unpack methods using BinData and ContainerClass.

 

public container pack() 

{

    // Business as usual…  

    container result = [#currentVersion, #currentList]; 

 

    // Compress  

    ContainerClass containerClass = new ContainerClass(result);  

    binData = new BinData();  

    binData.setData(containerClass.toBlob());  

    binData.compressLZ77(12);  

 

    return binData.getData();  

}  

 

  1. public boolean unpack(container  _compressed)  
  2. {
  3.     // Decompress          
  4.     BinData  binData  =  new  BinData();        
  5.     binData.setData(_compressed);        
  6.     binData.decompressLZ77();        
  7.     container packed = ContainerClass::blob2Container(binData.getData());
  8.  
  9.     // Business as usual…          
  10.     Version version = RunBase::getVersion(packed);        
  11.     switch (version)
  12.      {            
  13.         case #CurrentVersion:  
  14.              [version, #currentList] = packed;                
  15.             break;            
  16.         default:  
  17.             return false;        
  18.     }        
  19.     return true;    
  20. }    

     

    THIS POST IS PROVIDED AS-IS; AND CONFERS NO RIGHTS.

转载请注明:ww12345678 的部落格 | AX Helper » Container to bindata, and back again

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址