001/* 002 * Copyright (c) 2020-2024 See AUTHORS file. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 */ 017 018package com.github.tommyettinger.kryo.cringe; 019 020import com.esotericsoftware.kryo.Kryo; 021import com.esotericsoftware.kryo.Serializer; 022import com.esotericsoftware.kryo.io.Input; 023import com.esotericsoftware.kryo.io.Output; 024import com.github.tommyettinger.cringe.UniqueIdentifier; 025 026/** 027 * Doesn't need anything else registered. The name doesn't match exactly; the class 028 * this serializes and deserializes is {@link UniqueIdentifier.Generator}. 029 * You usually will want to assign the result of {@link #read(Kryo, Input, Class)} to 030 * {@link UniqueIdentifier#GENERATOR}. Unlike in earlier versions, this does not assign 031 * to GENERATOR automatically. 032 */ 033public class UniqueIdentifierGeneratorSerializer extends Serializer<UniqueIdentifier.Generator> { 034 public UniqueIdentifierGeneratorSerializer() { 035 setImmutable(false); 036 setAcceptsNull(false); 037 } 038 039 @Override 040 public void write(final Kryo kryo, final Output output, final UniqueIdentifier.Generator data) { 041 output.writeInt(data.getA()); 042 output.writeInt(data.getB()); 043 output.writeInt(data.getC()); 044 output.writeInt(data.getD()); 045 } 046 047 @Override 048 public UniqueIdentifier.Generator read(final Kryo kryo, final Input input, final Class<? extends UniqueIdentifier.Generator> dataClass) { 049 return new UniqueIdentifier.Generator(input.readInt(), input.readInt(), input.readInt(), input.readInt()); 050 } 051 052 @Override 053 public UniqueIdentifier.Generator copy(Kryo kryo, UniqueIdentifier.Generator original) { 054 return new UniqueIdentifier.Generator(original.getA(), original.getB(), original.getC(), original.getD()); 055 } 056}