Class JSONzip

  • All Implemented Interfaces:
    None, PostMortem
    Direct Known Subclasses:
    Unzipper, Zipper

    public abstract class JSONzip
    extends java.lang.Object
    implements None, PostMortem
    JSONzip is a binary-encoded JSON dialect. It is designed to compress the messages in a session in bandwidth constrained applications, such as mobile. JSONzip is adaptive, so with each message seen, it should improve its compression. It minimizes JSON's overhead, reducing punctuation to a small number of bits. It uses Huffman encoding to reduce the average size of characters. It uses caches (or Keeps) to keep recently seen strings and values, so repetitive content (such as object keys) can be substantially reduced. It uses a character encoding called Kim (Keep it minimal) that is smaller than UTF-8 for most East European, African, and Asian scripts. JSONzip tends to reduce most content by about half. If there is a lot of recurring information, the reduction can be much more dramatic. FOR EVALUATION PURPOSES ONLY. THIS PACKAGE HAS NOT YET BEEN TESTED ADEQUATELY FOR PRODUCTION USE.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static byte[] bcd
      The characters in JSON numbers can be reduced to 4 bits each.
      static int end
      The end of string code.
      static int endOfNumber
      The end of number code.
      static long int14
      The first positive integer that cannot be encoded in 14 bits.
      static long int4
      The first positive integer that cannot be encoded in 4 bits.
      static long int7
      The first positive integer that cannot be encoded in 7 bits.
      protected Huff namehuff
      A Huffman encoder for names.
      protected Huff namehuffext
      A Huffman encoder for names extended bytes.
      protected totalcross.json.zip.Keep namekeep
      A place to keep the names (keys).
      static boolean probe
      The package supports tracing for debugging.
      protected Huff stringhuff
      A Huffman encoder for string values.
      protected Huff stringhuffext
      A Huffman encoder for string values extended bytes.
      protected totalcross.json.zip.Keep stringkeep
      A place to keep the strings.
      protected totalcross.json.zip.Keep valuekeep
      A place to keep the values.
      static int zipArrayString
      The value code for an array with a string as its first element.
      static int zipArrayValue
      The value code for an array with a non-string value as its first element.
      static int zipEmptyArray
      The value code for an empty array.
      static int zipEmptyObject
      The value code for an empty object.
      static int zipFalse
      The value code for false.
      static int zipNull
      The value code for null.
      static int zipObject
      The value code for a non-empty object.
      static int zipTrue
      The value code for true.
      • Fields inherited from interface totalcross.json.zip.None

        none
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected JSONzip()
      Initialize the data structures.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected void generate()
      Generate the Huffman tables.
      boolean postMortem​(PostMortem pm)
      This method is used for testing the implementation of JSONzip.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • bcd

        public static final byte[] bcd
        The characters in JSON numbers can be reduced to 4 bits each.
      • endOfNumber

        public static final int endOfNumber
        The end of number code.
      • int4

        public static final long int4
        The first positive integer that cannot be encoded in 4 bits.
        See Also:
        Constant Field Values
      • int7

        public static final long int7
        The first positive integer that cannot be encoded in 7 bits.
        See Also:
        Constant Field Values
      • int14

        public static final long int14
        The first positive integer that cannot be encoded in 14 bits.
        See Also:
        Constant Field Values
      • probe

        public static final boolean probe
        The package supports tracing for debugging.
        See Also:
        Constant Field Values
      • zipEmptyObject

        public static final int zipEmptyObject
        The value code for an empty object.
        See Also:
        Constant Field Values
      • zipEmptyArray

        public static final int zipEmptyArray
        The value code for an empty array.
        See Also:
        Constant Field Values
      • zipObject

        public static final int zipObject
        The value code for a non-empty object.
        See Also:
        Constant Field Values
      • zipArrayString

        public static final int zipArrayString
        The value code for an array with a string as its first element.
        See Also:
        Constant Field Values
      • zipArrayValue

        public static final int zipArrayValue
        The value code for an array with a non-string value as its first element.
        See Also:
        Constant Field Values
      • namehuff

        protected final Huff namehuff
        A Huffman encoder for names.
      • namehuffext

        protected final Huff namehuffext
        A Huffman encoder for names extended bytes.
      • namekeep

        protected final totalcross.json.zip.Keep namekeep
        A place to keep the names (keys).
      • stringhuff

        protected final Huff stringhuff
        A Huffman encoder for string values.
      • stringhuffext

        protected final Huff stringhuffext
        A Huffman encoder for string values extended bytes.
      • stringkeep

        protected final totalcross.json.zip.Keep stringkeep
        A place to keep the strings.
      • valuekeep

        protected final totalcross.json.zip.Keep valuekeep
        A place to keep the values.
    • Constructor Detail

      • JSONzip

        protected JSONzip()
        Initialize the data structures.
    • Method Detail

      • generate

        protected void generate()
        Generate the Huffman tables.
      • postMortem

        public boolean postMortem​(PostMortem pm)
        This method is used for testing the implementation of JSONzip. It is not suitable for any other purpose. It is used to compare a Compressor and a Decompressor, verifying that the data structures that were built during zipping and unzipping were the same.
        Specified by:
        postMortem in interface PostMortem
        Parameters:
        pm - Another object of the same type.
        Returns:
        true if the structures match.