40package com.jogamp.common.nio;
49 private final ByteBuffer bb;
53 this.bb = bb.order(ByteOrder.nativeOrder());
64 return Buffers.getDirectBufferAddressImpl(bb);
73 public final ByteBuffer
slice(
final int byteOffset,
final int byteLength) {
74 bb.position(byteOffset);
75 bb.limit(byteOffset + byteLength);
76 final ByteBuffer newBuf = bb.slice().order(bb.order());
78 bb.limit(bb.capacity());
84 return bb.get(byteOffset);
88 public final void setByteAt(
final int byteOffset,
final byte v) {
89 bb.put(byteOffset, v);
94 return (
byte)0 != bb.get(byteOffset);
98 public final void setBooleanAt(
final int byteOffset,
final boolean v) {
99 bb.put(byteOffset, v?(
byte)1:(
byte)0);
104 return bb.getChar(byteOffset);
108 public final void setCharAt(
final int byteOffset,
final char v) {
109 bb.putChar(byteOffset, v);
114 return bb.getShort(byteOffset);
118 public final void setShortAt(
final int byteOffset,
final short v) {
119 bb.putShort(byteOffset, v);
124 return bb.getInt(byteOffset);
128 public final void setIntAt(
final int byteOffset,
final int v) {
129 bb.putInt(byteOffset, v);
133 public final int getIntAt(
final int byteOffset,
final int nativeSizeInBytes) {
134 switch(nativeSizeInBytes) {
136 return bb.getShort(byteOffset) & 0x0000FFFF ;
138 return bb.getInt(byteOffset);
140 return (
int) ( bb.getLong(byteOffset) & 0x00000000FFFFFFFFL ) ;
142 throw new InternalError(
"invalid nativeSizeInBytes "+nativeSizeInBytes);
147 public final void setIntAt(
final int byteOffset,
final int v,
final int nativeSizeInBytes) {
148 switch(nativeSizeInBytes) {
150 bb.putShort(byteOffset, (
short) ( v & 0x0000FFFF ) );
153 bb.putInt(byteOffset, v);
156 bb.putLong(byteOffset, v & 0x00000000FFFFFFFFL );
159 throw new InternalError(
"invalid nativeSizeInBytes "+nativeSizeInBytes);
165 return bb.getFloat(byteOffset);
169 public final void setFloatAt(
final int byteOffset,
final float v) {
170 bb.putFloat(byteOffset, v);
175 return bb.getDouble(byteOffset);
179 public final void setDoubleAt(
final int byteOffset,
final double v) {
180 bb.putDouble(byteOffset, v);
185 return bb.getLong(byteOffset);
189 public final void setLongAt(
final int byteOffset,
final long v) {
190 bb.putLong(byteOffset, v);
194 public final long getLongAt(
final int byteOffset,
final int nativeSizeInBytes) {
195 switch(nativeSizeInBytes) {
197 return bb.getInt(byteOffset) & 0x00000000FFFFFFFFL;
199 return bb.getLong(byteOffset);
201 throw new InternalError(
"invalid nativeSizeInBytes "+nativeSizeInBytes);
206 public final void setLongAt(
final int byteOffset,
final long v,
final int nativeSizeInBytes) {
207 switch(nativeSizeInBytes) {
209 bb.putInt(byteOffset, (
int) ( v & 0x00000000FFFFFFFFL ) );
212 bb.putLong(byteOffset, v);
215 throw new InternalError(
"invalid nativeSizeInBytes "+nativeSizeInBytes);
219 public final void setBytesAt(
int byteOffset,
final byte[] v) {
220 for (
int i = 0; i < v.length; i++) {
221 bb.put(byteOffset++, v[i]);
225 public final byte[]
getBytesAt(
int byteOffset,
final byte[] v) {
226 for (
int i = 0; i < v.length; i++) {
227 v[i] = bb.get(byteOffset++);
233 for (
int i = 0; i < v.length; i++) {
234 bb.put(byteOffset++, v[i]?(
byte)1:(
byte)0);
239 for (
int i = 0; i < v.length; i++) {
240 v[i] = (byte)0 != bb.get(byteOffset++);
245 public final void setCharsAt(
int byteOffset,
final char[] v) {
246 for (
int i = 0; i < v.length; i++, byteOffset+=2) {
247 bb.putChar(byteOffset, v[i]);
251 public final char[]
getCharsAt(
int byteOffset,
final char[] v) {
252 for (
int i = 0; i < v.length; i++, byteOffset+=2) {
253 v[i] = bb.getChar(byteOffset);
259 for (
int i = 0; i < v.length; i++, byteOffset+=2) {
260 bb.putShort(byteOffset, v[i]);
264 public final short[]
getShortsAt(
int byteOffset,
final short[] v) {
265 for (
int i = 0; i < v.length; i++, byteOffset+=2) {
266 v[i] = bb.getShort(byteOffset);
271 public final void setIntsAt(
int byteOffset,
final int[] v) {
272 for (
int i = 0; i < v.length; i++, byteOffset+=4) {
273 bb.putInt(byteOffset, v[i]);
277 public final int[]
getIntsAt(
int byteOffset,
final int[] v) {
278 for (
int i = 0; i < v.length; i++, byteOffset+=4) {
279 v[i] = bb.getInt(byteOffset);
285 for (
int i = 0; i < v.length; i++, byteOffset+=4) {
286 bb.putFloat(byteOffset, v[i]);
290 public final float[]
getFloatsAt(
int byteOffset,
final float[] v) {
291 for (
int i = 0; i < v.length; i++, byteOffset+=4) {
292 v[i] = bb.getFloat(byteOffset);
298 for (
int i = 0; i < v.length; i++, byteOffset+=8) {
299 bb.putDouble(byteOffset, v[i]);
304 for (
int i = 0; i < v.length; i++, byteOffset+=8) {
305 v[i] = bb.getDouble(byteOffset);
310 public final void setLongsAt(
int byteOffset,
final long[] v) {
311 for (
int i = 0; i < v.length; i++, byteOffset+=8) {
312 bb.putLong(byteOffset, v[i]);
316 public final long[]
getLongsAt(
int byteOffset,
final long[] v) {
317 for (
int i = 0; i < v.length; i++, byteOffset+=8) {
318 v[i] = bb.getLong(byteOffset);
Utility methods allowing easy java.nio.Buffer manipulations.
final long[] getLongsAt(int byteOffset, final long[] v)
StructAccessor(final ByteBuffer bb)
Create a new instance.
final void setLongAt(final int byteOffset, final long v)
Puts a long at the specified byteOffset.
final byte[] getBytesAt(int byteOffset, final byte[] v)
final long getDirectBufferAddress()
Returns the native address of the underlying native ByteBuffer.
final int getIntAt(final int byteOffset)
Retrieves the int at the specified byteOffset.
final void setCharAt(final int byteOffset, final char v)
Puts a char at the specified byteOffset.
final double getDoubleAt(final int byteOffset)
Retrieves the double at the specified byteOffset.
final long getLongAt(final int byteOffset, final int nativeSizeInBytes)
Retrieves the long at the specified byteOffset.
final void setIntAt(final int byteOffset, final int v, final int nativeSizeInBytes)
Puts a int at the specified byteOffset.
final float[] getFloatsAt(int byteOffset, final float[] v)
final int getIntAt(final int byteOffset, final int nativeSizeInBytes)
Retrieves the int at the specified byteOffset.
final short[] getShortsAt(int byteOffset, final short[] v)
final long getLongAt(final int byteOffset)
Retrieves the long at the specified byteOffset.
final void setFloatAt(final int byteOffset, final float v)
Puts a float at the specified byteOffset.
final void setShortAt(final int byteOffset, final short v)
Puts a short at the specified byteOffset.
final void setDoubleAt(final int byteOffset, final double v)
Puts a double at the specified byteOffset.
final void setFloatsAt(int byteOffset, final float[] v)
final void setCharsAt(int byteOffset, final char[] v)
final byte getByteAt(final int byteOffset)
Retrieves the byte at the specified byteOffset.
final char[] getCharsAt(int byteOffset, final char[] v)
final int[] getIntsAt(int byteOffset, final int[] v)
final ByteBuffer getBuffer()
Return the underlying native direct ByteBuffer.
final void setIntsAt(int byteOffset, final int[] v)
final float getFloatAt(final int byteOffset)
Retrieves the float at the specified byteOffset.
final char getCharAt(final int byteOffset)
Retrieves the char at the specified byteOffset.
final void setShortsAt(int byteOffset, final short[] v)
final void setIntAt(final int byteOffset, final int v)
Puts a int at the specified byteOffset.
final void setBooleansAt(int byteOffset, final boolean[] v)
final double[] getDoublesAt(int byteOffset, final double[] v)
final void setBytesAt(int byteOffset, final byte[] v)
final short getShortAt(final int byteOffset)
Retrieves the short at the specified byteOffset.
final void setByteAt(final int byteOffset, final byte v)
Puts a byte at the specified byteOffset.
final ByteBuffer slice(final int byteOffset, final int byteLength)
Returns a slice of the current ByteBuffer starting at the specified byte offset and extending the spe...
final void setLongAt(final int byteOffset, final long v, final int nativeSizeInBytes)
Puts a long at the specified byteOffset.
final void setDoublesAt(int byteOffset, final double[] v)
final boolean[] getBooleansAt(int byteOffset, final boolean[] v)
final boolean getBooleanAt(final int byteOffset)
Retrieves the boolean at the specified byteOffset.
final void setBooleanAt(final int byteOffset, final boolean v)
Puts a boolean at the specified byteOffset.
final void setLongsAt(int byteOffset, final long[] v)