Example #1
0
 @Override
 public void deserialize(Buffer buf) {
   houseId = buf.readInt();
   if (houseId < 0)
     throw new RuntimeException(
         "Forbidden value on houseId = "
             + houseId
             + ", it doesn't respect the following condition : houseId < 0");
 }
Example #2
0
 @Override
 public void deserialize(Buffer buf) {
   objectUID = buf.readInt();
   if (objectUID < 0)
     throw new RuntimeException(
         "Forbidden value on objectUID = "
             + objectUID
             + ", it doesn't respect the following condition : objectUID < 0");
   foodUID = buf.readInt();
   if (foodUID < 0)
     throw new RuntimeException(
         "Forbidden value on foodUID = "
             + foodUID
             + ", it doesn't respect the following condition : foodUID < 0");
   foodQuantity = buf.readShort();
   if (foodQuantity < 0)
     throw new RuntimeException(
         "Forbidden value on foodQuantity = "
             + foodQuantity
             + ", it doesn't respect the following condition : foodQuantity < 0");
 }
Example #3
0
  @Test
  public void readPadStringAndRightTrim() {
    String testString = StringUtils.repeat('a', 10);
    Buffer writeBuffer = new FixedBuffer(32);
    writeBuffer.putPadString(testString, 20);
    writeBuffer.put(255);

    Buffer readBuffer = new FixedBuffer(writeBuffer.getBuffer());
    String readPadString = readBuffer.readPadStringAndRightTrim(20);
    Assert.assertEquals(testString, readPadString);
    int readInt = readBuffer.readInt();
    Assert.assertEquals(255, readInt);
  }
Example #4
0
  @Test
  public void readPadBytes() {
    byte[] bytes = new byte[10];
    random.nextBytes(bytes);
    Buffer writeBuffer = new FixedBuffer(32);
    writeBuffer.putPadBytes(bytes, 20);
    writeBuffer.put(255);

    Buffer readBuffer = new FixedBuffer(writeBuffer.getBuffer());
    byte[] readPadBytes = readBuffer.readPadBytes(20);
    Assert.assertArrayEquals(bytes, Arrays.copyOf(readPadBytes, 10));
    int readInt = readBuffer.readInt();
    Assert.assertEquals(255, readInt);
  }
Example #5
0
 @Override
 public void deserialize(Buffer buf) {
   short flag1 = buf.readUByte();
   isOnSale = BooleanByteWrapper.getFlag(flag1, 0);
   isSaleLocked = BooleanByteWrapper.getFlag(flag1, 1);
   houseId = buf.readInt();
   if (houseId < 0)
     throw new RuntimeException(
         "Forbidden value on houseId = "
             + houseId
             + ", it doesn't respect the following condition : houseId < 0");
   int limit = buf.readUShort();
   doorsOnMap = new int[limit];
   for (int i = 0; i < limit; i++) {
     doorsOnMap[i] = buf.readInt();
   }
   ownerName = buf.readString();
   modelId = buf.readShort();
   if (modelId < 0)
     throw new RuntimeException(
         "Forbidden value on modelId = "
             + modelId
             + ", it doesn't respect the following condition : modelId < 0");
 }
Example #6
0
  private void testPutPrefixedBytes(String test, int expected) {
    Buffer buffer = new FixedBuffer(1024);
    if (test != null) {
      buffer.putPrefixedBytes(test.getBytes(UTF8_CHARSET));
    } else {
      buffer.putPrefixedString(null);
    }

    buffer.put(expected);
    byte[] buffer1 = buffer.getBuffer();

    Buffer actual = new FixedBuffer(buffer1);
    String s = actual.readPrefixedString();
    Assert.assertEquals(test, s);

    int i = actual.readInt();
    Assert.assertEquals(expected, i);
  }