@Test public void testEncodePayload_base64() { final byte[][] messages = new byte[][] { {1, 2, 3, 4, 5}, {11, 12, 13, 14, 15} }; final List<Packet<?>> packets = new ArrayList<>(); final JSONArray jsonArray = new JSONArray(); for (int i = 0; i < messages.length; i++) { jsonArray.put(i, messages[i]); Packet<byte[]> packet = new Packet<>(Packet.MESSAGE); packet.data = messages[i]; packets.add(packet); } ServerParser.encodePayload(packets, false, data -> { String result = runScriptAndGetOutput("src/test/resources/testEncodePayload_base64.js", jsonArray.toString(), String.class); assertEquals(result, data); }); }
public static void encodePayload(List<Packet<?>> packets, boolean supportsBinary, Parser.EncodeCallback callback) { boolean isBinary = false; for (Packet packet : packets) { if (packet.data instanceof byte[]) { isBinary = true; break; } } if (isBinary && supportsBinary) { Parser.EncodeCallback<byte[]> _callback = (Parser.EncodeCallback<byte[]>) callback; encodePayloadAsBinary(packets, _callback); return; } if (packets.size() == 0) { callback.call("0:"); return; } final StringBuilder result = new StringBuilder(); for (Packet packet : packets) { encodePacket(packet, false, data -> result.append(setLengthHeader((String) data))); } callback.call(result.toString()); }
ServerParser { public static void encodePayload(List<Packet<?>> packets, boolean supportsBinary, Parser.EncodeCallback callback) { boolean isBinary = false; for (Packet packet : packets) { if (packet.data instanceof byte[]) { isBinary = true; break; } } if (isBinary && supportsBinary) { Parser.EncodeCallback<byte[]> _callback = (Parser.EncodeCallback<byte[]>) callback; encodePayloadAsBinary(packets, _callback); return; } if (packets.size() == 0) { callback.call("0:"); return; } final StringBuilder result = new StringBuilder(); for (Packet packet : packets) { encodePacket(packet, false, data -> result.append(setLengthHeader((String) data))); } callback.call(result.toString()); } }
ServerParser { public static void encodePayload(List<Packet<?>> packets, boolean supportsBinary, Parser.EncodeCallback callback) { boolean isBinary = false; for (Packet packet : packets) { if (packet.data instanceof byte[]) { isBinary = true; break; } } if (isBinary && supportsBinary) { Parser.EncodeCallback<byte[]> _callback = (Parser.EncodeCallback<byte[]>) callback; encodePayloadAsBinary(packets, _callback); return; } if (packets.size() == 0) { callback.call("0:"); return; } final StringBuilder result = new StringBuilder(); for (Packet packet : packets) { encodePacket(packet, false, data -> result.append(setLengthHeader((String) data))); } callback.call(result.toString()); } private  ServerParser(); }
ServerParser { public static void encodePayload(List<Packet<?>> packets, boolean supportsBinary, Parser.EncodeCallback callback) { boolean isBinary = false; for (Packet packet : packets) { if (packet.data instanceof byte[]) { isBinary = true; break; } } if (isBinary && supportsBinary) { Parser.EncodeCallback<byte[]> _callback = (Parser.EncodeCallback<byte[]>) callback; encodePayloadAsBinary(packets, _callback); return; } if (packets.size() == 0) { callback.call("0:"); return; } final StringBuilder result = new StringBuilder(); for (Packet packet : packets) { encodePacket(packet, false, data -> result.append(setLengthHeader((String) data))); } callback.call(result.toString()); } 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 void encodePayload(List<Packet<?>> packets, boolean supportsBinary, Parser.EncodeCallback callback) { boolean isBinary = false; for (Packet packet : packets) { if (packet.data instanceof byte[]) { isBinary = true; break; } } if (isBinary && supportsBinary) { Parser.EncodeCallback<byte[]> _callback = (Parser.EncodeCallback<byte[]>) callback; encodePayloadAsBinary(packets, _callback); return; } if (packets.size() == 0) { callback.call("0:"); return; } final StringBuilder result = new StringBuilder(); for (Packet packet : packets) { encodePacket(packet, false, data -> result.append(setLengthHeader((String) data))); } callback.call(result.toString()); } 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; }