org.djutils.serialization.serializers.ObjectSerializer Maven / Gradle / Ivy
Show all versions of djutils-serialization Show documentation
package org.djutils.serialization.serializers;
import org.djutils.serialization.EndianUtil;
import org.djutils.serialization.SerializationException;
/**
* Serializer for simple classes.
*
* Copyright (c) 2019-2023 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
* BSD-style license. See DJUTILS License.
*
* @version $Revision$, $LastChangedDate$, by $Author$,
* @author Alexander Verbraeck
* @author Peter Knoppers
* @param class
*/
public abstract class ObjectSerializer extends BasicSerializer
{
/**
* Construct a new ObjectSerializer.
* @param type byte; the field type (returned by the fieldType
method)
* @param dataClassName String; returned by the dataClassName method
*/
public ObjectSerializer(final byte type, final String dataClassName)
{
super(type, dataClassName);
}
@Override
public final int sizeWithPrefix(final T object) throws SerializationException
{
return 1 + size(object);
}
@Override
public final void serializeWithPrefix(final T object, final byte[] buffer, final Pointer pointer,
final EndianUtil endianUtil) throws SerializationException
{
buffer[pointer.getAndIncrement(1)] = fieldType();
serialize(object, buffer, pointer, endianUtil);
}
@Override
public final int getNumberOfDimensions()
{
return 0;
}
}