Container to bindata, and back again


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.

 

  1. public container pack()  
  2. {
  3.     // Business as usual...          
  4.     container result = [#currentVersion, #currentList];
  5.  
  6.     // Compress          
  7.     ContainerClass containerClass = new ContainerClass(result);        
  8.     binData = new BinData();        
  9.     binData.setData(containerClass.toBlob());        
  10.     binData.compressLZ77(12);        
  11.     return  binData.getData();    
  12. }    

     

  13. public boolean unpack(container  _compressed)  
  14. {
  15.     // Decompress          
  16.     BinData binData = new BinData();        
  17.     binData.setData(_compressed);        
  18.     binData.decompressLZ77();        
  19.     container packed = ContainerClass::blob2Container(binData.getData());
  20.  
  21.     // Business as usual...          
  22.     Version version = RunBase::getVersion(packed);        
  23.     switch (version)
  24.      {            
  25.         case #CurrentVersion:  
  26.              [version, #currentList] = packed;                
  27.             break;            
  28.         default:  
  29.             return false;        
  30.     }        
  31.     return true;    
  32. }    

     

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


Comments (0)

Skip to main content