// JavaDoc inherited.
@SuppressWarnings("unchecked")
public <T> Codec<T> create(AnnotatedElement metadata, Class<T> type,
ResolverContext context) {
BoundList settings = null;
if (metadata != null
&& (settings = metadata.getAnnotation(BoundList.class)) != null
&& java.util.List.class.equals(type)) {
Codec<?> codec = createElementCodec(context, settings);
if (settings.size().length() == 0) {
// So, we don't know the number of elements in this list.
// This means we need to keep on reading elements until we get
// an 'EOF' or a DecodingException. In case of a
// DecodingException, the pointer is expected to be moved back
// to the first position.
return (Codec<T>) new DynamicListCodec(codec);
} else if (settings.offset().length() != 0) {
// So the size is known. If the offset attribute has been set,
// it means we can calculate the position of the individual
// elements based on the index of that element.
Expression<Integer, Resolver> size = getSizeExpression(
settings, context);
Expression<Integer, Resolver> offsets = null;
CodecDescriptorHolder holder = new CodecDescriptorHolder();
offsets = Expressions.createInteger(new IndexedResolverContext(
context, holder), settings.offset());
Codec<T> result = (Codec<T>) new OffsetListCodec(offsets, size,
codec);
// TODO:
holder.setDescriptor(result.getCodecDescriptor());
return result;