public byte[] Serialize(IBitBufferSerializable obj) { BitBuffer bitBuffer = new BitBuffer(); if (ConfigProperties.Instance.isServer) { bitBuffer.EnqueueEnum(MessageType.SERVER, MessageType.TOTAL); if (obj is PlayerJoinedMessage) { bitBuffer.EnqueueEnum(ServerMessageType.PLAYER_JOINED, ServerMessageType.TOTAL); } else if (obj is PlayerLeftMessage) { bitBuffer.EnqueueEnum(ServerMessageType.PLAYER_LEFT, ServerMessageType.TOTAL); } else if (obj is SnapshotMessage) { bitBuffer.EnqueueEnum(ServerMessageType.SNAPSHOT, ServerMessageType.TOTAL); } } else { bitBuffer.EnqueueEnum(MessageType.CLIENT, MessageType.TOTAL); if (obj is JoinMessage) { bitBuffer.EnqueueEnum(ClientMessageType.JOIN, ClientMessageType.TOTAL); } else if (obj is LeaveMessage) { bitBuffer.EnqueueEnum(ClientMessageType.LEAVE, ClientMessageType.TOTAL); } else if (obj is GameMessage) { bitBuffer.EnqueueEnum(ClientMessageType.GAME, ClientMessageType.TOTAL); if (obj is MovementMessage) { bitBuffer.EnqueueEnum(GameMessageType.MOVEMENT, GameMessageType.TOTAL); } } } obj.Serialize(bitBuffer); return(bitBuffer.Bytes); }
public void EnqueueSerializable(IBitBufferSerializable serializable) { serializable.Serialize(this); }