Home / Function/ compress() — netty Function Reference

compress() — netty Function Reference

Architecture documentation for the compress() function in FastLz.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  2e9a6712_fc03_7631_0209_22e699baf3b2["compress()"]
  98671d94_5a6d_343c_6d73_292cd19cfd19["FastLz"]
  2e9a6712_fc03_7631_0209_22e699baf3b2 -->|defined in| 98671d94_5a6d_343c_6d73_292cd19cfd19
  dd7e1ac4_b45d_9cfb_2ce3_1576201c58e8["readU16()"]
  2e9a6712_fc03_7631_0209_22e699baf3b2 -->|calls| dd7e1ac4_b45d_9cfb_2ce3_1576201c58e8
  caa54910_d565_ad45_1f26_c35707051a0c["hashFunction()"]
  2e9a6712_fc03_7631_0209_22e699baf3b2 -->|calls| caa54910_d565_ad45_1f26_c35707051a0c
  style 2e9a6712_fc03_7631_0209_22e699baf3b2 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

codec-compression/src/main/java/io/netty/handler/codec/compression/FastLz.java lines 95–399

    @SuppressWarnings("IdentityBinaryExpression")
    static int compress(final ByteBuf input, final int inOffset, final int inLength,
                        final ByteBuf output, final int outOffset, final int proposedLevel) {
        final int level;
        if (proposedLevel == LEVEL_AUTO) {
            level = inLength < MIN_RECOMENDED_LENGTH_FOR_LEVEL_2 ? LEVEL_1 : LEVEL_2;
        } else {
            level = proposedLevel;
        }

        int ip = 0;
        int ipBound = ip + inLength - 2;
        int ipLimit = ip + inLength - 12;

        int op = 0;

        // const flzuint8* htab[HASH_SIZE];
        int[] htab = new int[HASH_SIZE];
        // const flzuint8** hslot;
        int hslot;
        // flzuint32 hval;
        // int OK b/c address starting from 0
        int hval;
        // flzuint32 copy;
        // int OK b/c address starting from 0
        int copy;

        /* sanity check */
        if (inLength < 4) {
            if (inLength != 0) {
                // *op++ = length-1;
                output.setByte(outOffset + op++, (byte) (inLength - 1));
                ipBound++;
                while (ip <= ipBound) {
                    output.setByte(outOffset + op++, input.getByte(inOffset + ip++));
                }
                return inLength + 1;
            }
            // else
            return 0;
        }

        /* initializes hash table */
        //  for (hslot = htab; hslot < htab + HASH_SIZE; hslot++)
        for (hslot = 0; hslot < HASH_SIZE; hslot++) {
            //*hslot = ip;
            htab[hslot] = ip;
        }

        /* we start with literal copy */
        copy = 2;
        output.setByte(outOffset + op++, MAX_COPY - 1);
        output.setByte(outOffset + op++, input.getByte(inOffset + ip++));
        output.setByte(outOffset + op++, input.getByte(inOffset + ip++));

        /* main loop */
        while (ip < ipLimit) {
            int ref = 0;

            long distance = 0;

            /* minimum match length */
            // flzuint32 len = 3;
            // int OK b/c len is 0 and octal based
            int len = 3;

            /* comparison starting-point */
            int anchor = ip;

            boolean matchLabel = false;

            /* check for a run */
            if (level == LEVEL_2) {
                //if(ip[0] == ip[-1] && FASTLZ_READU16(ip-1)==FASTLZ_READU16(ip+1))
                if (input.getByte(inOffset + ip) == input.getByte(inOffset + ip - 1) &&
                        readU16(input, inOffset + ip - 1) == readU16(input, inOffset + ip + 1)) {
                    distance = 1;
                    ip += 3;
                    ref = anchor + (3 - 1);

                    /*

Domain

Subdomains

Frequently Asked Questions

What does compress() do?
compress() is a function in the netty codebase, defined in codec-compression/src/main/java/io/netty/handler/codec/compression/FastLz.java.
Where is compress() defined?
compress() is defined in codec-compression/src/main/java/io/netty/handler/codec/compression/FastLz.java at line 95.
What does compress() call?
compress() calls 2 function(s): hashFunction, readU16.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free