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 ch.qos.logback.core.kryo.SerializerBase;
018import com.esotericsoftware.kryo.kryo5.Kryo;
019import com.esotericsoftware.kryo.kryo5.io.Input;
020import com.esotericsoftware.kryo.kryo5.io.Output;
021import com.esotericsoftware.kryo.kryo5.minlog.Log;
022
023import java.util.HashMap;
024
025public class LoggerContextVOSerializer extends SerializerBase<LoggerContextVO> {
026
027
028    public LoggerContextVOSerializer(int capacity) {
029        super(BiMapType.DIRECT_MAP, capacity);
030        setAcceptsNull(false);
031    }
032
033    @Override
034    protected void writeNewEntry(Kryo kryo, Output output, LoggerContextVO loggerContextVO) {
035        //Log.info("writeNewEntry for LoggerContextVO: " + loggerContextVO);
036        kryo.writeObject(output, loggerContextVO.getName());
037        output.writeLong(loggerContextVO.getBirthTime());
038        kryo.writeObject(output, loggerContextVO.getPropertyMap());
039    }
040
041    @Override
042    protected LoggerContextVO readNewEntry(Kryo kryo, Input input) {
043        //Log.info("readNewEntry for LoggerContextVO: ");
044        String name = kryo.readObject(input, String.class);
045        long birthTime = input.readLong();
046        HashMap<?, ?> map = kryo.readObject(input, java.util.HashMap.class);
047        LoggerContextVO deserialized = new LoggerContextVO(name, (HashMap<String, String>) map, birthTime);
048        //Log.info("readNewEntry for LoggerContextVO named " + name);
049        return deserialized;
050    }
051
052}