Javolution 6.0.0 java
|
Public Member Functions | |
Union () | |
final boolean | isUnion () |
final int | size () |
Struct | outer () |
final ByteBuffer | getByteBuffer () |
final Struct | setByteBuffer (ByteBuffer byteBuffer, int position) |
final Struct | setByteBufferPosition (int position) |
final int | getByteBufferPosition () |
int | read (InputStream in) throws IOException |
void | write (OutputStream out) throws IOException |
final long | address () |
String | toString () |
ByteOrder | byteOrder () |
boolean | isPacked () |
long | readBits (int bitOffset, int bitSize) |
void | writeBits (long value, int bitOffset, int bitSize) |
Static Public Attributes | |
static final LocalContext.Parameter< Integer > | MAXIMUM_ALIGNMENT |
Protected Member Functions | |
UTF8String[] | array (UTF8String[] array, int stringLength) |
Package Functions | |
protected< S extends Struct > S | inner (S struct) |
protected< S extends Struct > S[] | array (S[] structs) |
protected< S extends Struct > S[][] | array (S[][] structs) |
protected< S extends Struct > S[][][] | array (S[][][] structs) |
protected< M extends Member > M[] | array (M[] arrayMember) |
protected< M extends Member > M[][] | array (M[][] arrayMember) |
protected< M extends Member > M[][][] | array (M[][][] arrayMember) |
Package Attributes | |
Struct | _outer |
ByteBuffer | _byteBuffer |
int | _outerOffset |
int | _alignment = 1 |
int | _length |
int | _index |
int | _wordSize |
int | _bitsUsed |
boolean | _resetIndex |
byte[] | _bytes |
Private Member Functions | |
synchronized ByteBuffer | newBuffer () |
long | readByteBufferLong (int index) |
void | writeByteBufferLong (int index, long value) |
Static Private Member Functions | |
static byte | readByte (int index, ByteBuffer byteBuffer) |
static void | writeByte (int index, ByteBuffer byteBuffer, byte value) |
Static Private Attributes | |
static final char[] | HEXA |
static final Class<? extends Bool[]> | BOOL = new Bool[0].getClass() |
static final Class<? extends Signed8[]> | SIGNED_8 |
static final Class<? extends Unsigned8[]> | UNSIGNED_8 |
static final Class<? extends Signed16[]> | SIGNED_16 |
static final Class<? extends Unsigned16[]> | UNSIGNED_16 |
static final Class<? extends Signed32[]> | SIGNED_32 |
static final Class<? extends Unsigned32[]> | UNSIGNED_32 |
static final Class<? extends Signed64[]> | SIGNED_64 |
static final Class<? extends Float32[]> | FLOAT_32 |
static final Class<? extends Float64[]> | FLOAT_64 |
Equivalent to C/C++ union
; this class works in the same way as Struct (sub-class) except that all members are mapped to the same location in memory.
Here is an example of C union: [code] union Number { int asInt; float asFloat; char asString[12]; };[/code] And its Java equivalent:[code] public class Number extends Union { Signed32 asInt = new Signed32(); Float32 asFloat = new Float32(); Utf8String asString = new Utf8String(12); }[/code] As for any Struct, fields are directly accessible:[code] Number num = new Number(); num.asInt.set(23); num.asString.set("23"); // Null terminated (C compatible) float f = num.asFloat.get();[/code]
Definition at line 36 of file Union.java.
javolution.io.Union.Union | ( | ) |
|
inherited |
Returns this struct address. This method allows for structs to be referenced (e.g. pointer) from other structs.
UnsupportedOperationException | if the struct buffer is not a direct buffer. |
Definition at line 393 of file Struct.java.
References javolution.io.Struct.getByteBuffer().
Referenced by javolution.io.Struct.Reference32< S extends Struct >.set(), and javolution.io.Struct.Reference64< S extends Struct >.set().
|
packageinherited |
Defines the specified array member. For predefined members, the array is populated when empty; custom members should use literal (populated) arrays.
arrayMember | the array member. |
UnsupportedOperationException | if the specified array is empty and the member type is unknown. |
Definition at line 618 of file Struct.java.
References javolution.io.Struct._index, javolution.io.Struct._resetIndex, javolution.io.Struct.BOOL, javolution.io.Struct.FLOAT_32, javolution.io.Struct.FLOAT_64, javolution.io.Struct.SIGNED_16, javolution.io.Struct.SIGNED_32, javolution.io.Struct.SIGNED_64, javolution.io.Struct.SIGNED_8, javolution.io.Struct.UNSIGNED_16, javolution.io.Struct.UNSIGNED_32, and javolution.io.Struct.UNSIGNED_8.
|
packageinherited |
Defines the specified two-dimensional array member. For predefined members, the array is populated when empty; custom members should use literal (populated) arrays.
arrayMember | the two-dimensional array member. |
UnsupportedOperationException | if the specified array is empty and the member type is unknown. |
Definition at line 703 of file Struct.java.
References javolution.io.Struct._index, javolution.io.Struct._resetIndex, and javolution.io.Struct.array().
|
packageinherited |
Defines the specified three-dimensional array member. For predefined members, the array is populated when empty; custom members should use literal (populated) arrays.
arrayMember | the three-dimensional array member. |
UnsupportedOperationException | if the specified array is empty and the member type is unknown. |
Definition at line 726 of file Struct.java.
References javolution.io.Struct._index, javolution.io.Struct._resetIndex, and javolution.io.Struct.array().
|
packageinherited |
Defines the specified array of structs as inner structs. The array is populated if necessary using the struct component default constructor (which must be public).
structs | the struct array. |
IllegalArgumentException | if the specified array contains inner structs. |
Definition at line 532 of file Struct.java.
References javolution.io.Struct._index, javolution.io.Struct._resetIndex, and javolution.io.Struct.inner().
Referenced by javolution.io.Struct.array().
|
packageinherited |
Defines the specified two-dimensional array of structs as inner structs. The array is populated if necessary using the struct component default constructor (which must be public).
structs | the two dimensional struct array. |
IllegalArgumentException | if the specified array contains inner structs. |
Definition at line 572 of file Struct.java.
References javolution.io.Struct._index, javolution.io.Struct._resetIndex, and javolution.io.Struct.array().
|
packageinherited |
Defines the specified three dimensional array of structs as inner structs. The array is populated if necessary using the struct component default constructor (which must be public).
structs | the three dimensional struct array. |
IllegalArgumentException | if the specified array contains inner structs. |
Definition at line 595 of file Struct.java.
References javolution.io.Struct._index, javolution.io.Struct._resetIndex, and javolution.io.Struct.array().
|
protectedinherited |
Defines the specified array of UTF-8 strings, all strings having the specified length (convenience method).
array | the string array. |
stringLength | the length of the string elements. |
Definition at line 747 of file Struct.java.
References javolution.io.Struct._index, javolution.io.Struct._resetIndex, and javolution.io.Struct.array().
|
inherited |
Returns the byte order for this struct (configurable). The byte order is inherited by inner structs. Sub-classes may change the byte order by overriding this method. For example:[code] public class TopStruct extends Struct { ... // Members initialization. public ByteOrder byteOrder() { // TopStruct and its inner structs use hardware byte order. return ByteOrder.nativeOrder(); } }}[/code]
BIG_ENDIAN
). Definition at line 480 of file Struct.java.
References javolution.io.Struct._outer, and javolution.io.Struct.byteOrder().
Referenced by javolution.io.Struct.byteOrder(), javolution.io.Struct.Member.get(), javolution.io.Struct.newBuffer(), javolution.io.Struct.readBits(), javolution.io.Struct.Member.set(), javolution.io.Struct.setByteBuffer(), and javolution.io.Struct.writeBits().
|
inherited |
Returns the byte buffer for this struct. This method will allocate a new direct buffer if none has been set.
Changes to the buffer's content are visible in this struct, and vice versa.
The buffer of an inner struct is the same as its parent struct.
If no byte buffer has been set, a direct buffer is allocated with a capacity equals to this struct's size.
Definition at line 254 of file Struct.java.
References javolution.io.Struct._byteBuffer, javolution.io.Struct._outer, javolution.io.Struct.getByteBuffer(), and javolution.io.Struct.newBuffer().
Referenced by javolution.io.Struct.address(), javolution.io.Struct.UTF8String.get(), javolution.io.Struct.Bool.get(), javolution.io.Struct.Signed8.get(), javolution.io.Struct.Unsigned8.get(), javolution.io.Struct.Signed16.get(), javolution.io.Struct.Unsigned16.get(), javolution.io.Struct.Signed32.get(), javolution.io.Struct.Unsigned32.get(), javolution.io.Struct.Signed64.get(), javolution.io.Struct.Float32.get(), javolution.io.Struct.Float64.get(), javolution.io.Struct.Enum8< T extends Enum< T >.get(), javolution.io.Struct.Enum16< T extends Enum< T >.get(), javolution.io.Struct.Enum32< T extends Enum< T >.get(), javolution.io.Struct.Enum64< T extends Enum< T >.get(), javolution.io.Struct.getByteBuffer(), javolution.io.Struct.Reference32< S extends Struct >.isUpToDate(), javolution.io.Struct.Reference64< S extends Struct >.isUpToDate(), javolution.io.Struct.read(), javolution.io.Struct.readByteBufferLong(), javolution.io.Struct.UTF8String.set(), javolution.io.Struct.Bool.set(), javolution.io.Struct.Signed8.set(), javolution.io.Struct.Unsigned8.set(), javolution.io.Struct.Signed16.set(), javolution.io.Struct.Unsigned16.set(), javolution.io.Struct.Signed32.set(), javolution.io.Struct.Unsigned32.set(), javolution.io.Struct.Signed64.set(), javolution.io.Struct.Float32.set(), javolution.io.Struct.Float64.set(), javolution.io.Struct.Reference32< S extends Struct >.set(), javolution.io.Struct.Reference64< S extends Struct >.set(), javolution.io.Struct.Enum8< T extends Enum< T >.set(), javolution.io.Struct.Enum16< T extends Enum< T >.set(), javolution.io.Struct.Enum32< T extends Enum< T >.set(), javolution.io.Struct.Enum64< T extends Enum< T >.set(), javolution.io.Struct.setByteBufferPosition(), javolution.io.Struct.toString(), javolution.io.Struct.Reference32< S extends Struct >.value(), javolution.io.Struct.Reference64< S extends Struct >.value(), javolution.io.Struct.write(), and javolution.io.Struct.writeByteBufferLong().
|
inherited |
Returns the absolute byte position of this struct within its associated byte buffer.
Definition at line 312 of file Struct.java.
References javolution.io.Struct._outer, javolution.io.Struct._outerOffset, and javolution.io.Struct.getByteBufferPosition().
Referenced by javolution.io.Struct.UTF8String.get(), javolution.io.Struct.Bool.get(), javolution.io.Struct.Signed8.get(), javolution.io.Struct.Unsigned8.get(), javolution.io.Struct.Signed16.get(), javolution.io.Struct.Unsigned16.get(), javolution.io.Struct.Signed32.get(), javolution.io.Struct.Unsigned32.get(), javolution.io.Struct.Signed64.get(), javolution.io.Struct.Float32.get(), javolution.io.Struct.Float64.get(), javolution.io.Struct.Enum8< T extends Enum< T >.get(), javolution.io.Struct.Enum16< T extends Enum< T >.get(), javolution.io.Struct.Enum32< T extends Enum< T >.get(), javolution.io.Struct.Enum64< T extends Enum< T >.get(), javolution.io.Struct.getByteBufferPosition(), javolution.io.Struct.Reference32< S extends Struct >.isUpToDate(), javolution.io.Struct.Reference64< S extends Struct >.isUpToDate(), javolution.io.Struct.read(), javolution.io.Struct.readBits(), javolution.io.Struct.UTF8String.set(), javolution.io.Struct.Bool.set(), javolution.io.Struct.Signed8.set(), javolution.io.Struct.Unsigned8.set(), javolution.io.Struct.Signed16.set(), javolution.io.Struct.Unsigned16.set(), javolution.io.Struct.Signed32.set(), javolution.io.Struct.Unsigned32.set(), javolution.io.Struct.Signed64.set(), javolution.io.Struct.Float32.set(), javolution.io.Struct.Float64.set(), javolution.io.Struct.Reference32< S extends Struct >.set(), javolution.io.Struct.Reference64< S extends Struct >.set(), javolution.io.Struct.Enum8< T extends Enum< T >.set(), javolution.io.Struct.Enum16< T extends Enum< T >.set(), javolution.io.Struct.Enum32< T extends Enum< T >.set(), javolution.io.Struct.Enum64< T extends Enum< T >.set(), javolution.io.Struct.toString(), javolution.io.Struct.Reference32< S extends Struct >.value(), javolution.io.Struct.Reference64< S extends Struct >.value(), javolution.io.Struct.write(), and javolution.io.Struct.writeBits().
|
packageinherited |
Defines the specified struct as inner of this struct.
struct | the inner struct. |
IllegalArgumentException | if the specified struct is already an inner struct. |
Definition at line 513 of file Struct.java.
References javolution.io.Struct._alignment, javolution.io.Struct._outer, and javolution.io.Struct.size().
Referenced by javolution.io.Struct.array().
|
inherited |
Indicates if this struct is packed (configurable). By default, members of a struct are aligned on the boundary corresponding to the member base type; padding is performed if necessary. This directive is not inherited by inner structs. Sub-classes may change the packing directive by overriding this method. For example:[code] public class MyStruct extends Struct { ... // Members initialization. public boolean isPacked() { return true; // MyStruct is packed. } }}[/code]
true
if word size requirements are ignored. false
otherwise (default). Definition at line 501 of file Struct.java.
Referenced by javolution.io.Struct.Member.Member().
final boolean javolution.io.Union.isUnion | ( | ) |
Returns true
.
true
Reimplemented from javolution.io.Struct.
Definition at line 48 of file Union.java.
|
privateinherited |
Definition at line 259 of file Struct.java.
References javolution.io.Struct._byteBuffer, javolution.io.Struct.byteOrder(), javolution.io.Struct.setByteBuffer(), and javolution.io.Struct.size().
Referenced by javolution.io.Struct.getByteBuffer().
|
inherited |
Returns the outer of this struct or null
if this struct is not an inner struct.
null
. Definition at line 236 of file Struct.java.
References javolution.io.Struct._outer.
|
inherited |
Reads this struct from the specified input stream (convenience method when using Stream I/O). For better performance, use of Block I/O (e.g. java.nio.channels.*
) is recommended. This method behaves appropriately when not all of the data is available from the input stream. Incomplete data is extremely common when the input stream is associated with something like a TCP connection. The typical usage pattern in those scenarios is to repeatedly call read() until the entire message is received.
in | the input stream being read from. |
IOException | if an I/O error occurs. |
Definition at line 332 of file Struct.java.
References javolution.io.Struct._bytes, javolution.io.Struct.getByteBuffer(), javolution.io.Struct.getByteBufferPosition(), and javolution.io.Struct.size().
|
inherited |
Reads the specified bits from this Struct as an long (signed) integer value.
bitOffset | the bit start position in the Struct. |
bitSize | the number of bits. |
IllegalArgumentException | if (bitOffset + bitSize - 1) / 8 >= this.size() |
Definition at line 770 of file Struct.java.
References javolution.io.Struct.byteOrder(), javolution.io.Struct.getByteBufferPosition(), javolution.io.Struct.readByteBufferLong(), and javolution.io.Struct.size().
Referenced by javolution.io.Struct.BitField.longValue().
|
staticprivateinherited |
Definition at line 809 of file Struct.java.
Referenced by javolution.io.Struct.readByteBufferLong().
|
privateinherited |
Definition at line 784 of file Struct.java.
References javolution.io.Struct.getByteBuffer(), and javolution.io.Struct.readByte().
Referenced by javolution.io.Struct.readBits(), and javolution.io.Struct.writeBits().
|
inherited |
Sets the current byte buffer for this struct. The specified byte buffer can be mapped to memory for direct memory access or can wrap a shared byte array for I/O purpose (e.g. DatagramPacket
). The capacity of the specified byte buffer should be at least the size of this struct plus the offset position.
byteBuffer | the new byte buffer. |
position | the position of this struct in the specified byte buffer. |
this
IllegalArgumentException | if the specified byteBuffer has a different byte order than this struct. |
UnsupportedOperationException | if this struct is an inner struct. |
Definition at line 283 of file Struct.java.
References javolution.io.Struct._byteBuffer, javolution.io.Struct._outer, javolution.io.Struct._outerOffset, and javolution.io.Struct.byteOrder().
Referenced by javolution.io.Struct.newBuffer(), and javolution.io.Struct.setByteBufferPosition().
|
inherited |
Sets the byte position of this struct within its byte buffer.
position | the position of this struct in its byte buffer. |
this
UnsupportedOperationException | if this struct is an inner struct. |
Definition at line 301 of file Struct.java.
References javolution.io.Struct.getByteBuffer(), and javolution.io.Struct.setByteBuffer().
|
inherited |
Returns the size in bytes of this struct. The size includes tail padding to satisfy the struct word size requirement (defined by the largest word size of its members).
sizeof(this)
. Definition at line 225 of file Struct.java.
References javolution.io.Struct._alignment, and javolution.io.Struct._length.
Referenced by javolution.io.Struct.inner(), javolution.io.Struct.newBuffer(), javolution.io.Struct.read(), javolution.io.Struct.readBits(), javolution.io.Struct.toString(), javolution.io.Struct.write(), and javolution.io.Struct.writeBits().
|
inherited |
Returns the String
representation of this struct in the form of its constituing bytes (hexadecimal). For example:[code] public static class Student extends Struct { Utf8String name = new Utf8String(16); Unsigned16 year = new Unsigned16(); Float32 grade = new Float32(); } Student student = new Student(); student.name.set("John Doe"); student.year.set(2003); student.grade.set(12.5f); System.out.println(student);
4A 6F 68 6E 20 44 6F 65 00 00 00 00 00 00 00 00 07 D3 00 00 41 48 00 00[/code]
Definition at line 420 of file Struct.java.
References javolution.text.TextBuilder.append(), javolution.io.Struct.getByteBuffer(), javolution.io.Struct.getByteBufferPosition(), javolution.io.Struct.HEXA, javolution.io.Struct.size(), and javolution.text.TextBuilder.toString().
|
inherited |
Writes this struct to the specified output stream (convenience method when using Stream I/O). For better performance, use of Block I/O (e.g. java.nio.channels.*
) is recommended.
out | the output stream to write to. |
IOException | if an I/O error occurs. |
Definition at line 366 of file Struct.java.
References javolution.io.Struct._bytes, javolution.io.Struct.getByteBuffer(), javolution.io.Struct.getByteBufferPosition(), and javolution.io.Struct.size().
|
inherited |
Writes the specified bits into this Struct.
value | the bits value as a signed long. |
bitOffset | the bit start position in the Struct. |
bitSize | the number of bits. |
IllegalArgumentException | if (bitOffset + bitSize - 1) / 8 >= this.size() |
Definition at line 822 of file Struct.java.
References javolution.io.Struct.byteOrder(), javolution.io.Struct.getByteBufferPosition(), javolution.io.Struct.readByteBufferLong(), javolution.io.Struct.size(), and javolution.io.Struct.writeByteBufferLong().
Referenced by javolution.io.Struct.BitField.set().
|
staticprivateinherited |
Definition at line 869 of file Struct.java.
Referenced by javolution.io.Struct.writeByteBufferLong().
|
privateinherited |
Definition at line 841 of file Struct.java.
References javolution.io.Struct.getByteBuffer(), and javolution.io.Struct.writeByte().
Referenced by javolution.io.Struct.writeBits().
|
packageinherited |
Holds this struct alignment in bytes (largest word size of its members).
Definition at line 181 of file Struct.java.
Referenced by javolution.io.Struct.inner(), javolution.io.Struct.Member.Member(), and javolution.io.Struct.size().
|
packageinherited |
Holds the bits used in the word during construction (for bit fields). This is the number of bits used in the last word.
Definition at line 200 of file Struct.java.
Referenced by javolution.io.Struct.Member.Member().
|
packageinherited |
Holds the byte buffer backing the struct (top struct).
Definition at line 172 of file Struct.java.
Referenced by javolution.io.Struct.getByteBuffer(), javolution.io.Struct.newBuffer(), and javolution.io.Struct.setByteBuffer().
|
packageinherited |
Holds bytes array for Stream I/O when byteBuffer has no intrinsic array.
Definition at line 209 of file Struct.java.
Referenced by javolution.io.Struct.read(), and javolution.io.Struct.write().
|
packageinherited |
Holds the index position during construction. This is the index a the first unused byte available.
Definition at line 190 of file Struct.java.
Referenced by javolution.io.Struct.array(), and javolution.io.Struct.Member.Member().
|
packageinherited |
Holds this struct's length.
Definition at line 185 of file Struct.java.
Referenced by javolution.io.Struct.Member.Member(), and javolution.io.Struct.size().
|
packageinherited |
Holds the outer struct if any.
Definition at line 168 of file Struct.java.
Referenced by javolution.io.Struct.byteOrder(), javolution.io.Struct.getByteBuffer(), javolution.io.Struct.getByteBufferPosition(), javolution.io.Struct.inner(), javolution.io.Struct.outer(), and javolution.io.Struct.setByteBuffer().
|
packageinherited |
Holds the offset of this struct relative to the outer struct or to the byte buffer if there is no outer.
Definition at line 177 of file Struct.java.
Referenced by javolution.io.Struct.getByteBufferPosition(), and javolution.io.Struct.setByteBuffer().
|
packageinherited |
Indicates if the index has to be reset for each new field ( true
only for Union subclasses).
Definition at line 205 of file Struct.java.
Referenced by javolution.io.Struct.array(), javolution.io.Struct.Member.Member(), and javolution.io.Struct.Struct().
|
packageinherited |
Holds the word size during construction (for bit fields). This is the size of the last word used.
Definition at line 195 of file Struct.java.
Referenced by javolution.io.Struct.Member.Member().
|
staticprivateinherited |
Definition at line 673 of file Struct.java.
Referenced by javolution.io.Struct.array().
|
staticprivateinherited |
Definition at line 688 of file Struct.java.
Referenced by javolution.io.Struct.array().
|
staticprivateinherited |
Definition at line 690 of file Struct.java.
Referenced by javolution.io.Struct.array().
|
staticprivateinherited |
Definition at line 434 of file Struct.java.
Referenced by javolution.io.Struct.toString().
|
staticinherited |
Configurable holding the maximum wordSize in bytes (default 4
). Should be a value greater or equal to 1.
Definition at line 158 of file Struct.java.
|
staticprivateinherited |
Definition at line 678 of file Struct.java.
Referenced by javolution.io.Struct.array().
|
staticprivateinherited |
Definition at line 682 of file Struct.java.
Referenced by javolution.io.Struct.array().
|
staticprivateinherited |
Definition at line 686 of file Struct.java.
Referenced by javolution.io.Struct.array().
|
staticprivateinherited |
Definition at line 674 of file Struct.java.
Referenced by javolution.io.Struct.array().
|
staticprivateinherited |
Definition at line 680 of file Struct.java.
Referenced by javolution.io.Struct.array().
|
staticprivateinherited |
Definition at line 684 of file Struct.java.
Referenced by javolution.io.Struct.array().
|
staticprivateinherited |
Definition at line 676 of file Struct.java.
Referenced by javolution.io.Struct.array().