getBestCodec<T> function
Implementation
int getBestCodec<T>(List<BitCodec<T>> codecs, T value) {
int smallest = -1;
int bestCodec = -1;
for (int i = 0; i < codecs.length; i++) {
int size = getCodecWrittenSize(codecs[i], value);
if (size < 0) {
continue;
}
if (smallest == -1 || size < smallest) {
smallest = size;
bestCodec = i;
}
}
if (bestCodec == -1) {
throw Exception("No codec could write $value");
}
return bestCodec;
}