private int getRowLength() { org.apache.kudu.util.Slice rawData = getCurrentRowRawData(); if (rawData != null) { return rawData.length(); } else { return columnTypes.size(); } }
static void readProtobuf(final Slice slice, final Builder builder) { final int length = slice.length(); final byte[] payload = slice.getRawArray(); final int offset = slice.getRawOffset(); try { builder.mergeFrom(payload, offset, length); if (!builder.isInitialized()) { throw new RuntimeException("Could not deserialize the response," + " incompatible RPC? Error is: " + builder.getInitializationErrorString()); } } catch (InvalidProtocolBufferException e) { throw new RuntimeException("Invalid RPC response: length=" + length, e); } }
public static Slice ensureSize(Slice existingSlice, int minWritableBytes) { if (existingSlice == null) { existingSlice = EMPTY_SLICE; } if (minWritableBytes <= existingSlice.length()) { return existingSlice; } int newCapacity; if (existingSlice.length() == 0) { newCapacity = 1; } else { newCapacity = existingSlice.length(); } int minNewCapacity = existingSlice.length() + minWritableBytes; while (newCapacity < minNewCapacity) { newCapacity <<= 1; } Slice newSlice = Slices.allocate(newCapacity); newSlice.setBytes(0, existingSlice, 0, existingSlice.length()); return newSlice; }
/** * Get a copy of the specified column's binary data. * @param columnIndex Column index in the schema * @return a byte[] with the binary data. * @throws IllegalArgumentException if the column is null * or if the type doesn't match the column's type * @throws IndexOutOfBoundsException if the column doesn't exist */ public byte[] getBinaryCopy(int columnIndex) { checkValidColumn(columnIndex); checkNull(columnIndex); // C++ puts a Slice in rowData which is 16 bytes long for simplicity, // but we only support ints. long offset = getLong(columnIndex); long length = rowData.getLong(getCurrentRowDataOffsetForColumn(columnIndex) + 8); assert offset < Integer.MAX_VALUE; assert length < Integer.MAX_VALUE; byte[] ret = new byte[(int)length]; System.arraycopy(indirectData.getRawArray(), indirectData.getRawOffset() + (int) offset, ret, 0, (int) length); return ret; }
private static Slice subslice(Slice parent, int offset, int length) { return new Slice(parent.getRawArray(), parent.getRawOffset() + offset, length); }
public static Slice allocate(int capacity) { if (capacity == 0) { return EMPTY_SLICE; } return new Slice(capacity); }
public byte[] getBytes() { return getBytes(0, length); }
/** * Gets an unsigned byte at the specified absolute {@code index} in this * buffer. * * @throws IndexOutOfBoundsException if the specified {@code index} is less than {@code 0} or * {@code index + 1} is greater than {@code this.capacity} */ public short getUnsignedByte(int index) { return (short) (getByte(index) & 0xFF); }
public byte[] copyBytes() { return copyBytes(0, length); }
public Slice copySlice() { return copySlice(0, length); }
/** * Get the specified column's binary data. * * This doesn't copy the data and instead returns a ByteBuffer that wraps it. * * @param columnIndex Column index in the schema * @return a ByteBuffer with the binary data. * @throws IllegalArgumentException if the column is null * or if the type doesn't match the column's type * @throws IndexOutOfBoundsException if the column doesn't exist */ public ByteBuffer getBinary(int columnIndex) { checkValidColumn(columnIndex); checkNull(columnIndex); checkType(columnIndex, Type.BINARY); // C++ puts a Slice in rowData which is 16 bytes long for simplicity, // but we only support ints. long offset = getLong(columnIndex); long length = rowData.getLong(getCurrentRowDataOffsetForColumn(columnIndex) + 8); assert offset < Integer.MAX_VALUE; assert length < Integer.MAX_VALUE; return ByteBuffer.wrap(indirectData.getRawArray(), indirectData.getRawOffset() + (int) offset, (int) length); }
public static Slice wrappedBuffer(byte[] array) { if (array.length == 0) { return EMPTY_SLICE; } return new Slice(array); }
/** * Transfers this buffer's data to the specified destination starting at * the specified absolute {@code index}. * * @param dstIndex the first index of the destination * @param length the number of bytes to transfer * @throws IndexOutOfBoundsException if the specified {@code index} is less than {@code 0}, * if the specified {@code dstIndex} is less than {@code 0}, * if {@code index + length} is greater than * {@code this.capacity}, or * if {@code dstIndex + length} is greater than * {@code dst.capacity} */ public void getBytes(int index, Slice dst, int dstIndex, int length) { getBytes(index, dst.data, dstIndex, length); }
@Override public String toString() { return getClass().getSimpleName() + '(' + "length=" + length() + ')'; } }
/** * Get the specified column's string. * @param columnIndex Column index in the schema * @return a string * @throws IllegalArgumentException if the column is null * or if the type doesn't match the column's type * @throws IndexOutOfBoundsException if the column doesn't exist */ public String getString(int columnIndex) { checkValidColumn(columnIndex); checkNull(columnIndex); checkType(columnIndex, Type.STRING); // C++ puts a Slice in rowData which is 16 bytes long for simplity, but we only support ints. long offset = getLong(columnIndex); long length = rowData.getLong(getCurrentRowDataOffsetForColumn(columnIndex) + 8); assert offset < Integer.MAX_VALUE; assert length < Integer.MAX_VALUE; return Bytes.getString(indirectData.getRawArray(), indirectData.getRawOffset() + (int)offset, (int)length); }
/** * Returns a copy of this buffer's sub-region. Modifying the content of * the returned buffer or this buffer does not affect each other at all. */ public Slice copySlice(int index, int length) { Preconditions.checkPositionIndexes(index, index + length, this.length); index += offset; byte[] copiedArray = new byte[length]; System.arraycopy(data, index, copiedArray, 0, length); return new Slice(copiedArray); }
private int getRowLength() { org.apache.kudu.util.Slice rawData = getCurrentRowRawData(); if (rawData != null) { return rawData.length(); } else { return columnTypes.size(); } }
/** * Returns a slice of this buffer's sub-region. Modifying the content of * the returned buffer or this buffer affects each other's content while * they maintain separate indexes and marks. */ public Slice slice(int index, int length) { if (index == 0 && length == this.length) { return this; } Preconditions.checkPositionIndexes(index, index + length, this.length); if (index >= 0 && length == 0) { return Slices.EMPTY_SLICE; } return new Slice(data, offset + index, length); }
private int getRowLength() { org.apache.kudu.util.Slice rawData = getCurrentRowRawData(); if (rawData != null) { return rawData.length(); } else { return columnTypes.size(); } }
private static Slice nextBytes(final ChannelBuffer buf, final int length) { byte[] payload; int offset; if (buf.hasArray()) { // Zero copy. payload = buf.array(); offset = buf.arrayOffset() + buf.readerIndex(); buf.skipBytes(length); } else { // We have to copy the entire payload out of the buffer :( payload = new byte[length]; buf.readBytes(payload); offset = 0; } return new Slice(payload, offset, length); }