@SuppressWarnings("unchecked") public ByteBuffer serialize() {
// see Javadoc of org.apache.cassandra.db.marshal.DynamicCompositeType for protocol description
int l = 0;
TypeCodec codec = TypeCodec.utf8Instance;
ByteBuffer[] types = new ByteBuffer[dataTypes.size()];
for (int i = 0; i < dataTypes.size(); i++) {
DataType dataType = dataTypes.get(i);
ByteBuffer arg = components.get(i);
// serialize type
String typeStr = dataType.cassandraType();
// TODO support type aliases for DynamicComposite
ByteBuffer typeBin = types[i] = codec.serialize(typeStr);
int sz = typeBin.remaining();
if (sz > 65535)
throw new IllegalArgumentException("Component at index #"+i+" in DynamicCompositeType too long ("+sz+") - max 65535 bytes in serialized form");
l += 2 + sz;