/** * Test serialization code of RPClass by serializing it and then deserializing the stream again * and checking that it is the same RPClass. * * @throws IOException */ @Test public void testSerialization() throws IOException { RPClass expected = new RPClass("RPClassTest::I"); assertEquals(expected, RPClass.getRPClass("RPClassTest::I")); expected.add(DefinitionClass.ATTRIBUTE, "a", Type.INT, Definition.STANDARD); expected.add(DefinitionClass.ATTRIBUTE, "b", Type.FLAG, Definition.HIDDEN); expected.add( DefinitionClass.ATTRIBUTE, "c", Type.STRING, (byte) (Definition.PRIVATE | Definition.VOLATILE)); expected.add(DefinitionClass.RPSLOT, "d", 1, Definition.HIDDEN); ByteArrayOutputStream out = new ByteArrayOutputStream(); OutputSerializer os = new OutputSerializer(out); os.write(expected); ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); InputSerializer is = new InputSerializer(in); RPClass result = (RPClass) is.readObject(new RPClass()); assertEquals(expected, result); }
@Override public void readObject(marauroa.common.net.InputSerializer in) throws IOException { super.readObject(in); try { reason = Result.values()[in.readByte()]; } catch (ArrayIndexOutOfBoundsException e) { logger.error(e, e); reason = Result.FAILED_EXCEPTION; } if (type != MessageType.S2C_CREATEACCOUNT_NACK) { throw new IOException(); } }