/** * Initializes the state of the encoder based on the schema and number of operations to encode. * * @param schema the schema of the table which the operations belong to. * @param numOperations the number of operations. */ private void init(Schema schema, int numOperations) { this.schema = schema; // Set up the encoded data. // Estimate a maximum size for the data. This is conservative, but avoids // having to loop through all the operations twice. final int columnBitSetSize = Bytes.getBitSetSize(schema.getColumnCount()); int sizePerRow = 1 /* for the op type */ + schema.getRowSize() + columnBitSetSize; if (schema.hasNullableColumns()) { // nullsBitSet is the same size as the columnBitSet sizePerRow += columnBitSetSize; } // TODO: would be more efficient to use a buffer which "chains" smaller allocations // instead of a doubling buffer like BAOS. this.rows = ByteBuffer.allocate(sizePerRow * numOperations) .order(ByteOrder.LITTLE_ENDIAN); this.indirect = new ArrayList<>(schema.getVarLengthColumnCount() * numOperations); }