Changeset 23:89f426c7f59a in rrlib_serialization-java


Ignore:
Timestamp:
02.02.2015 01:15:56 (5 years ago)
Author:
Max Reichardt <mreichardt@…>
Branch:
default
Phase:
public
Message:

Added support for data compression

Files:
3 added
3 edited

Legend:

Unmodified
Added
Removed
  • BinaryInputStream.java

    r21 r23  
    2525import java.io.StringReader; 
    2626 
     27import org.rrlib.logging.Log; 
     28import org.rrlib.serialization.compression.Compressible; 
     29import org.rrlib.serialization.compression.DataCompressor; 
    2730import org.rrlib.serialization.rtti.DataTypeBase; 
    2831import org.rrlib.xml.XMLDocument; 
     
    854857            } 
    855858            return deserializeTo; 
     859        } else if (encoding == Serialization.DataEncoding.BINARY_COMPRESSED) { 
     860            String format = this.readString(); 
     861            if (format.length() == 0) { 
     862                return readObject(deserializeTo, type); 
     863            } else { 
     864                int size = this.readInt(); 
     865                if (deserializeTo == null) { 
     866                    deserializeTo = type.newInstance(); 
     867                } 
     868                if (deserializeTo instanceof Compressible) { 
     869                    ((Compressible)deserializeTo).decompressNext(this, format, size); 
     870                } else { 
     871                    DataCompressor compressor = new DataCompressor(type, format); 
     872                    compressor.decompressNext(this, deserializeTo, size); 
     873                } 
     874                return deserializeTo; 
     875            } 
    856876        } else { 
    857877            assert(encoding == Serialization.DataEncoding.XML); 
  • BinaryOutputStream.java

    r21 r23  
    620620        } else if (encoding == Serialization.DataEncoding.STRING) { 
    621621            writeString(Serialization.serialize(object)); 
     622        } else if (encoding == Serialization.DataEncoding.BINARY_COMPRESSED) { 
     623            // TODO actually compress data (currently not needed) 
     624            writeString(""); 
     625            writeObject(object, type); 
    622626        } else { 
    623627            assert(encoding == Serialization.DataEncoding.XML); 
  • Serialization.java

    r18 r23  
    4949 
    5050    /** Enum for different types of data encoding */ 
    51     public enum DataEncoding { BINARY, STRING, XML } 
     51    public enum DataEncoding { BINARY, STRING, XML, BINARY_COMPRESSED } 
    5252 
    5353    /** int -> hex char */ 
Note: See TracChangeset for help on using the changeset viewer.