List<Expression<Integer, Resolver>> expressions = new ArrayList<Expression<Integer, Resolver>>();
List<Codec<?>> codecs = new ArrayList<Codec<?>>();
ByteOrder byteOrder = null;
for (Codec<?> codec : allCodecs) {
for (Class<?> valueType : codec.getTypes()) {
TypePrefix prefix = (TypePrefix) valueType
.getAnnotation(TypePrefix.class);
if (prefix == null) {
throw new CodecConstructionException(
"To little context to decide between codecs.");
} else {
if (byteOrder == null) {
byteOrder = prefix.byteOrder();
} else {
if (byteOrder != prefix.byteOrder()) {
throw new CodecConstructionException("Two distinct types of byte orders are not supported: "
+ "expected " + byteOrder.asText() + ", got "
+ prefix.byteOrder().asText() + " for " + codec);
}
}
if (size != -1) {
if (size != prefix.size()) {
throw new CodecConstructionException(
"Two distinct prefix sizes are not supported: "
+ "expected " + size + ", got "
+ prefix.size() + " for " + codec);
} else {
size = prefix.size();
}
}
if (size == -1)
size = prefix.size();
Expression<Integer, Resolver> value = Expressions
.createInteger(context, prefix.value());
expressions.add(value);
codecs.add(codec);
}
}
}