Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
199 changes: 191 additions & 8 deletions java/memory/src/main/java/io/netty/buffer/ArrowBuf.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.io.OutputStream;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.channels.FileChannel;
import java.nio.channels.GatheringByteChannel;
import java.nio.channels.ScatteringByteChannel;
import java.nio.charset.Charset;
Expand Down Expand Up @@ -493,6 +494,16 @@ public ArrowBuf retain() {
return retain(1);
}

@Override
public ByteBuf touch() {
return this;
Copy link

@johnou johnou Nov 30, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zsxwing why does this method return this instead of invoking the super.touch()?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AbstractByteBuf doesn't implement it.

Copy link
Member Author

@zsxwing zsxwing Dec 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The touch method is added for AdvancedLeakAwareByteBuf/AdvancedLeakAwareCompositeByteBuf. Other ByteBufs just need to delegate it to super/underlying buffer, or implement it as an empty method.

}

@Override
public ByteBuf touch(Object hint) {
return this;
Copy link

@johnou johnou Nov 30, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zsxwing why does this method return this instead of invoking the super.touch(Object hint)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AbstractByteBuf doesn't implement it.

}

@Override
public long getLong(int index) {
chk(index, 8);
Expand All @@ -505,6 +516,17 @@ public float getFloat(int index) {
return Float.intBitsToFloat(getInt(index));
}

/**
* Gets a 64-bit long integer at the specified absolute {@code index} in
* this buffer in Big Endian Byte Order.
*/
@Override
public long getLongLE(int index) {
chk(index, 8);
final long v = PlatformDependent.getLong(addr(index));
return Long.reverseBytes(v);
}

@Override
public double getDouble(int index) {
return Double.longBitsToDouble(getLong(index));
Expand All @@ -527,6 +549,17 @@ public int getInt(int index) {
return v;
}

/**
* Gets a 32-bit integer at the specified absolute {@code index} in
* this buffer in Big Endian Byte Order.
*/
@Override
public int getIntLE(int index) {
chk(index, 4);
final int v = PlatformDependent.getInt(addr(index));
return Integer.reverseBytes(v);
}

@Override
public int getUnsignedShort(int index) {
return getShort(index) & 0xFFFF;
Expand All @@ -535,31 +568,125 @@ public int getUnsignedShort(int index) {
@Override
public short getShort(int index) {
chk(index, 2);
short v = PlatformDependent.getShort(addr(index));
final short v = PlatformDependent.getShort(addr(index));
return v;
}

/**
* Gets a 16-bit short integer at the specified absolute {@code index} in
* this buffer in Big Endian Byte Order.
*/
@Override
public short getShortLE(int index) {
final short v = PlatformDependent.getShort(addr(index));
return Short.reverseBytes(v);
}

/**
* Gets an unsigned 24-bit medium integer at the specified absolute
* {@code index} in this buffer.
*/
@Override
public int getUnsignedMedium(int index) {
chk(index, 3);
final long addr = addr(index);
return (PlatformDependent.getByte(addr) & 0xff) << 16 |
(PlatformDependent.getShort(addr + 1) & 0xffff);
}

/**
* Gets an unsigned 24-bit medium integer at the specified absolute {@code index} in
* this buffer in Big Endian Byte Order.
*/
@Override
public int getUnsignedMediumLE(int index) {
chk(index, 3);
final long addr = addr(index);
return (PlatformDependent.getByte(addr) & 0xff) |
(Short.reverseBytes(PlatformDependent.getShort(addr + 1)) & 0xffff) << 8;
}

@Override
public ArrowBuf setShort(int index, int value) {
chk(index, 2);
PlatformDependent.putShort(addr(index), (short) value);
return this;
}

/**
* Sets the specified 16-bit short integer at the specified absolute {@code index}
* in this buffer with Big Endian byte order.
*/
@Override
public ByteBuf setShortLE(int index, int value) {
chk(index, 2);
PlatformDependent.putShort(addr(index), Short.reverseBytes((short) value));
return this;
}

/**
* Sets the specified 24-bit medium integer at the specified absolute
* {@code index} in this buffer.
*/
@Override
public ByteBuf setMedium(int index, int value) {
chk(index, 3);
final long addr = addr(index);
PlatformDependent.putByte(addr, (byte) (value >>> 16));
PlatformDependent.putShort(addr + 1, (short) value);
return this;
}


/**
* Sets the specified 24-bit medium integer at the specified absolute {@code index}
* in this buffer with Big Endian byte order.
*/
@Override
public ByteBuf setMediumLE(int index, int value) {
chk(index, 3);
final long addr = addr(index);
PlatformDependent.putByte(addr, (byte) value);
PlatformDependent.putShort(addr + 1, Short.reverseBytes((short) (value >>> 8)));
return this;
}

@Override
public ArrowBuf setInt(int index, int value) {
chk(index, 4);
PlatformDependent.putInt(addr(index), value);
return this;
}

/**
* Sets the specified 32-bit integer at the specified absolute {@code index}
* in this buffer with Big Endian byte order.
*/
@Override
public ByteBuf setIntLE(int index, int value) {
chk(index, 4);
PlatformDependent.putInt(addr(index), Integer.reverseBytes(value));
return this;
}

@Override
public ArrowBuf setLong(int index, long value) {
chk(index, 8);
PlatformDependent.putLong(addr(index), value);
return this;
}

/**
* Sets the specified 64-bit long integer at the specified absolute {@code index}
* in this buffer with Big Endian byte order.
*/
@Override
public ByteBuf setLongLE(int index, long value) {
chk(index, 8);
PlatformDependent.putLong(addr(index), Long.reverseBytes(value));
return this;
}

@Override
public ArrowBuf setChar(int index, int value) {
chk(index, 2);
Expand Down Expand Up @@ -668,16 +795,46 @@ protected short _getShort(int index) {
return getShort(index);
}

/** @see {@link #getShortLE(int)} */
@Override
protected short _getShortLE(int index) {
return getShortLE(index);
}

@Override
protected int _getInt(int index) {
return getInt(index);
}

/** @see {@link #getIntLE(int)} */
@Override
protected int _getIntLE(int index) {
return getIntLE(index);
}

/** @see {@link #getUnsignedMedium(int)} */
@Override
protected int _getUnsignedMedium(int index) {
return getUnsignedMedium(index);
}

/** @see {@link #getUnsignedMediumLE(int)} */
@Override
protected int _getUnsignedMediumLE(int index) {
return getUnsignedMediumLE(index);
}

@Override
protected long _getLong(int index) {
return getLong(index);
}

/** @see {@link #getLongLE(int)} */
@Override
protected long _getLongLE(int index) {
return getLongLE(index);
}

@Override
protected void _setByte(int index, int value) {
setByte(index, value);
Expand All @@ -688,21 +845,45 @@ protected void _setShort(int index, int value) {
setShort(index, value);
}

/** @see {@link #setShortLE(int, int)} */
@Override
protected void _setShortLE(int index, int value) {
setShortLE(index, value);
}

@Override
protected void _setMedium(int index, int value) {
setMedium(index, value);
}

/** @see {@link #setMediumLE(int, int)} */
@Override
protected void _setMediumLE(int index, int value) {
setMediumLE(index, value);
}

@Override
protected void _setInt(int index, int value) {
setInt(index, value);
}

/** @see {@link #setIntLE(int, int)} */
@Override
protected void _setIntLE(int index, int value) {
setIntLE(index, value);
}

@Override
protected void _setLong(int index, long value) {
setLong(index, value);
}

/** @see {@link #setLongLE(int, long)} */
@Override
public void _setLongLE(int index, long value) {
setLongLE(index, value);
}

@Override
public ArrowBuf getBytes(int index, ByteBuf dst, int dstIndex, int length) {
udle.getBytes(index + offset, dst, dstIndex, length);
Expand All @@ -716,16 +897,13 @@ public ArrowBuf getBytes(int index, OutputStream out, int length) throws IOExcep
}

@Override
protected int _getUnsignedMedium(int index) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@siddharthteotia I added all methods back. This is the only exception. It's implemented in getUnsignedMedium now.

final long addr = addr(index);
return (PlatformDependent.getByte(addr) & 0xff) << 16 |
(PlatformDependent.getByte(addr + 1) & 0xff) << 8 |
PlatformDependent.getByte(addr + 2) & 0xff;
public int getBytes(int index, GatheringByteChannel out, int length) throws IOException {
return udle.getBytes(index + offset, out, length);
}

@Override
public int getBytes(int index, GatheringByteChannel out, int length) throws IOException {
return udle.getBytes(index + offset, out, length);
public int getBytes(int index, FileChannel out, long position, int length) throws IOException {
return udle.getBytes(index + offset, out, position, length);
}

@Override
Expand Down Expand Up @@ -776,6 +954,11 @@ public int setBytes(int index, ScatteringByteChannel in, int length) throws IOEx
return udle.setBytes(index + offset, in, length);
}

@Override
public int setBytes(int index, FileChannel in, long position, int length) throws IOException {
return udle.setBytes(index + offset, in, position, length);
}

@Override
public byte getByte(int index) {
chk(index, 1);
Expand Down
Loading