Javolution 6.0.0 java
Struct.java
Go to the documentation of this file.
1 /*
2  * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
3  * Copyright (C) 2012 - Javolution (http://javolution.org/)
4  * All rights reserved.
5  *
6  * Permission to use, copy, modify, and distribute this software is
7  * freely granted, provided that this notice is preserved.
8  */
9 package javolution.io;
10 
11 import java.io.IOException;
12 import java.io.InputStream;
13 import java.io.OutputStream;
14 import java.nio.ByteBuffer;
15 import java.nio.ByteOrder;
16 
18 import javolution.lang.MathLib;
19 import javolution.lang.Realtime;
21 
150 @SuppressWarnings("unchecked")
151 @Realtime
152 public class Struct {
153 
158  public static final LocalContext.Parameter<Integer> MAXIMUM_ALIGNMENT = new LocalContext.Parameter<Integer>() {
159  @Override
160  protected Integer getDefault() {
161  return 4;
162  }
163  };
164 
172  ByteBuffer _byteBuffer;
181  int _alignment = 1;
185  int _length;
190  int _index;
205  boolean _resetIndex;
209  byte[] _bytes;
210 
214  public Struct() {
215  _resetIndex = isUnion();
216  }
217 
225  public final int size() {
226  return (_alignment <= 1) ? _length
227  : ((_length + _alignment - 1) / _alignment) * _alignment;
228  }
229 
236  public Struct outer() {
237  return _outer;
238  }
239 
254  public final ByteBuffer getByteBuffer() {
255  if (_outer != null) return _outer.getByteBuffer();
256  return (_byteBuffer != null) ? _byteBuffer : newBuffer();
257  }
258 
259  private synchronized ByteBuffer newBuffer() {
260  if (_byteBuffer != null) return _byteBuffer; // Synchronized check.
261  ByteBuffer bf = ByteBuffer.allocateDirect(size());
262  bf.order(byteOrder());
263  setByteBuffer(bf, 0);
264  return _byteBuffer;
265  }
266 
283  public final Struct setByteBuffer(ByteBuffer byteBuffer, int position) {
284  if (byteBuffer.order() != byteOrder()) throw new IllegalArgumentException(
285  "The byte order of the specified byte buffer"
286  + " is different from this struct byte order");
287  if (_outer != null) throw new UnsupportedOperationException(
288  "Inner struct byte buffer is inherited from outer");
289  _byteBuffer = byteBuffer;
290  _outerOffset = position;
291  return this;
292  }
293 
301  public final Struct setByteBufferPosition(int position) {
302  return setByteBuffer(this.getByteBuffer(), position);
303  }
304 
312  public final int getByteBufferPosition() {
313  return (_outer != null) ? _outer.getByteBufferPosition() + _outerOffset
314  : _outerOffset;
315  }
316 
332  public int read(InputStream in) throws IOException {
333  ByteBuffer buffer = getByteBuffer();
334  int size = size();
335  int remaining = size - buffer.position();
336  if (remaining == 0) remaining = size;// at end so move to beginning
337  int alreadyRead = size - remaining; // typically 0
338  if (buffer.hasArray()) {
339  int offset = buffer.arrayOffset() + getByteBufferPosition();
340  int bytesRead = in
341  .read(buffer.array(), offset + alreadyRead, remaining);
342  buffer.position(getByteBufferPosition() + alreadyRead + bytesRead
343  - offset);
344  return bytesRead;
345  } else {
346  synchronized (buffer) {
347  if (_bytes == null) {
348  _bytes = new byte[size()];
349  }
350  int bytesRead = in.read(_bytes, 0, remaining);
351  buffer.position(getByteBufferPosition() + alreadyRead);
352  buffer.put(_bytes, 0, bytesRead);
353  return bytesRead;
354  }
355  }
356  }
357 
366  public void write(OutputStream out) throws IOException {
367  ByteBuffer buffer = getByteBuffer();
368  if (buffer.hasArray()) {
369  int offset = buffer.arrayOffset() + getByteBufferPosition();
370  out.write(buffer.array(), offset, size());
371  } else {
372  synchronized (buffer) {
373  if (_bytes == null) {
374  _bytes = new byte[size()];
375  }
376  buffer.position(getByteBufferPosition());
377  buffer.get(_bytes);
378  out.write(_bytes);
379  }
380  }
381  }
382 
393  public final long address() {
394  ByteBuffer thisBuffer = this.getByteBuffer();
395  if (thisBuffer instanceof sun.nio.ch.DirectBuffer)
396  return ((sun.nio.ch.DirectBuffer)thisBuffer).address();
397  throw new UnsupportedOperationException();
398  }
399 
420  public String toString() {
421  TextBuilder tmp = new TextBuilder();
422  final int size = size();
423  final ByteBuffer buffer = getByteBuffer();
424  final int start = getByteBufferPosition();
425  for (int i = 0; i < size; i++) {
426  int b = buffer.get(start + i) & 0xFF;
427  tmp.append(HEXA[b >> 4]);
428  tmp.append(HEXA[b & 0xF]);
429  tmp.append(((i & 0xF) == 0xF) ? '\n' : ' ');
430  }
431  return tmp.toString();
432  }
433 
434  private static final char[] HEXA = { '0', '1', '2', '3', '4', '5', '6',
435  '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
436 
438  // CONFIGURATION //
440 
461  public boolean isUnion() {
462  return false;
463  }
464 
480  public ByteOrder byteOrder() {
481  return (_outer != null) ? _outer.byteOrder() : ByteOrder.BIG_ENDIAN;
482  }
483 
501  public boolean isPacked() {
502  return false;
503  }
504 
513  protected <S extends Struct> S inner(S struct) {
514  if (struct._outer != null) throw new IllegalArgumentException(
515  "struct: Already an inner struct");
516  Member inner = new Member(struct.size() << 3, struct._alignment); // Update indexes.
517  struct._outer = this;
518  struct._outerOffset = inner.offset();
519  return (S) struct;
520  }
521 
532  protected <S extends Struct> S[] array(S[] structs) {
533  Class<?> structClass = null;
534  boolean resetIndexSaved = _resetIndex;
535  if (_resetIndex) {
536  _index = 0;
537  _resetIndex = false; // Ensures the array elements are sequential.
538  }
539  for (int i = 0; i < structs.length;) {
540  S struct = structs[i];
541  if (struct == null) {
542  try {
543  if (structClass == null) {
544  String arrayName = structs.getClass().getName();
545  String structName = arrayName.substring(2,
546  arrayName.length() - 1);
547  structClass = Class.forName(structName);
548  if (structClass == null) { throw new IllegalArgumentException(
549  "Struct class: " + structName + " not found"); }
550  }
551  struct = (S) structClass.newInstance();
552  } catch (Exception e) {
553  throw new RuntimeException(e.getMessage());
554  }
555  }
556  structs[i++] = inner(struct);
557  }
558  _resetIndex = resetIndexSaved;
559  return (S[]) structs;
560  }
561 
572  protected <S extends Struct> S[][] array(S[][] structs) {
573  boolean resetIndexSaved = _resetIndex;
574  if (_resetIndex) {
575  _index = 0;
576  _resetIndex = false; // Ensures the array elements are sequential.
577  }
578  for (int i = 0; i < structs.length; i++) {
579  array(structs[i]);
580  }
581  _resetIndex = resetIndexSaved;
582  return (S[][]) structs;
583  }
584 
595  protected <S extends Struct> S[][][] array(S[][][] structs) {
596  boolean resetIndexSaved = _resetIndex;
597  if (_resetIndex) {
598  _index = 0;
599  _resetIndex = false; // Ensures the array elements are sequential.
600  }
601  for (int i = 0; i < structs.length; i++) {
602  array(structs[i]);
603  }
604  _resetIndex = resetIndexSaved;
605  return (S[][][]) structs;
606  }
607 
618  protected <M extends Member> M[] array(M[] arrayMember) {
619  boolean resetIndexSaved = _resetIndex;
620  if (_resetIndex) {
621  _index = 0;
622  _resetIndex = false; // Ensures the array elements are sequential.
623  }
624  if (BOOL.isInstance(arrayMember)) {
625  for (int i = 0; i < arrayMember.length;) {
626  arrayMember[i++] = (M) this.new Bool();
627  }
628  } else if (SIGNED_8.isInstance(arrayMember)) {
629  for (int i = 0; i < arrayMember.length;) {
630  arrayMember[i++] = (M) this.new Signed8();
631  }
632  } else if (UNSIGNED_8.isInstance(arrayMember)) {
633  for (int i = 0; i < arrayMember.length;) {
634  arrayMember[i++] = (M) this.new Unsigned8();
635  }
636  } else if (SIGNED_16.isInstance(arrayMember)) {
637  for (int i = 0; i < arrayMember.length;) {
638  arrayMember[i++] = (M) this.new Signed16();
639  }
640  } else if (UNSIGNED_16.isInstance(arrayMember)) {
641  for (int i = 0; i < arrayMember.length;) {
642  arrayMember[i++] = (M) this.new Unsigned16();
643  }
644  } else if (SIGNED_32.isInstance(arrayMember)) {
645  for (int i = 0; i < arrayMember.length;) {
646  arrayMember[i++] = (M) this.new Signed32();
647  }
648  } else if (UNSIGNED_32.isInstance(arrayMember)) {
649  for (int i = 0; i < arrayMember.length;) {
650  arrayMember[i++] = (M) this.new Unsigned32();
651  }
652  } else if (SIGNED_64.isInstance(arrayMember)) {
653  for (int i = 0; i < arrayMember.length;) {
654  arrayMember[i++] = (M) this.new Signed64();
655  }
656  } else if (FLOAT_32.isInstance(arrayMember)) {
657  for (int i = 0; i < arrayMember.length;) {
658  arrayMember[i++] = (M) this.new Float32();
659  }
660  } else if (FLOAT_64.isInstance(arrayMember)) {
661  for (int i = 0; i < arrayMember.length;) {
662  arrayMember[i++] = (M) this.new Float64();
663  }
664  } else {
665  throw new UnsupportedOperationException(
666  "Cannot create member elements, the arrayMember should "
667  + "contain the member instances instead of null");
668  }
669  _resetIndex = resetIndexSaved;
670  return (M[]) arrayMember;
671  }
672 
673  private static final Class<? extends Bool[]> BOOL = new Bool[0].getClass();
674  private static final Class<? extends Signed8[]> SIGNED_8 = new Signed8[0]
675  .getClass();
676  private static final Class<? extends Unsigned8[]> UNSIGNED_8 = new Unsigned8[0]
677  .getClass();
678  private static final Class<? extends Signed16[]> SIGNED_16 = new Signed16[0]
679  .getClass();
680  private static final Class<? extends Unsigned16[]> UNSIGNED_16 = new Unsigned16[0]
681  .getClass();
682  private static final Class<? extends Signed32[]> SIGNED_32 = new Signed32[0]
683  .getClass();
684  private static final Class<? extends Unsigned32[]> UNSIGNED_32 = new Unsigned32[0]
685  .getClass();
686  private static final Class<? extends Signed64[]> SIGNED_64 = new Signed64[0]
687  .getClass();
688  private static final Class<? extends Float32[]> FLOAT_32 = new Float32[0]
689  .getClass();
690  private static final Class<? extends Float64[]> FLOAT_64 = new Float64[0]
691  .getClass();
692 
703  protected <M extends Member> M[][] array(M[][] arrayMember) {
704  boolean resetIndexSaved = _resetIndex;
705  if (_resetIndex) {
706  _index = 0;
707  _resetIndex = false; // Ensures the array elements are sequential.
708  }
709  for (int i = 0; i < arrayMember.length; i++) {
710  array(arrayMember[i]);
711  }
712  _resetIndex = resetIndexSaved;
713  return (M[][]) arrayMember;
714  }
715 
726  protected <M extends Member> M[][][] array(M[][][] arrayMember) {
727  boolean resetIndexSaved = _resetIndex;
728  if (_resetIndex) {
729  _index = 0;
730  _resetIndex = false; // Ensures the array elements are sequential.
731  }
732  for (int i = 0; i < arrayMember.length; i++) {
733  array(arrayMember[i]);
734  }
735  _resetIndex = resetIndexSaved;
736  return (M[][][]) arrayMember;
737  }
738 
747  protected UTF8String[] array(UTF8String[] array, int stringLength) {
748  boolean resetIndexSaved = _resetIndex;
749  if (_resetIndex) {
750  _index = 0;
751  _resetIndex = false; // Ensures the array elements are sequential.
752  }
753  for (int i = 0; i < array.length; i++) {
754  array[i] = new UTF8String(stringLength);
755  }
756  _resetIndex = resetIndexSaved;
757  return array;
758  }
759 
770  public long readBits(int bitOffset, int bitSize) {
771  if ((bitOffset + bitSize - 1) >> 3 >= this.size()) throw new IllegalArgumentException(
772  "Attempt to read outside the Struct");
773  int offset = bitOffset >> 3;
774  int bitStart = bitOffset - (offset << 3);
775  bitStart = (byteOrder() == ByteOrder.BIG_ENDIAN) ? bitStart : 64
776  - bitSize - bitStart;
777  int index = getByteBufferPosition() + offset;
778  long value = readByteBufferLong(index);
779  value <<= bitStart; // Clears preceding bits.
780  value >>= (64 - bitSize); // Signed shift.
781  return value;
782  }
783 
784  private long readByteBufferLong(int index) {
785  ByteBuffer byteBuffer = getByteBuffer();
786  if (index + 8 < byteBuffer.limit()) return byteBuffer.getLong(index);
787  // Else possible buffer overflow.
788  if (byteBuffer.order() == ByteOrder.LITTLE_ENDIAN) {
789  return (readByte(index, byteBuffer) & 0xff)
790  + ((readByte(++index, byteBuffer) & 0xff) << 8)
791  + ((readByte(++index, byteBuffer) & 0xff) << 16)
792  + ((readByte(++index, byteBuffer) & 0xffL) << 24)
793  + ((readByte(++index, byteBuffer) & 0xffL) << 32)
794  + ((readByte(++index, byteBuffer) & 0xffL) << 40)
795  + ((readByte(++index, byteBuffer) & 0xffL) << 48)
796  + ((readByte(++index, byteBuffer) & 0xffL) << 56);
797  } else {
798  return (((long) readByte(index, byteBuffer)) << 56)
799  + ((readByte(++index, byteBuffer) & 0xffL) << 48)
800  + ((readByte(++index, byteBuffer) & 0xffL) << 40)
801  + ((readByte(++index, byteBuffer) & 0xffL) << 32)
802  + ((readByte(++index, byteBuffer) & 0xffL) << 24)
803  + ((readByte(++index, byteBuffer) & 0xff) << 16)
804  + ((readByte(++index, byteBuffer) & 0xff) << 8)
805  + (readByte(++index, byteBuffer) & 0xffL);
806  }
807  }
808 
809  private static byte readByte(int index, ByteBuffer byteBuffer) {
810  return (index < byteBuffer.limit()) ? byteBuffer.get(index) : 0;
811  }
812 
822  public void writeBits(long value, int bitOffset, int bitSize) {
823  if ((bitOffset + bitSize - 1) >> 3 >= this.size()) throw new IllegalArgumentException(
824  "Attempt to write outside the Struct");
825  int offset = bitOffset >> 3;
826  int bitStart = (byteOrder() == ByteOrder.BIG_ENDIAN) ? bitOffset
827  - (offset << 3) : 64 - bitSize - (bitOffset - (offset << 3));
828  long mask = -1L;
829  mask <<= bitStart; // Clears preceding bits
830  mask >>>= (64 - bitSize); // Unsigned shift.
831  mask <<= 64 - bitSize - bitStart;
832  value <<= (64 - bitSize - bitStart);
833  value &= mask; // Protects against out of range values.
834  int index = getByteBufferPosition() + offset;
835  long oldValue = readByteBufferLong(index);
836  long resetValue = oldValue & (~mask);
837  long newValue = resetValue | value;
838  writeByteBufferLong(index, newValue);
839  }
840 
841  private void writeByteBufferLong(int index, long value) {
842  ByteBuffer byteBuffer = getByteBuffer();
843  if (index + 8 < byteBuffer.limit()) {
844  byteBuffer.putLong(index, value);
845  return;
846  }
847  // Else possible buffer overflow.
848  if (byteBuffer.order() == ByteOrder.LITTLE_ENDIAN) {
849  writeByte(index, byteBuffer, (byte) value);
850  writeByte(++index, byteBuffer, (byte) (value >> 8));
851  writeByte(++index, byteBuffer, (byte) (value >> 16));
852  writeByte(++index, byteBuffer, (byte) (value >> 24));
853  writeByte(++index, byteBuffer, (byte) (value >> 32));
854  writeByte(++index, byteBuffer, (byte) (value >> 40));
855  writeByte(++index, byteBuffer, (byte) (value >> 48));
856  writeByte(++index, byteBuffer, (byte) (value >> 56));
857  } else {
858  writeByte(index, byteBuffer, (byte) (value >> 56));
859  writeByte(++index, byteBuffer, (byte) (value >> 48));
860  writeByte(++index, byteBuffer, (byte) (value >> 40));
861  writeByte(++index, byteBuffer, (byte) (value >> 32));
862  writeByte(++index, byteBuffer, (byte) (value >> 24));
863  writeByte(++index, byteBuffer, (byte) (value >> 16));
864  writeByte(++index, byteBuffer, (byte) (value >> 8));
865  writeByte(++index, byteBuffer, (byte) value);
866  }
867  }
868 
869  private static void writeByte(int index, ByteBuffer byteBuffer, byte value) {
870  if (index < byteBuffer.limit()) {
871  byteBuffer.put(index, value);
872  }
873  }
874 
876  // MEMBERS //
878 
894  protected class Member {
895 
899  private final int _offset;
903  private final int _bitIndex;
907  private final int _bitLength;
908 
922  protected Member(int bitLength, int wordSize) {
924 
925  // Resets index if union.
926  if (_resetIndex) {
927  _index = 0;
928  }
929 
930  // Check if we can merge bitfields (always true if no word boundary).
931  if ((wordSize == 0)
932  || ((bitLength != 0) && (wordSize == _wordSize) && ((_bitsUsed + bitLength) <= (wordSize << 3)))) {
933 
936  _bitsUsed += bitLength;
937 
938  // Straddling word boundary only possible if (wordSize == 0)
939  while (_bitsUsed > (_wordSize << 3)) {
940  _index++;
941  _wordSize++;
943  }
944  return; // Bit field merge done.
945  }
946 
947  // Check alignment.
948  if (!isPacked()) {
949 
950  // Updates struct's alignment constraint, based on largest word size.
951  if ((_alignment < wordSize)) {
952  _alignment = wordSize;
953  }
954 
955  // Adds padding if misaligned.
956  int misaligned = _index % wordSize;
957  if (misaligned != 0) {
958  _index += wordSize - misaligned;
959  }
960  }
961 
962  // Sets member indices.
963  _offset = _index;
964  _bitIndex = 0;
965 
966  // Update struct indices.
967  _index += MathLib.max(wordSize, (bitLength + 7) >> 3);
968  _wordSize = wordSize;
971  // size and index may differ because of {@link Union}
972  }
973 
979  public final Struct struct() {
980  return Struct.this;
981  }
982 
989  public final int offset() {
990  return _offset;
991  }
992 
998  public final int bitIndex() {
999  return _bitIndex;
1000  }
1001 
1008  public final int bitLength() {
1009  return _bitLength;
1010  }
1011 
1012  // Returns the member int value.
1013  final int get(int wordSize, int word) {
1014  final int shift = (byteOrder() == ByteOrder.BIG_ENDIAN) ? (wordSize << 3)
1015  - bitIndex() - bitLength()
1016  : bitIndex();
1017  word >>= shift;
1018  int mask = 0xFFFFFFFF >>> (32 - bitLength());
1019  return word & mask;
1020  }
1021 
1022  // Sets the member int value.
1023  final int set(int value, int wordSize, int word) {
1024  final int shift = (byteOrder() == ByteOrder.BIG_ENDIAN) ? (wordSize << 3)
1025  - bitIndex() - bitLength()
1026  : bitIndex();
1027  int mask = 0xFFFFFFFF >>> (32 - bitLength());
1028  mask <<= shift;
1029  value <<= shift;
1030  return (word & ~mask) | (value & mask);
1031  }
1032 
1033  // Returns the member long value.
1034  final long get(int wordSize, long word) {
1035  final int shift = (byteOrder() == ByteOrder.BIG_ENDIAN) ? (wordSize << 3)
1036  - bitIndex() - bitLength()
1037  : bitIndex();
1038  word >>= shift;
1039  long mask = 0xFFFFFFFFFFFFFFFFL >>> (64 - bitLength());
1040  return word & mask;
1041  }
1042 
1043  // Sets the member long value.
1044  final long set(long value, int wordSize, long word) {
1045  final int shift = (byteOrder() == ByteOrder.BIG_ENDIAN) ? (wordSize << 3)
1046  - bitIndex() - bitLength()
1047  : bitIndex();
1048  long mask = 0xFFFFFFFFFFFFFFFFL >>> (64 - bitLength());
1049  mask <<= shift;
1050  value <<= shift;
1051  return (word & ~mask) | (value & mask);
1052  }
1053  }
1054 
1056  // PREDEFINED FIELDS //
1058 
1062  public class UTF8String extends Member {
1063 
1066  private final int _length;
1067 
1068  public UTF8String(int length) {
1069  super(length << 3, 1);
1070  _length = length; // Takes into account 0 terminator.
1071  }
1072 
1073  public void set(String string) {
1074  final ByteBuffer buffer = getByteBuffer();
1075  synchronized (buffer) {
1076  try {
1077  int index = getByteBufferPosition() + offset();
1078  buffer.position(index);
1079  _writer.setOutput(buffer);
1080  if (string.length() < _length) {
1081  _writer.write(string);
1082  _writer.write(0); // Marks end of string.
1083  } else if (string.length() > _length) { // Truncates.
1084  _writer.write(string.substring(0, _length));
1085  } else { // Exact same length.
1086  _writer.write(string);
1087  }
1088  } catch (IOException e) { // Should never happen.
1089  throw new Error(e.getMessage());
1090  } finally {
1091  _writer.reset();
1092  }
1093  }
1094  }
1095 
1096  public String get() {
1097  final ByteBuffer buffer = getByteBuffer();
1098  synchronized (buffer) {
1099  TextBuilder tmp = new TextBuilder();
1100  try {
1101  int index = getByteBufferPosition() + offset();
1102  buffer.position(index);
1103  _reader.setInput(buffer);
1104  for (int i = 0; i < _length; i++) {
1105  char c = (char) _reader.read();
1106  if (c == 0) { // Null terminator.
1107  return tmp.toString();
1108  } else {
1109  tmp.append(c);
1110  }
1111  }
1112  return tmp.toString();
1113  } catch (IOException e) { // Should never happen.
1114  throw new Error(e.getMessage());
1115  } finally {
1116  _reader.reset();
1117  }
1118  }
1119  }
1120 
1121  public String toString() {
1122  return this.get();
1123  }
1124  }
1125 
1130  public class Bool extends Member {
1131 
1132  public Bool() {
1133  super(8, 1);
1134  }
1135 
1136  public Bool(int nbrOfBits) {
1137  super(nbrOfBits, 1);
1138  }
1139 
1140  public boolean get() {
1141  final int index = getByteBufferPosition() + offset();
1142  int word = getByteBuffer().get(index);
1143  word = (bitLength() == 8) ? word : get(1, word);
1144  return word != 0;
1145  }
1146 
1147  public void set(boolean value) {
1148  final int index = getByteBufferPosition() + offset();
1149  if (bitLength() == 8) {
1150  getByteBuffer().put(index, (byte) (value ? -1 : 0));
1151  } else {
1152  getByteBuffer().put(
1153  index,
1154  (byte) set(value ? -1 : 0, 1, getByteBuffer()
1155  .get(index)));
1156  }
1157  }
1158 
1159  public String toString() {
1160  return String.valueOf(this.get());
1161  }
1162  }
1163 
1167  public class Signed8 extends Member {
1168 
1169  public Signed8() {
1170  super(8, 1);
1171  }
1172 
1173  public Signed8(int nbrOfBits) {
1174  super(nbrOfBits, 1);
1175  }
1176 
1177  public byte get() {
1178  final int index = getByteBufferPosition() + offset();
1179  int word = getByteBuffer().get(index);
1180  return (byte) ((bitLength() == 8) ? word : get(1, word));
1181  }
1182 
1183  public void set(byte value) {
1184  final int index = getByteBufferPosition() + offset();
1185  if (bitLength() == 8) {
1186  getByteBuffer().put(index, value);
1187  } else {
1188  getByteBuffer().put(index,
1189  (byte) set(value, 1, getByteBuffer().get(index)));
1190  }
1191  }
1192 
1193  public String toString() {
1194  return String.valueOf(this.get());
1195  }
1196  }
1197 
1201  public class Unsigned8 extends Member {
1202 
1203  public Unsigned8() {
1204  super(8, 1);
1205  }
1206 
1207  public Unsigned8(int nbrOfBits) {
1208  super(nbrOfBits, 1);
1209  }
1210 
1211  public short get() {
1212  final int index = getByteBufferPosition() + offset();
1213  int word = getByteBuffer().get(index);
1214  return (short) (0xFF & ((bitLength() == 8) ? word : get(1, word)));
1215  }
1216 
1217  public void set(short value) {
1218  final int index = getByteBufferPosition() + offset();
1219  if (bitLength() == 8) {
1220  getByteBuffer().put(index, (byte) value);
1221  } else {
1222  getByteBuffer().put(index,
1223  (byte) set(value, 1, getByteBuffer().get(index)));
1224  }
1225  }
1226 
1227  public String toString() {
1228  return String.valueOf(this.get());
1229  }
1230  }
1231 
1235  public class Signed16 extends Member {
1236 
1237  public Signed16() {
1238  super(16, 2);
1239  }
1240 
1241  public Signed16(int nbrOfBits) {
1242  super(nbrOfBits, 2);
1243  }
1244 
1245  public short get() {
1246  final int index = getByteBufferPosition() + offset();
1247  int word = getByteBuffer().getShort(index);
1248  return (short) ((bitLength() == 16) ? word : get(2, word));
1249  }
1250 
1251  public void set(short value) {
1252  final int index = getByteBufferPosition() + offset();
1253  if (bitLength() == 16) {
1254  getByteBuffer().putShort(index, value);
1255  } else {
1256  getByteBuffer().putShort(index,
1257  (short) set(value, 2, getByteBuffer().getShort(index)));
1258  }
1259  }
1260 
1261  public String toString() {
1262  return String.valueOf(this.get());
1263  }
1264  }
1265 
1269  public class Unsigned16 extends Member {
1270 
1271  public Unsigned16() {
1272  super(16, 2);
1273  }
1274 
1275  public Unsigned16(int nbrOfBits) {
1276  super(nbrOfBits, 2);
1277  }
1278 
1279  public int get() {
1280  final int index = getByteBufferPosition() + offset();
1281  int word = getByteBuffer().getShort(index);
1282  return 0xFFFF & ((bitLength() == 16) ? word : get(2, word));
1283  }
1284 
1285  public void set(int value) {
1286  final int index = getByteBufferPosition() + offset();
1287  if (bitLength() == 16) {
1288  getByteBuffer().putShort(index, (short) value);
1289  } else {
1290  getByteBuffer().putShort(index,
1291  (short) set(value, 2, getByteBuffer().getShort(index)));
1292  }
1293  }
1294 
1295  public String toString() {
1296  return String.valueOf(this.get());
1297  }
1298  }
1299 
1303  public class Signed32 extends Member {
1304 
1305  public Signed32() {
1306  super(32, 4);
1307  }
1308 
1309  public Signed32(int nbrOfBits) {
1310  super(nbrOfBits, 4);
1311  }
1312 
1313  public int get() {
1314  final int index = getByteBufferPosition() + offset();
1315  int word = getByteBuffer().getInt(index);
1316  return (bitLength() == 32) ? word : get(4, word);
1317  }
1318 
1319  public void set(int value) {
1320  final int index = getByteBufferPosition() + offset();
1321  if (bitLength() == 32) {
1322  getByteBuffer().putInt(index, value);
1323  } else {
1324  getByteBuffer().putInt(index,
1325  set(value, 4, getByteBuffer().getInt(index)));
1326  }
1327  }
1328 
1329  public String toString() {
1330  return String.valueOf(this.get());
1331  }
1332  }
1333 
1337  public class Unsigned32 extends Member {
1338 
1339  public Unsigned32() {
1340  super(32, 4);
1341  }
1342 
1343  public Unsigned32(int nbrOfBits) {
1344  super(nbrOfBits, 4);
1345  }
1346 
1347  public long get() {
1348  final int index = getByteBufferPosition() + offset();
1349  int word = getByteBuffer().getInt(index);
1350  return 0xFFFFFFFFL & ((bitLength() == 32) ? word : get(4, word));
1351  }
1352 
1353  public void set(long value) {
1354  final int index = getByteBufferPosition() + offset();
1355  if (bitLength() == 32) {
1356  getByteBuffer().putInt(index, (int) value);
1357  } else {
1358  getByteBuffer().putInt(index,
1359  set((int) value, 4, getByteBuffer().getInt(index)));
1360  }
1361  }
1362 
1363  public String toString() {
1364  return String.valueOf(this.get());
1365  }
1366  }
1367 
1371  public class Signed64 extends Member {
1372 
1373  public Signed64() {
1374  super(64, 8);
1375  }
1376 
1377  public Signed64(int nbrOfBits) {
1378  super(nbrOfBits, 8);
1379  }
1380 
1381  public long get() {
1382  final int index = getByteBufferPosition() + offset();
1383  long word = getByteBuffer().getLong(index);
1384  return (bitLength() == 64) ? word : get(8, word);
1385  }
1386 
1387  public void set(long value) {
1388  final int index = getByteBufferPosition() + offset();
1389  if (bitLength() == 64) {
1390  getByteBuffer().putLong(index, value);
1391  } else {
1392  getByteBuffer().putLong(index,
1393  set(value, 8, getByteBuffer().getLong(index)));
1394  }
1395  }
1396 
1397  public String toString() {
1398  return String.valueOf(this.get());
1399  }
1400  }
1401 
1406  public class BitField extends Member {
1407 
1408  public BitField(int nbrOfBits) {
1409  super(nbrOfBits, 0);
1410  }
1411 
1412  public long longValue() {
1413  long signedValue = readBits(bitIndex() + (offset() << 3),
1414  bitLength());
1415  return ~(-1L << bitLength()) & signedValue;
1416  }
1417 
1418  public int intValue() {
1419  return (int) longValue();
1420  }
1421 
1422  public short shortValue() {
1423  return (short) longValue();
1424  }
1425 
1426  public byte byteValue() {
1427  return (byte) longValue();
1428  }
1429 
1430  public void set(long value) {
1431  writeBits(value, bitIndex() + (offset() << 3), bitLength());
1432  }
1433 
1434  public String toString() {
1435  return String.valueOf(longValue());
1436  }
1437  }
1438 
1442  public class Float32 extends Member {
1443 
1444  public Float32() {
1445  super(32, 4);
1446  }
1447 
1448  public float get() {
1449  final int index = getByteBufferPosition() + offset();
1450  return getByteBuffer().getFloat(index);
1451  }
1452 
1453  public void set(float value) {
1454  final int index = getByteBufferPosition() + offset();
1455  getByteBuffer().putFloat(index, value);
1456  }
1457 
1458  public String toString() {
1459  return String.valueOf(this.get());
1460  }
1461  }
1462 
1466  public class Float64 extends Member {
1467 
1468  public Float64() {
1469  super(64, 8);
1470  }
1471 
1472  public double get() {
1473  final int index = getByteBufferPosition() + offset();
1474  return getByteBuffer().getDouble(index);
1475  }
1476 
1477  public void set(double value) {
1478  final int index = getByteBufferPosition() + offset();
1479  getByteBuffer().putDouble(index, value);
1480  }
1481 
1482  public String toString() {
1483  return String.valueOf(this.get());
1484  }
1485  }
1486 
1497  public class Reference32<S extends Struct> extends Member {
1498 
1499  private S _struct;
1500 
1501  public Reference32() {
1502  super(32, 4);
1503  }
1504 
1505  public void set(S struct) {
1506  final int index = getByteBufferPosition() + offset();
1507  if (struct != null) {
1508  getByteBuffer().putInt(index, (int) struct.address());
1509  } else {
1510  getByteBuffer().putInt(index, 0);
1511  }
1512  _struct = struct;
1513  }
1514 
1515  public S get() {
1516  return _struct;
1517  }
1518 
1519  public int value() {
1520  final int index = getByteBufferPosition() + offset();
1521  return getByteBuffer().getInt(index);
1522  }
1523 
1524  public boolean isUpToDate() {
1525  final int index = getByteBufferPosition() + offset();
1526  if (_struct != null) {
1527  return getByteBuffer().getInt(index) == (int) _struct.address();
1528  } else {
1529  return getByteBuffer().getInt(index) == 0;
1530  }
1531  }
1532  }
1533 
1544  public class Reference64<S extends Struct> extends Member {
1545 
1546  private S _struct;
1547 
1548  public Reference64() {
1549  super(64, 8);
1550  }
1551 
1552  public void set(S struct) {
1553  final int index = getByteBufferPosition() + offset();
1554  if (struct != null) {
1555  getByteBuffer().putLong(index, struct.address());
1556  } else if (struct == null) {
1557  getByteBuffer().putLong(index, 0L);
1558  }
1559  _struct = struct;
1560  }
1561 
1562  public S get() {
1563  return _struct;
1564  }
1565 
1566  public long value() {
1567  final int index = getByteBufferPosition() + offset();
1568  return getByteBuffer().getLong(index);
1569  }
1570 
1571  public boolean isUpToDate() {
1572  final int index = getByteBufferPosition() + offset();
1573  if (_struct != null) {
1574  return getByteBuffer().getLong(index) == _struct.address();
1575  } else {
1576  return getByteBuffer().getLong(index) == 0L;
1577  }
1578  }
1579  }
1580 
1584  public class Enum8<T extends Enum<T>> extends Member {
1585 
1586  private final T[] _values;
1587 
1588  public Enum8(T[] values) {
1589  super(8, 1);
1590  _values = values;
1591  }
1592 
1593  public Enum8(T[] values, int nbrOfBits) {
1594  super(nbrOfBits, 1);
1595  _values = values;
1596  }
1597 
1598  public T get() {
1599  final int index = getByteBufferPosition() + offset();
1600  int word = getByteBuffer().get(index);
1601  return _values[0xFF & get(1, word)];
1602  }
1603 
1604  public void set(T e) {
1605  int value = e.ordinal();
1606  if (_values[value] != e) throw new IllegalArgumentException(
1607  "enum: "
1608  + e
1609  + ", ordinal value does not reflect enum values position");
1610  final int index = getByteBufferPosition() + offset();
1611  int word = getByteBuffer().get(index);
1612  getByteBuffer().put(index, (byte) set(value, 1, word));
1613  }
1614 
1615  public String toString() {
1616  return String.valueOf(this.get());
1617  }
1618  }
1619 
1623  public class Enum16<T extends Enum<T>> extends Member {
1624 
1625  private final T[] _values;
1626 
1627  public Enum16(T[] values) {
1628  super(16, 2);
1629  _values = values;
1630  }
1631 
1632  public Enum16(T[] values, int nbrOfBits) {
1633  super(nbrOfBits, 2);
1634  _values = values;
1635  }
1636 
1637  public T get() {
1638  final int index = getByteBufferPosition() + offset();
1639  int word = getByteBuffer().getShort(index);
1640  return _values[0xFFFF & get(2, word)];
1641  }
1642 
1643  public void set(T e) {
1644  int value = e.ordinal();
1645  if (_values[value] != e) throw new IllegalArgumentException(
1646  "enum: "
1647  + e
1648  + ", ordinal value does not reflect enum values position");
1649  final int index = getByteBufferPosition() + offset();
1650  int word = getByteBuffer().getShort(index);
1651  getByteBuffer().putShort(index, (short) set(value, 2, word));
1652  }
1653 
1654  public String toString() {
1655  return String.valueOf(this.get());
1656  }
1657  }
1658 
1662  public class Enum32<T extends Enum<T>> extends Member {
1663 
1664  private final T[] _values;
1665 
1666  public Enum32(T[] values) {
1667  super(32, 4);
1668  _values = values;
1669  }
1670 
1671  public Enum32(T[] values, int nbrOfBits) {
1672  super(nbrOfBits, 4);
1673  _values = values;
1674  }
1675 
1676  public T get() {
1677  final int index = getByteBufferPosition() + offset();
1678  int word = getByteBuffer().getInt(index);
1679  return _values[get(4, word)];
1680  }
1681 
1682  public void set(T e) {
1683  int value = e.ordinal();
1684  if (_values[value] != e) throw new IllegalArgumentException(
1685  "enum: "
1686  + e
1687  + ", ordinal value does not reflect enum values position");
1688  final int index = getByteBufferPosition() + offset();
1689  int word = getByteBuffer().getInt(index);
1690  getByteBuffer().putInt(index, set(value, 4, word));
1691  }
1692 
1693  public String toString() {
1694  return String.valueOf(this.get());
1695  }
1696  }
1697 
1701  public class Enum64<T extends Enum<T>> extends Member {
1702 
1703  private final T[] _values;
1704 
1705  public Enum64(T[] values) {
1706  super(64, 8);
1707  _values = values;
1708  }
1709 
1710  public Enum64(T[] values, int nbrOfBits) {
1711  super(nbrOfBits, 8);
1712  _values = values;
1713  }
1714 
1715  public T get() {
1716  final int index = getByteBufferPosition() + offset();
1717  long word = getByteBuffer().getLong(index);
1718  return _values[(int) get(8, word)];
1719  }
1720 
1721  public void set(T e) {
1722  long value = e.ordinal();
1723  if (_values[(int) value] != e) throw new IllegalArgumentException(
1724  "enum: "
1725  + e
1726  + ", ordinal value does not reflect enum values position");
1727  final int index = getByteBufferPosition() + offset();
1728  long word = getByteBuffer().getLong(index);
1729  getByteBuffer().putLong(index, set(value, 8, word));
1730  }
1731 
1732  public String toString() {
1733  return String.valueOf(this.get());
1734  }
1735  }
1736 }
javolution.lang.MathLib.max
static int max(int x, int y)
Definition: MathLib.java:964
javolution.io.Struct.Reference32._struct
S _struct
Definition: Struct.java:1499
javolution.io.Struct.Enum16.Enum16
Enum16(T[] values, int nbrOfBits)
Definition: Struct.java:1632
javolution.io.Struct.Reference32.Reference32
Reference32()
Definition: Struct.java:1501
javolution.io.Struct.UTF8String._reader
final UTF8ByteBufferReader _reader
Definition: Struct.java:1065
javolution.io.UTF8ByteBufferWriter.reset
void reset()
Definition: UTF8ByteBufferWriter.java:212
javolution.io.UTF8ByteBufferWriter.setOutput
UTF8ByteBufferWriter setOutput(ByteBuffer byteBuffer)
Definition: UTF8ByteBufferWriter.java:57
javolution.io.Struct.Bool.Bool
Bool()
Definition: Struct.java:1132
javolution.io.Struct.Float64.Float64
Float64()
Definition: Struct.java:1468
javolution.io.Struct.BitField.BitField
BitField(int nbrOfBits)
Definition: Struct.java:1408
javolution.io.UTF8ByteBufferWriter.write
void write(char c)
Definition: UTF8ByteBufferWriter.java:72
javolution
javolution.io.Struct.Signed8.Signed8
Signed8(int nbrOfBits)
Definition: Struct.java:1173
javolution.io.Struct.Unsigned32.toString
String toString()
Definition: Struct.java:1363
javolution.io.Struct._length
int _length
Definition: Struct.java:185
javolution.io.Struct.array
protected< M extends Member > M[] array(M[] arrayMember)
Definition: Struct.java:618
javolution.io.Struct.Float64.toString
String toString()
Definition: Struct.java:1482
javolution.io.Struct.Signed8.toString
String toString()
Definition: Struct.java:1193
javolution.io.Struct.Unsigned8
Definition: Struct.java:1201
javolution.io.Struct.Signed64.Signed64
Signed64()
Definition: Struct.java:1373
javolution.io.Struct.Enum32
Definition: Struct.java:1662
javolution.io.Struct.Enum32._values
final T[] _values
Definition: Struct.java:1664
javolution.io.Struct.Reference64
Definition: Struct.java:1544
javolution.context.LocalContext
Definition: LocalContext.java:43
javolution.text.TextBuilder.append
final TextBuilder append(char c)
Definition: TextBuilder.java:202
javolution.io.Struct.isUnion
boolean isUnion()
Definition: Struct.java:461
javolution.context
Definition: AbstractContext.java:9
javolution.lang.MathLib
Definition: MathLib.java:20
javolution.io.Struct.Member._offset
final int _offset
Definition: Struct.java:899
javolution.io.Struct.writeByte
static void writeByte(int index, ByteBuffer byteBuffer, byte value)
Definition: Struct.java:869
javolution.io.Struct.Signed32
Definition: Struct.java:1303
javolution.io.Struct.Unsigned32.Unsigned32
Unsigned32(int nbrOfBits)
Definition: Struct.java:1343
javolution.io.Struct.MAXIMUM_ALIGNMENT
static final LocalContext.Parameter< Integer > MAXIMUM_ALIGNMENT
Definition: Struct.java:158
javolution.io.Struct.Unsigned16.Unsigned16
Unsigned16()
Definition: Struct.java:1271
javolution.io.Struct.UTF8String.toString
String toString()
Definition: Struct.java:1121
javolution.io.Struct.array
protected< S extends Struct > S[][] array(S[][] structs)
Definition: Struct.java:572
javolution.io.Struct.BitField.toString
String toString()
Definition: Struct.java:1434
javolution.text.TextBuilder
Definition: TextBuilder.java:29
javolution.io.Struct.Enum32.toString
String toString()
Definition: Struct.java:1693
javolution.io.Struct.UTF8String.UTF8String
UTF8String(int length)
Definition: Struct.java:1068
javolution.io.Struct._outerOffset
int _outerOffset
Definition: Struct.java:177
javolution.io.Struct._bytes
byte[] _bytes
Definition: Struct.java:209
javolution.text.TextBuilder.toString
final String toString()
Definition: TextBuilder.java:780
javolution.io.Struct.Bool.Bool
Bool(int nbrOfBits)
Definition: Struct.java:1136
javolution.io.Struct.BitField.shortValue
short shortValue()
Definition: Struct.java:1422
javolution.io.Struct.Reference64.isUpToDate
boolean isUpToDate()
Definition: Struct.java:1571
javolution.io.Struct.Member
Definition: Struct.java:894
javolution.io.Struct.write
void write(OutputStream out)
Definition: Struct.java:366
javolution.io.Struct.Enum64.Enum64
Enum64(T[] values)
Definition: Struct.java:1705
javolution.io.Struct.Unsigned16.toString
String toString()
Definition: Struct.java:1295
javolution.io.Struct.Unsigned16
Definition: Struct.java:1269
javolution.io.Struct.BOOL
static final Class<? extends Bool[]> BOOL
Definition: Struct.java:673
javolution.io.Struct.array
protected< M extends Member > M[][][] array(M[][][] arrayMember)
Definition: Struct.java:726
javolution.io.Struct
Definition: Struct.java:152
javolution.io.Struct._wordSize
int _wordSize
Definition: Struct.java:195
javolution.io.Struct._index
int _index
Definition: Struct.java:190
javolution.io.Struct.array
UTF8String[] array(UTF8String[] array, int stringLength)
Definition: Struct.java:747
javolution.io.UTF8ByteBufferReader.reset
void reset()
Definition: UTF8ByteBufferReader.java:254
javolution.io.Struct.SIGNED_8
static final Class<? extends Signed8[]> SIGNED_8
Definition: Struct.java:674
javolution.io.Struct.readBits
long readBits(int bitOffset, int bitSize)
Definition: Struct.java:770
javolution.io.Struct.BitField.byteValue
byte byteValue()
Definition: Struct.java:1426
javolution.io.Struct.Member._bitLength
final int _bitLength
Definition: Struct.java:907
javolution.io.Struct._alignment
int _alignment
Definition: Struct.java:181
javolution.io.Struct.Float64
Definition: Struct.java:1466
javolution.io.Struct.UNSIGNED_8
static final Class<? extends Unsigned8[]> UNSIGNED_8
Definition: Struct.java:676
javolution.io.Struct.SIGNED_64
static final Class<? extends Signed64[]> SIGNED_64
Definition: Struct.java:686
javolution.io.Struct.Signed64.toString
String toString()
Definition: Struct.java:1397
javolution.io.Struct.Enum16
Definition: Struct.java:1623
javolution.io.Struct.Reference64.value
long value()
Definition: Struct.java:1566
javolution.io.Struct.Struct
Struct()
Definition: Struct.java:214
javolution.io.Struct.Signed16.Signed16
Signed16()
Definition: Struct.java:1237
javolution.io.Struct.Enum32.Enum32
Enum32(T[] values, int nbrOfBits)
Definition: Struct.java:1671
javolution.io.Struct.UTF8String
Definition: Struct.java:1062
javolution.io.Struct.Float32
Definition: Struct.java:1442
javolution.context.LocalContext.Parameter
Definition: LocalContext.java:49
javolution.io.UTF8ByteBufferReader.read
int read()
Definition: UTF8ByteBufferReader.java:102
javolution.io.Struct._resetIndex
boolean _resetIndex
Definition: Struct.java:205
javolution.io.Struct.Enum8
Definition: Struct.java:1584
javolution.io.Struct.Enum64
Definition: Struct.java:1701
javolution.io.Struct.isPacked
boolean isPacked()
Definition: Struct.java:501
javolution.io.Struct.UNSIGNED_32
static final Class<? extends Unsigned32[]> UNSIGNED_32
Definition: Struct.java:684
javolution.io.Struct.Enum64._values
final T[] _values
Definition: Struct.java:1703
javolution.lang
Definition: Configurable.java:9
javolution.io.Struct.Float32.toString
String toString()
Definition: Struct.java:1458
javolution.io.Struct.Unsigned8.Unsigned8
Unsigned8()
Definition: Struct.java:1203
javolution.io.UTF8ByteBufferWriter
Definition: UTF8ByteBufferWriter.java:37
javolution.io.UTF8ByteBufferReader.setInput
UTF8ByteBufferReader setInput(ByteBuffer byteBuffer)
Definition: UTF8ByteBufferReader.java:60
javolution.io.Struct.FLOAT_64
static final Class<? extends Float64[]> FLOAT_64
Definition: Struct.java:690
javolution.io.Struct.Signed8
Definition: Struct.java:1167
javolution.text
Definition: CharArray.java:9
javolution.io.Struct.Unsigned16.Unsigned16
Unsigned16(int nbrOfBits)
Definition: Struct.java:1275
javolution.io.Struct.Member.offset
final int offset()
Definition: Struct.java:989
javolution.io.Struct.Enum8._values
final T[] _values
Definition: Struct.java:1586
javolution.io.Struct.Signed32.Signed32
Signed32(int nbrOfBits)
Definition: Struct.java:1309
javolution.io.Struct._bitsUsed
int _bitsUsed
Definition: Struct.java:200
javolution.io.Struct.Member._bitIndex
final int _bitIndex
Definition: Struct.java:903
javolution.io.Struct.FLOAT_32
static final Class<? extends Float32[]> FLOAT_32
Definition: Struct.java:688
javolution.io.Struct.Reference32.value
int value()
Definition: Struct.java:1519
javolution.io.Struct.Member.Member
Member(int bitLength, int wordSize)
Definition: Struct.java:922
javolution.io.Struct.SIGNED_32
static final Class<? extends Signed32[]> SIGNED_32
Definition: Struct.java:682
javolution.io.Struct.Signed8.Signed8
Signed8()
Definition: Struct.java:1169
javolution.io.UTF8ByteBufferReader
Definition: UTF8ByteBufferReader.java:39
Exception
javolution.io.Struct.array
protected< M extends Member > M[][] array(M[][] arrayMember)
Definition: Struct.java:703
javolution.io.Struct.Unsigned8.toString
String toString()
Definition: Struct.java:1227
javolution.io.Struct.outer
Struct outer()
Definition: Struct.java:236
javolution.io.Struct.Signed64
Definition: Struct.java:1371
javolution.io.Struct.Signed16.Signed16
Signed16(int nbrOfBits)
Definition: Struct.java:1241
javolution.io.Struct.Enum16.Enum16
Enum16(T[] values)
Definition: Struct.java:1627
javolution.lang.Realtime
Definition: Realtime.java:59
javolution.io.Struct.Reference64._struct
S _struct
Definition: Struct.java:1546
javolution.io.Struct.UTF8String._length
final int _length
Definition: Struct.java:1066
javolution.io.Struct.BitField.longValue
long longValue()
Definition: Struct.java:1412
javolution.io.Struct.Enum8.Enum8
Enum8(T[] values)
Definition: Struct.java:1588
javolution.io.Struct.Reference32.isUpToDate
boolean isUpToDate()
Definition: Struct.java:1524
javolution.io.Struct.toString
String toString()
Definition: Struct.java:420
javolution.io.Struct.Enum32.Enum32
Enum32(T[] values)
Definition: Struct.java:1666
javolution.io.Struct.BitField
Definition: Struct.java:1406
javolution.io.Struct.Unsigned8.Unsigned8
Unsigned8(int nbrOfBits)
Definition: Struct.java:1207
javolution.io.Struct.getByteBufferPosition
final int getByteBufferPosition()
Definition: Struct.java:312
javolution.io.Struct.readByte
static byte readByte(int index, ByteBuffer byteBuffer)
Definition: Struct.java:809
javolution.io.Struct.BitField.intValue
int intValue()
Definition: Struct.java:1418
javolution.io.Struct.UTF8String._writer
final UTF8ByteBufferWriter _writer
Definition: Struct.java:1064
javolution.io.Struct.Float32.Float32
Float32()
Definition: Struct.java:1444
javolution.io.Struct.Signed32.Signed32
Signed32()
Definition: Struct.java:1305
javolution.io.Struct.Bool
Definition: Struct.java:1130
javolution.io.Struct.Enum8.toString
String toString()
Definition: Struct.java:1615
javolution.io.Struct.Unsigned32
Definition: Struct.java:1337
javolution.io.Struct.Enum8.Enum8
Enum8(T[] values, int nbrOfBits)
Definition: Struct.java:1593
javolution.io.Struct.size
final int size()
Definition: Struct.java:225
javolution.io.Struct.byteOrder
ByteOrder byteOrder()
Definition: Struct.java:480
javolution.io.Struct.Member.bitIndex
final int bitIndex()
Definition: Struct.java:998
javolution.io.Struct.writeBits
void writeBits(long value, int bitOffset, int bitSize)
Definition: Struct.java:822
javolution.io.Struct.Bool.toString
String toString()
Definition: Struct.java:1159
javolution.io.Struct.Reference64.Reference64
Reference64()
Definition: Struct.java:1548
javolution.io.Struct.Enum64.toString
String toString()
Definition: Struct.java:1732
javolution.io.Struct.Signed16
Definition: Struct.java:1235
javolution.io.Struct.writeByteBufferLong
void writeByteBufferLong(int index, long value)
Definition: Struct.java:841
javolution.io.Struct.array
protected< S extends Struct > S[][][] array(S[][][] structs)
Definition: Struct.java:595
javolution.io.Struct.Signed16.toString
String toString()
Definition: Struct.java:1261
javolution.io.Struct.Member.bitLength
final int bitLength()
Definition: Struct.java:1008
javolution.io.Struct.UNSIGNED_16
static final Class<? extends Unsigned16[]> UNSIGNED_16
Definition: Struct.java:680
javolution.io.Struct.address
final long address()
Definition: Struct.java:393
javolution.io.Struct.HEXA
static final char[] HEXA
Definition: Struct.java:434
javolution.io.Struct.setByteBufferPosition
final Struct setByteBufferPosition(int position)
Definition: Struct.java:301
javolution.io.Struct.setByteBuffer
final Struct setByteBuffer(ByteBuffer byteBuffer, int position)
Definition: Struct.java:283
javolution.io.Struct.Enum16._values
final T[] _values
Definition: Struct.java:1625
javolution.io.Struct.SIGNED_16
static final Class<? extends Signed16[]> SIGNED_16
Definition: Struct.java:678
javolution.io.Struct.Signed32.toString
String toString()
Definition: Struct.java:1329
javolution.io.Struct.readByteBufferLong
long readByteBufferLong(int index)
Definition: Struct.java:784
javolution.io.Struct.inner
protected< S extends Struct > S inner(S struct)
Definition: Struct.java:513
javolution.io.Struct.newBuffer
synchronized ByteBuffer newBuffer()
Definition: Struct.java:259
javolution.io.Struct.getByteBuffer
final ByteBuffer getByteBuffer()
Definition: Struct.java:254
javolution.io.Struct.read
int read(InputStream in)
Definition: Struct.java:332
javolution.io.Struct.Signed64.Signed64
Signed64(int nbrOfBits)
Definition: Struct.java:1377
javolution.io.Struct.Unsigned32.Unsigned32
Unsigned32()
Definition: Struct.java:1339
javolution.io.Struct.Enum64.Enum64
Enum64(T[] values, int nbrOfBits)
Definition: Struct.java:1710
javolution.io.Struct.Enum16.toString
String toString()
Definition: Struct.java:1654
javolution.io.Struct._outer
Struct _outer
Definition: Struct.java:168
javolution.io.Struct.array
protected< S extends Struct > S[] array(S[] structs)
Definition: Struct.java:532
javolution.io.Struct._byteBuffer
ByteBuffer _byteBuffer
Definition: Struct.java:172
javolution.io.Struct.Reference32
Definition: Struct.java:1497