Class DeflaterSerializer

All Implemented Interfaces:
MoleculerLifecycle

public class DeflaterSerializer extends ChainedSerializer
Message compressor / decompressor. Sample of usage:
Transporter trans = new NatsTransporter("localhost");
trans.setSerializer(new DeflaterSerializer());
ServiceBroker broker = ServiceBroker.builder().nodeID("node1").transporter(trans).build();
Chaining Serializers (serialize then compress then encrypt packets):
Transporter trans = new NatsTransporter("localhost");
MsgPackSerializer msgPack = new MsgPackSerializer();
DeflaterSerializer deflater = new DeflaterSerializer(msgPack);
BlockCipherSerializer cipher = new BlockCipherSerializer(deflater);
trans.setSerializer(cipher);
  • Field Details

    • threshold

      protected int threshold
      Compress key and/or value above this size (BYTES), 0 = disable compression
    • compressionLevel

      protected int compressionLevel
      Compression level (best speed = 1, best compression = 9)
  • Constructor Details

    • DeflaterSerializer

      public DeflaterSerializer()
      Creates a JSON-based Serializer that compresses content above 1024 bytes with compression level "1".
    • DeflaterSerializer

      public DeflaterSerializer(int threshold)
      Creates a JSON-based Serializer that compresses content above a specified size (see the "compressAbove" parameter).
      Parameters:
      threshold - Compress key and/or value above this size (BYTES), 0 = disable compression
    • DeflaterSerializer

      public DeflaterSerializer(int threshold, int compressionLevel)
      Creates a JSON-based Serializer that compresses content above a specified size with the specified compression level (1-9).
      Parameters:
      threshold - Compress key and/or value above this size (BYTES), 0 = disable compression
      compressionLevel - Compression level (best speed = 1, best compression = 9)
    • DeflaterSerializer

      public DeflaterSerializer(Serializer parent)
      Creates a custom Serializer that compresses content above 1024 bytes size with the compression level "1".
      Parameters:
      parent - parent Serializer (eg. a JsonSerializer)
    • DeflaterSerializer

      public DeflaterSerializer(Serializer parent, int threshold, int compressionLevel)
      Creates a custom Serializer that compresses content above a specified size with the specified compression level (1-9).
      Parameters:
      parent - parent Serializer (eg. a JsonSerializer)
      threshold - Compress key and/or value above this size (BYTES), 0 = disable compression
      compressionLevel - Compression level (best speed = 1, best compression = 9)
  • Method Details

    • write

      public byte[] write(io.datatree.Tree value) throws Exception
      Overrides:
      write in class Serializer
      Throws:
      Exception
    • read

      public io.datatree.Tree read(byte[] source) throws Exception
      Overrides:
      read in class Serializer
      Throws:
      Exception
    • getCompressionLevel

      public int getCompressionLevel()
    • setCompressionLevel

      public void setCompressionLevel(int compressionLevel)
    • getThreshold

      public int getThreshold()
    • setThreshold

      public void setThreshold(int threshold)