Exemplo n.º 1
0
 public void putRawBuilder(GameFrameBuilder builder) {
   checkByteAccess();
   if (builder.type != Type.RAW) {
     throw new IllegalArgumentException("Builder must be raw!");
   }
   builder.checkByteAccess();
   putBytes(builder.buffer);
 }
Exemplo n.º 2
0
 /**
  * Puts a smart into the buffer.
  *
  * @param value The value.
  */
 public void putSmart(int value) {
   checkByteAccess();
   if (value < 128) {
     buffer.writeByte(value);
   } else {
     buffer.writeShort(value);
   }
 }
Exemplo n.º 3
0
 /**
  * Puts a string into the buffer.
  *
  * @param str The string.
  */
 public void putString(String str) {
   checkByteAccess();
   char[] chars = str.toCharArray();
   for (char c : chars) {
     buffer.writeByte((byte) c);
   }
   buffer.writeByte(0);
 }
Exemplo n.º 4
0
  public void putRawBuilder(GameFrameBuilder builder, DataTransformation transformation) {
    checkByteAccess();
    if (builder.type != Type.RAW) {
      throw new IllegalArgumentException("Builder must be raw!");
    }
    builder.checkByteAccess();

    byte[] tmp = new byte[builder.buffer.readableBytes()];
    builder.buffer.readBytes(tmp);
    putBytes(transformation, tmp);
  }
Exemplo n.º 5
0
 public int getLength() {
   checkByteAccess();
   return buffer.writerIndex();
 }
Exemplo n.º 6
0
 /**
  * Puts the specified byte array into the buffer in reverse.
  *
  * @param bytes The byte array.
  * @throws IllegalStateException if the builder is not in byte access mode.
  */
 public void putBytesReverse(byte[] bytes) {
   checkByteAccess();
   for (int i = bytes.length - 1; i >= 0; i--) {
     buffer.writeByte(bytes[i]);
   }
 }
Exemplo n.º 7
0
 /**
  * Puts a standard data type with the specified value, byte order and transformation.
  *
  * @param type The data type.
  * @param order The byte order.
  * @param transformation The transformation.
  * @param value The value.
  * @throws IllegalStateException if this reader is not in byte access mode.
  * @throws IllegalArgumentException if the combination is invalid.
  */
 public void put(DataType type, DataOrder order, DataTransformation transformation, Number value) {
   checkByteAccess();
   long longValue = value.longValue();
   int length = type.getBytes();
   if (order == DataOrder.BIG) {
     for (int i = length - 1; i >= 0; i--) {
       if (i == 0 && transformation != DataTransformation.NONE) {
         if (transformation == DataTransformation.ADD) {
           buffer.writeByte((byte) (longValue + 128));
         } else if (transformation == DataTransformation.NEGATE) {
           buffer.writeByte((byte) (-longValue));
         } else if (transformation == DataTransformation.SUBTRACT) {
           buffer.writeByte((byte) (128 - longValue));
         } else {
           throw new IllegalArgumentException("unknown transformation");
         }
       } else {
         buffer.writeByte((byte) (longValue >> (i * 8)));
       }
     }
   } else if (order == DataOrder.LITTLE) {
     for (int i = 0; i < length; i++) {
       if (i == 0 && transformation != DataTransformation.NONE) {
         if (transformation == DataTransformation.ADD) {
           buffer.writeByte((byte) (longValue + 128));
         } else if (transformation == DataTransformation.NEGATE) {
           buffer.writeByte((byte) (-longValue));
         } else if (transformation == DataTransformation.SUBTRACT) {
           buffer.writeByte((byte) (128 - longValue));
         } else {
           throw new IllegalArgumentException("unknown transformation");
         }
       } else {
         buffer.writeByte((byte) (longValue >> (i * 8)));
       }
     }
   } else if (order == DataOrder.MIDDLE) {
     if (transformation != DataTransformation.NONE) {
       throw new IllegalArgumentException("middle endian cannot be transformed");
     }
     if (type != DataType.INT) {
       throw new IllegalArgumentException("middle endian can only be used with an integer");
     }
     buffer.writeByte((byte) (longValue >> 8));
     buffer.writeByte((byte) longValue);
     buffer.writeByte((byte) (longValue >> 24));
     buffer.writeByte((byte) (longValue >> 16));
   } else if (order == DataOrder.INVERSED_MIDDLE) {
     if (transformation != DataTransformation.NONE) {
       throw new IllegalArgumentException("inversed middle endian cannot be transformed");
     }
     if (type != DataType.INT) {
       throw new IllegalArgumentException(
           "inversed middle endian can only be used with an integer");
     }
     buffer.writeByte((byte) (longValue >> 16));
     buffer.writeByte((byte) (longValue >> 24));
     buffer.writeByte((byte) longValue);
     buffer.writeByte((byte) (longValue >> 8));
   } else {
     throw new IllegalArgumentException("unknown order");
   }
 }