@Test(expected = IllegalArgumentException.class) public void testDecodePacket_error() { ServerParser.decodePacket(0); }
public static Packet decodePacket(Object data) { if(data == null) { return err; } if(data instanceof String) { final String stringData = (String) data; if(stringData.charAt(0) == 'b') { Packet<byte[]> packet = new Packet<>(packetsList.get( Integer.parseInt(String.valueOf(stringData.charAt(1))))); packet.data = Base64.getDecoder().decode(stringData.substring(2)); return packet; } else { Packet<String> packet = new Packet<>(packetsList.get( Integer.parseInt(String.valueOf(stringData.charAt(0))))); packet.data = stringData.substring(1); return packet; } } else if(data instanceof byte[]) { final byte[] byteData = (byte[]) data; Packet<byte[]> packet = new Packet<>(packetsList.get((int) byteData[0])); packet.data = new byte[byteData.length - 1]; System.arraycopy(byteData, 1, packet.data, 0, packet.data.length); return packet; } else { throw new IllegalArgumentException("Invalid type for data: " + data.getClass().getSimpleName()); } }
ServerParser { public static Packet decodePacket(Object data) { if(data == null) { return err; } if(data instanceof String) { final String stringData = (String) data; if(stringData.charAt(0) == 'b') { Packet<byte[]> packet = new Packet<>(packetsList.get( Integer.parseInt(String.valueOf(stringData.charAt(1))))); packet.data = Base64.getDecoder().decode(stringData.substring(2)); return packet; } else { Packet<String> packet = new Packet<>(packetsList.get( Integer.parseInt(String.valueOf(stringData.charAt(0))))); packet.data = stringData.substring(1); return packet; } } else if(data instanceof byte[]) { final byte[] byteData = (byte[]) data; Packet<byte[]> packet = new Packet<>(packetsList.get((int) byteData[0])); packet.data = new byte[byteData.length - 1]; System.arraycopy(byteData, 1, packet.data, 0, packet.data.length); return packet; } else { throw new IllegalArgumentException("Invalid type for data: " + data.getClass().getSimpleName()); } } }
ServerParser { public static Packet decodePacket(Object data) { if(data == null) { return err; } if(data instanceof String) { final String stringData = (String) data; if(stringData.charAt(0) == 'b') { Packet<byte[]> packet = new Packet<>(packetsList.get( Integer.parseInt(String.valueOf(stringData.charAt(1))))); packet.data = Base64.getDecoder().decode(stringData.substring(2)); return packet; } else { Packet<String> packet = new Packet<>(packetsList.get( Integer.parseInt(String.valueOf(stringData.charAt(0))))); packet.data = stringData.substring(1); return packet; } } else if(data instanceof byte[]) { final byte[] byteData = (byte[]) data; Packet<byte[]> packet = new Packet<>(packetsList.get((int) byteData[0])); packet.data = new byte[byteData.length - 1]; System.arraycopy(byteData, 1, packet.data, 0, packet.data.length); return packet; } else { throw new IllegalArgumentException("Invalid type for data: " + data.getClass().getSimpleName()); } } private  ServerParser(); }
ServerParser { public static Packet decodePacket(Object data) { if(data == null) { return err; } if(data instanceof String) { final String stringData = (String) data; if(stringData.charAt(0) == 'b') { Packet<byte[]> packet = new Packet<>(packetsList.get( Integer.parseInt(String.valueOf(stringData.charAt(1))))); packet.data = Base64.getDecoder().decode(stringData.substring(2)); return packet; } else { Packet<String> packet = new Packet<>(packetsList.get( Integer.parseInt(String.valueOf(stringData.charAt(0))))); packet.data = stringData.substring(1); return packet; } } else if(data instanceof byte[]) { final byte[] byteData = (byte[]) data; Packet<byte[]> packet = new Packet<>(packetsList.get((int) byteData[0])); packet.data = new byte[byteData.length - 1]; System.arraycopy(byteData, 1, packet.data, 0, packet.data.length); return packet; } else { throw new IllegalArgumentException("Invalid type for data: " + data.getClass().getSimpleName()); } } private  ServerParser(); static void encodePacket(Packet packet, boolean supportsBinary, Parser.EncodeCallback callback); static void encodePayload(List<Packet<?>> packets, boolean supportsBinary, Parser.EncodeCallback callback); @SuppressWarnings("Duplicates") static void encodePayloadAsBinary(List<Packet<?>> packets, Parser.EncodeCallback<byte[]> callback); static Packet decodePacket(Object data); static void decodePayload(Object data, Parser.DecodePayloadCallback callback); }
ServerParser { public static Packet decodePacket(Object data) { if(data == null) { return err; } if(data instanceof String) { final String stringData = (String) data; if(stringData.charAt(0) == 'b') { Packet<byte[]> packet = new Packet<>(packetsList.get( Integer.parseInt(String.valueOf(stringData.charAt(1))))); packet.data = Base64.getDecoder().decode(stringData.substring(2)); return packet; } else { Packet<String> packet = new Packet<>(packetsList.get( Integer.parseInt(String.valueOf(stringData.charAt(0))))); packet.data = stringData.substring(1); return packet; } } else if(data instanceof byte[]) { final byte[] byteData = (byte[]) data; Packet<byte[]> packet = new Packet<>(packetsList.get((int) byteData[0])); packet.data = new byte[byteData.length - 1]; System.arraycopy(byteData, 1, packet.data, 0, packet.data.length); return packet; } else { throw new IllegalArgumentException("Invalid type for data: " + data.getClass().getSimpleName()); } } private  ServerParser(); static void encodePacket(Packet packet, boolean supportsBinary, Parser.EncodeCallback callback); static void encodePayload(List<Packet<?>> packets, boolean supportsBinary, Parser.EncodeCallback callback); @SuppressWarnings("Duplicates") static void encodePayloadAsBinary(List<Packet<?>> packets, Parser.EncodeCallback<byte[]> callback); static Packet decodePacket(Object data); static void decodePayload(Object data, Parser.DecodePayloadCallback callback); @SuppressWarnings("WeakerAccess")
    static final int PROTOCOL; }