/** * A setter that helps to avoid object creation every time and whenever * there is a need to create new OffheapKeyOnlyKeyValue. * @param key * @param offset * @param length */ public void setKey(ByteBuffer key, int offset, int length) { this.buf = key; this.offset = offset; this.length = length; this.rowLen = ByteBufferUtils.toShort(this.buf, this.offset); }
@Override public short getRowLength() { return ByteBufferUtils.toShort(this.buf, this.offset + KeyValue.ROW_OFFSET); }
private short getShort(int index, int itemIndex) { ByteBuffer item = items[itemIndex]; int offsetInItem = index - this.itemBeginPos[itemIndex]; int remainingLen = item.limit() - offsetInItem; if (remainingLen >= Bytes.SIZEOF_SHORT) { return ByteBufferUtils.toShort(item, offsetInItem); } if (items.length - 1 == itemIndex) { // means cur item is the last one and we wont be able to read a short. Throw exception throw new BufferUnderflowException(); } ByteBuffer nextItem = items[itemIndex + 1]; // Get available bytes from this item and remaining from next short l = 0; for (int i = offsetInItem; i < item.capacity(); i++) { l = (short) (l << 8); l = (short) (l ^ (ByteBufferUtils.toByte(item, i) & 0xFF)); } for (int i = 0; i < Bytes.SIZEOF_SHORT - remainingLen; i++) { l = (short) (l << 8); l = (short) (l ^ (ByteBufferUtils.toByte(nextItem, i) & 0xFF)); } return l; }
int offsetInItem = index - this.itemBeginPos[itemIndex]; if (item.limit() - offsetInItem >= Bytes.SIZEOF_SHORT) { return ByteBufferUtils.toShort(item, offsetInItem);
@Test public void testToPrimitiveTypes() { ByteBuffer buffer = ByteBuffer.allocate(15); long l = 988L; int i = 135; short s = 7; buffer.putLong(l); buffer.putShort(s); buffer.putInt(i); assertEquals(l, ByteBufferUtils.toLong(buffer, 0)); assertEquals(s, ByteBufferUtils.toShort(buffer, 8)); assertEquals(i, ByteBufferUtils.toInt(buffer, 10)); }
private static short getTagValuePartAsShort(Tag t, int offset) { if (t.hasArray()) { return Bytes.toShort(t.getValueArray(), offset); } return ByteBufferUtils.toShort(t.getValueByteBuffer(), offset); }
/** * A setter that helps to avoid object creation every time and whenever * there is a need to create new OffheapKeyOnlyKeyValue. * @param key * @param offset * @param length */ public void setKey(ByteBuffer key, int offset, int length) { this.buf = key; this.offset = offset; this.length = length; this.rowLen = ByteBufferUtils.toShort(this.buf, this.offset); }
@Override public short getRowLength() { return ByteBufferUtils.toShort(this.buf, this.offset + KeyValue.ROW_OFFSET); }
/** * A setter that helps to avoid object creation every time and whenever * there is a need to create new OffheapKeyOnlyKeyValue. * @param key * @param offset * @param length */ public void setKey(ByteBuffer key, int offset, int length) { this.buf = key; this.offset = offset; this.length = length; this.rowLen = ByteBufferUtils.toShort(this.buf, this.offset); }
private short getRowLen() { return ByteBufferUtils.toShort(this.buf, this.offset + KeyValue.ROW_OFFSET); }
private short getShort(int index, int itemIndex) { ByteBuffer item = items[itemIndex]; int offsetInItem = index - this.itemBeginPos[itemIndex]; int remainingLen = item.limit() - offsetInItem; if (remainingLen >= Bytes.SIZEOF_SHORT) { return ByteBufferUtils.toShort(item, offsetInItem); } if (items.length - 1 == itemIndex) { // means cur item is the last one and we wont be able to read a short. Throw exception throw new BufferUnderflowException(); } ByteBuffer nextItem = items[itemIndex + 1]; // Get available bytes from this item and remaining from next short l = 0; for (int i = offsetInItem; i < item.capacity(); i++) { l = (short) (l << 8); l = (short) (l ^ (ByteBufferUtils.toByte(item, i) & 0xFF)); } for (int i = 0; i < Bytes.SIZEOF_SHORT - remainingLen; i++) { l = (short) (l << 8); l = (short) (l ^ (ByteBufferUtils.toByte(nextItem, i) & 0xFF)); } return l; }
private short getShort(int index, int itemIndex) { ByteBuffer item = items[itemIndex]; int offsetInItem = index - this.itemBeginPos[itemIndex]; int remainingLen = item.limit() - offsetInItem; if (remainingLen >= Bytes.SIZEOF_SHORT) { return ByteBufferUtils.toShort(item, offsetInItem); } if (items.length - 1 == itemIndex) { // means cur item is the last one and we wont be able to read a short. Throw exception throw new BufferUnderflowException(); } ByteBuffer nextItem = items[itemIndex + 1]; // Get available bytes from this item and remaining from next short l = 0; for (int i = offsetInItem; i < item.capacity(); i++) { l = (short) (l << 8); l = (short) (l ^ (ByteBufferUtils.toByte(item, i) & 0xFF)); } for (int i = 0; i < Bytes.SIZEOF_SHORT - remainingLen; i++) { l = (short) (l << 8); l = (short) (l ^ (ByteBufferUtils.toByte(nextItem, i) & 0xFF)); } return l; }
int offsetInItem = index - this.itemBeginPos[itemIndex]; if (item.limit() - offsetInItem >= Bytes.SIZEOF_SHORT) { return ByteBufferUtils.toShort(item, offsetInItem);
int offsetInItem = index - this.itemBeginPos[itemIndex]; if (item.limit() - offsetInItem >= Bytes.SIZEOF_SHORT) { return ByteBufferUtils.toShort(item, offsetInItem);
@Test public void testToPrimitiveTypes() { ByteBuffer buffer = ByteBuffer.allocate(15); long l = 988L; int i = 135; short s = 7; buffer.putLong(l); buffer.putShort(s); buffer.putInt(i); assertEquals(l, ByteBufferUtils.toLong(buffer, 0)); assertEquals(s, ByteBufferUtils.toShort(buffer, 8)); assertEquals(i, ByteBufferUtils.toInt(buffer, 10)); }
@Test public void testToPrimitiveTypes() { ByteBuffer buffer = ByteBuffer.allocate(15); long l = 988L; int i = 135; short s = 7; buffer.putLong(l); buffer.putShort(s); buffer.putInt(i); assertEquals(l, ByteBufferUtils.toLong(buffer, 0)); assertEquals(s, ByteBufferUtils.toShort(buffer, 8)); assertEquals(i, ByteBufferUtils.toInt(buffer, 10)); }
private static short getTagValuePartAsShort(Tag t, int offset) { if (t.hasArray()) { return Bytes.toShort(t.getValueArray(), offset); } return ByteBufferUtils.toShort(t.getValueByteBuffer(), offset); }