View Javadoc
1   /*
2    * Copyright 2014 The Netty Project
3    *
4    * The Netty Project licenses this file to you under the Apache License,
5    * version 2.0 (the "License"); you may not use this file except in compliance
6    * with the License. You may obtain a copy of the License at:
7    *
8    *   https://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13   * License for the specific language governing permissions and limitations
14   * under the License.
15   */
16  package io.netty.handler.codec.compression;
17  
18  final class Lz4Constants {
19      /**
20       * Magic number of LZ4 block.
21       */
22      static final long MAGIC_NUMBER = (long) 'L' << 56 |
23                                       (long) 'Z' << 48 |
24                                       (long) '4' << 40 |
25                                       (long) 'B' << 32 |
26                                              'l' << 24 |
27                                              'o' << 16 |
28                                              'c' << 8  |
29                                              'k';
30  
31      /**
32       * Full length of LZ4 block header.
33       */
34      static final int HEADER_LENGTH = 8 +  // magic number
35                                       1 +  // token
36                                       4 +  // compressed length
37                                       4 +  // decompressed length
38                                       4;   // checksum
39  
40      /**
41       * Offsets of header's parts.
42       */
43      static final int TOKEN_OFFSET = 8;
44  
45      static final int COMPRESSED_LENGTH_OFFSET = TOKEN_OFFSET + 1;
46      static final int DECOMPRESSED_LENGTH_OFFSET = COMPRESSED_LENGTH_OFFSET + 4;
47      static final int CHECKSUM_OFFSET = DECOMPRESSED_LENGTH_OFFSET + 4;
48  
49      /**
50       * Base value for compression level.
51       */
52      static final int COMPRESSION_LEVEL_BASE = 10;
53  
54      /**
55       * LZ4 block sizes.
56       */
57      static final int MIN_BLOCK_SIZE = 64;
58      static final int MAX_BLOCK_SIZE = 1 << COMPRESSION_LEVEL_BASE + 0x0F;   //  32 M
59      static final int DEFAULT_BLOCK_SIZE = 1 << 16;  // 64 KB
60  
61      /**
62       * LZ4 block types.
63       */
64      static final int BLOCK_TYPE_NON_COMPRESSED = 0x10;
65      static final int BLOCK_TYPE_COMPRESSED = 0x20;
66  
67      /**
68       * Default seed value for xxhash.
69       */
70      static final int DEFAULT_SEED = 0x9747b28c;
71  
72      private Lz4Constants() { }
73  }