}
/** Serialize given AIS. Allocates a new buffer if necessary so always use <i>returned</i> buffer. */
private static ByteBuffer serialize(ByteBuffer buffer, AkibanInformationSchema ais, ProtobufWriter.WriteSelector selector) {
ProtobufWriter writer = new ProtobufWriter(selector);
writer.save(ais);
int size = writer.getBufferSize();
if(buffer == null || (buffer.capacity() < size)) {
buffer = ByteBuffer.allocate(size);
}
buffer.clear();