package it.cavallium.dbengine.database.serialization;
public class CodecsArray implements Codecs {
private final Codec[] codecs;
public CodecsArray() {
//noinspection unchecked
codecs = new Codec[256];
}
@Override
public synchronized void registerCodec(int id, Codec serializer) {
if (codecs[id] != null) {
throw new IllegalArgumentException("Codec " + id + " already registered!");
}
codecs[id] = serializer;
}
@Override
public Codec getCodec(int id) {
var codec = codecs[id];
if (codec == null) {
throw new UnsupportedOperationException("Unsupported codec " + id);
}
return codec;
}
}