001/* 002 * Logback: the reliable, generic, fast and flexible logging framework. 003 * Copyright (C) 1999-2026, QOS.ch. All rights reserved. 004 * 005 * This program and the accompanying materials are dual-licensed under 006 * either the terms of the Eclipse Public License v2.0 as published by 007 * the Eclipse Foundation 008 * 009 * or (per the licensee's choosing) 010 * 011 * under the terms of the GNU Lesser General Public License version 2.1 012 * as published by the Free Software Foundation. 013 */ 014package ch.qos.logback.classic.kryo; 015 016import ch.qos.logback.classic.spi.LoggerContextVO; 017import com.esotericsoftware.kryo.kryo5.Kryo; 018import com.esotericsoftware.kryo.kryo5.Serializer; 019import com.esotericsoftware.kryo.kryo5.io.Input; 020import com.esotericsoftware.kryo.kryo5.io.Output; 021 022import java.util.Map; 023 024/** 025 * Serializer for {@link LoggerContextVO} used by the vanilla stream format. 026 * 027 * <p>Relies only on the public API of {@link LoggerContextVO}. Kryo's reflection based 028 * FieldSerializer would require module ch.qos.logback.classic to open package 029 * ch.qos.logback.classic.spi. 030 */ 031public class VanillaLoggerContextVOSerializer extends Serializer<LoggerContextVO> { 032 033 @Override 034 public void write(Kryo kryo, Output output, LoggerContextVO loggerContextVO) { 035 output.writeString(loggerContextVO.getName()); 036 output.writeVarLong(loggerContextVO.getBirthTime(), false); 037 kryo.writeClassAndObject(output, loggerContextVO.getPropertyMap()); 038 } 039 040 @Override 041 @SuppressWarnings("unchecked") 042 public LoggerContextVO read(Kryo kryo, Input input, Class<? extends LoggerContextVO> type) { 043 String name = input.readString(); 044 long birthTime = input.readVarLong(false); 045 Map<String, String> propertyMap = (Map<String, String>) kryo.readClassAndObject(input); 046 return new LoggerContextVO(name, propertyMap, birthTime); 047 } 048}