aboutsummaryrefslogtreecommitdiffstats
path: root/vespajlib/src/main/java/com/yahoo/compress/CompressionType.java
blob: db0b039ea92558ebaf9e44ee8cf980c119968fcd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.compress;

/**
 * Compression type enum.
 *
 * @author bratseth
 */
public enum CompressionType {

    // Do not change the type->ordinal association. The gap is due to historic types no longer supported.
    NONE((byte) 0),
    INCOMPRESSIBLE((byte) 5),
    LZ4((byte) 6),
    ZSTD((byte) 7);

    private final byte code;

    CompressionType(byte code) {
        this.code = code;
    }

    public byte getCode() {
        return code;
    }

    /**
     * Returns whether this type represent actually compressed data
     */
    public boolean isCompressed() {
        return this != NONE && this != INCOMPRESSIBLE;
    }

    public static CompressionType valueOf(byte value) {
        switch (value) {
            case ((byte) 0):
                return NONE;
            case ((byte) 5):
                return INCOMPRESSIBLE;
            case ((byte) 6):
                return LZ4;
            case ((byte) 7):
                return ZSTD;
            default:
                throw new IllegalArgumentException("Unknown compression type ordinal " + value);
        }
    }

}