View Javadoc
1   /*
2    * Logback: the reliable, generic, fast and flexible logging framework.
3    * Copyright (C) 1999-2026, QOS.ch. All rights reserved.
4    *
5    * This program and the accompanying materials are dual-licensed under
6    * either the terms of the Eclipse Public License v2.0 as published by
7    * the Eclipse Foundation
8    *
9    *   or (per the licensee's choosing)
10   *
11   * under the terms of the GNU Lesser General Public License version 2.1
12   * as published by the Free Software Foundation.
13   */
14  package ch.qos.logback.classic.kryo;
15  
16  import java.util.Objects;
17  
18  public final class EncoderVersionTag {
19  
20      private final KryoEncoder.SerializerType serializerType;
21      private final byte streamVersion;
22  
23      public EncoderVersionTag(KryoEncoder.SerializerType serializerType, byte streamVersion) {
24          this.serializerType = serializerType;
25          this.streamVersion = streamVersion;
26      }
27  
28      public KryoEncoder.SerializerType serializerType() {
29          return serializerType;
30      }
31  
32      public byte streamVersion() {
33          return streamVersion;
34      }
35  
36      @Override
37      public boolean equals(Object o) {
38          if (this == o)
39              return true;
40          if (!(o instanceof EncoderVersionTag))
41              return false;
42          EncoderVersionTag that = (EncoderVersionTag) o;
43          return serializerType == that.serializerType && streamVersion == that.streamVersion;
44      }
45  
46      @Override
47      public int hashCode() {
48          return Objects.hash(serializerType, streamVersion);
49      }
50  
51      @Override
52      public String toString() {
53          return "EncoderVersionTag[serializerType=" + serializerType + ", streamVersion=" + streamVersion + "]";
54      }
55  
56  
57      static EncoderVersionTag PATTERN_VANILLA = new EncoderVersionTag(null, (byte) 0);
58      static EncoderVersionTag PATTERN_V5 = new EncoderVersionTag(null, (byte) 0);
59  
60      static EncoderVersionTag VANILLA = new EncoderVersionTag(KryoEncoder.SerializerType.Vanilla, KryoClassicConstants.STREAM_VERSION_0);
61      static EncoderVersionTag CUSTOM_V5 = new EncoderVersionTag(KryoEncoder.SerializerType.Custom, KryoClassicConstants.STREAM_VERSION_5);
62  
63  
64      static final String CUSTOM_KRYO_SUFFIX_V5 = "-custom-v5.kryo";
65      static final String VANILLA_KRYO_SUFFIX = "-vanilla.kryo";
66  
67  
68      static final String DIRECT_LOG_SUFFIX = ".log";
69      static final String LOG_SUFFIX_VANILLA = ".log-vanilla";
70      static final String LOG_SUFFIX_V5 = ".log-v5";
71  
72      public String toSuffix() {
73  
74          if (serializerType == null) {
75              if (this == PATTERN_VANILLA)
76                  return LOG_SUFFIX_VANILLA;
77              if (this == PATTERN_V5)
78                  return LOG_SUFFIX_V5;
79          }
80  
81  
82          if (serializerType == KryoEncoder.SerializerType.Vanilla) {
83              return VANILLA_KRYO_SUFFIX;
84          }
85  
86          if (serializerType == KryoEncoder.SerializerType.Custom) {
87              if (streamVersion == KryoClassicConstants.STREAM_VERSION_5)
88                  return CUSTOM_KRYO_SUFFIX_V5;
89          }
90  
91          throw new
92  
93                  IllegalArgumentException("Unknown EncoderType: " + this);
94  
95      }
96  
97  
98  }