Network Serialization (5 posts)

  • Profile picture of squizzle squizzle1p said 6 months, 3 weeks ago:

    How do you use the Serializer to write and read from ByteBuffer?

    I tried and I keep getting a java.lang.UnsupportedOperationException

    	Serializer.setStrictRegistration(false);
    	ByteBuffer buffer = BufferUtils.createByteBuffer(1024);
    	Serializer.writeClassAndObject(buffer, o); // o is a object
    	return buffer.array();
  • Profile picture of pspeed pspeed815p said 6 months, 3 weeks ago:

    I’d probably have to see the stack trace for the exception and the rest of its message (if there was one).

    Note: if you don’t register your classes ahead of time then you likely won’t be able to read the data again… since reading will definitely require registration and it has to be done in _exactly_ the same order. (Unless you are giving everything specific IDs… then the order doesn’t matter as much but you’ll still need to register ahead of reading.)

  • Profile picture of squizzle squizzle1p said 6 months, 3 weeks ago:

    Here is the stacktrace.

    00:00 ERROR: *ERROR*
    java.lang.UnsupportedOperationException
    at java.nio.ByteBuffer.array(ByteBuffer.java:940)
    at shared.util.Cryption.encryptObject(Cryption.java:25)
    at shared.network.packets.SecureMessage.setData(SecureMessage.java:26)
    at server.MainApplication.main(MainApplication.java:37)
    Looks to me like the bytebuffer.array is the problem. The object is registered and the underlying types in the class are registered as well.

  • Profile picture of pspeed pspeed815p said 6 months, 3 weeks ago:

    What’s this doing:
    shared.util.Cryption.encryptObject(Cryption.java:25)

    What is that code trying to do and to which ByteBuffer?

  • Profile picture of pspeed pspeed815p said 6 months, 3 weeks ago:

    By the way… 99.999% sure this is creating a direct memory buffer:
    ByteBuffer buffer = BufferUtils.createByteBuffer(1024);

    …you probably don’t want that as the memory is native and therefore access from Java is slightly slower and you can’t do things like array().