Package org.ngengine.network.protocol
Class DynamicSerializerProtocol
java.lang.Object
org.ngengine.network.protocol.DynamicSerializerProtocol
- All Implemented Interfaces:
MessageProtocol
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static class -
Constructor Summary
ConstructorsConstructorDescriptionDynamicSerializerProtocol(boolean spidermonkeyCompatible, Consumer<Long> onClassRegistered, long initialLastId) Creates a new DynamicSerializerProtocol that automatically handles class registration and serialization. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidcheckIsSerializable(Class<?> messageClass, boolean messageOnly) protected <T> Tdeserialize(ByteBuffer bytes, Class<?> expectedClass, boolean messageOnly) protected SerializergetBestSerializerFor(Class<?> cls) voidmarkClassRegistered(long id) protected voidregisterDefaultSerializables(boolean spidermonkeyCompatible) protected voidvoidregisterSerializable(Class<?>... clss) voidregisterSerializableAnnotation(Class<?> cls) voidregisterSerializer(Class<?> cls, Serializer serializer) protected voidserialize(Object obj, GrowableByteBuffer buffer, boolean messageOnly) voidsetForceStaticBuffer(boolean forceStatic) Force use of static buffer (old behavior) even if the serialize supports dynamic buffers.voidsetLastId(long lastId) protected ObjectswapInternals(Object obj) toByteBuffer(Message message, ByteBuffer target) Converts a message to a ByteBuffer using the com.jme3.network.serializing.Serializer and the (short length) + data protocol.toMessage(ByteBuffer bytes) Creates and returns a message from the properly sized byte buffer using com.jme3.network.serializing.Serializer.
-
Constructor Details
-
DynamicSerializerProtocol
public DynamicSerializerProtocol(boolean spidermonkeyCompatible, Consumer<Long> onClassRegistered, long initialLastId) Creates a new DynamicSerializerProtocol that automatically handles class registration and serialization.- Parameters:
strict- set if the serializer should be strict (safer) or unstrict (FAFO)
-
-
Method Details
-
registerDefaultSerializables
protected void registerDefaultSerializables(boolean spidermonkeyCompatible) -
registerDefaultSerializers
protected void registerDefaultSerializers() -
setLastId
public void setLastId(long lastId) -
setForceStaticBuffer
public void setForceStaticBuffer(boolean forceStatic) Force use of static buffer (old behavior) even if the serialize supports dynamic buffers. Used mostly for debugging.- Parameters:
forceStatic-
-
registerSerializer
-
registerSerializable
-
registerSerializableAnnotation
-
checkIsSerializable
-
getBestSerializerFor
-
swapInternals
-
serialize
protected void serialize(Object obj, GrowableByteBuffer buffer, boolean messageOnly) throws IOException - Throws:
IOException
-
markClassRegistered
public void markClassRegistered(long id) -
deserialize
protected <T> T deserialize(ByteBuffer bytes, Class<?> expectedClass, boolean messageOnly) throws IOException - Throws:
IOException
-
toByteBuffer
Converts a message to a ByteBuffer using the com.jme3.network.serializing.Serializer and the (short length) + data protocol. If target is null then a 32k byte buffer will be created and filled.- Specified by:
toByteBufferin interfaceMessageProtocol
-
toMessage
Creates and returns a message from the properly sized byte buffer using com.jme3.network.serializing.Serializer.- Specified by:
toMessagein interfaceMessageProtocol
-
createBuffer
- Specified by:
createBufferin interfaceMessageProtocol
-