/**
* {@inheritDoc}
*/
@Override
public <T> int serialize(T obj, Class<T> type, OutputStream out) throws IOException {
out = new CountingOutputStream(new BufferedOutputStream(out, getBufferSize()));
Schema<T> schema = RuntimeSchema.getSchema(type);
writeTo(out, obj, schema);
return ((CountingOutputStream)out).getCount();
}