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 ch.qos.logback.classic.spi.LoggerContextVO;
17  import com.esotericsoftware.kryo.kryo5.Kryo;
18  import com.esotericsoftware.kryo.kryo5.Serializer;
19  import com.esotericsoftware.kryo.kryo5.io.Input;
20  import com.esotericsoftware.kryo.kryo5.io.Output;
21  
22  import java.util.Map;
23  
24  /**
25   * Serializer for {@link LoggerContextVO} used by the vanilla stream format.
26   *
27   * <p>Relies only on the public API of {@link LoggerContextVO}. Kryo's reflection based
28   * FieldSerializer would require module ch.qos.logback.classic to open package
29   * ch.qos.logback.classic.spi.
30   */
31  public class VanillaLoggerContextVOSerializer extends Serializer<LoggerContextVO> {
32  
33      @Override
34      public void write(Kryo kryo, Output output, LoggerContextVO loggerContextVO) {
35          output.writeString(loggerContextVO.getName());
36          output.writeVarLong(loggerContextVO.getBirthTime(), false);
37          kryo.writeClassAndObject(output, loggerContextVO.getPropertyMap());
38      }
39  
40      @Override
41      @SuppressWarnings("unchecked")
42      public LoggerContextVO read(Kryo kryo, Input input, Class<? extends LoggerContextVO> type) {
43          String name = input.readString();
44          long birthTime = input.readVarLong(false);
45          Map<String, String> propertyMap = (Map<String, String>) kryo.readClassAndObject(input);
46          return new LoggerContextVO(name, propertyMap, birthTime);
47      }
48  }