@Test public void testEncodingOpenResponse() { final String openFrameData = "relp_version=0\nrelp_software=librelp,1.2.7,http: final String openFrame = "1 open 85 " + openFrameData + "\n"; System.out.println(openFrame); final RELPDecoder decoder = new RELPDecoder(StandardCharsets.UTF_8); final RELPEncoder encoder = new RELPEncoder(StandardCharsets.UTF_8); RELPFrame frame = null; for (byte b : openFrame.getBytes(StandardCharsets.UTF_8)) { if (decoder.process(b)) { frame = decoder.getFrame(); break; } } Assert.assertNotNull(frame); final Map<String,String> offers = RELPResponse.parseOffers(frame.getData(), StandardCharsets.UTF_8); final RELPFrame responseFrame = RELPResponse.open(frame.getTxnr(), offers).toFrame(StandardCharsets.UTF_8); final byte[] response = encoder.encode(responseFrame); System.out.println(new String(response, StandardCharsets.UTF_8)); }
public byte[] encode(final RELPFrame frame) { final ByteArrayOutputStream buffer = new ByteArrayOutputStream(); byte[] txnr = String.format("%s", frame.getTxnr()).getBytes(charset); buffer.write(txnr, 0, txnr.length); buffer.write(RELPFrame.SEPARATOR); byte[] command = frame.getCommand().getBytes(charset); buffer.write(command, 0, command.length); buffer.write(RELPFrame.SEPARATOR); byte[] dataLength = String.format("%s", frame.getDataLength()).getBytes(charset); buffer.write(dataLength, 0, dataLength.length); if (frame.getDataLength() > 0) { buffer.write(RELPFrame.SEPARATOR); buffer.write(frame.getData(), 0, frame.getDataLength()); } buffer.write(RELPFrame.DELIMITER); return buffer.toByteArray(); }
RELPEncoder { public byte[] encode(final RELPFrame frame) { final ByteArrayOutputStream buffer = new ByteArrayOutputStream(); byte[] txnr = String.format("%s", frame.getTxnr()).getBytes(charset); buffer.write(txnr, 0, txnr.length); buffer.write(RELPFrame.SEPARATOR); byte[] command = frame.getCommand().getBytes(charset); buffer.write(command, 0, command.length); buffer.write(RELPFrame.SEPARATOR); byte[] dataLength = String.format("%s", frame.getDataLength()).getBytes(charset); buffer.write(dataLength, 0, dataLength.length); if (frame.getDataLength() > 0) { buffer.write(RELPFrame.SEPARATOR); buffer.write(frame.getData(), 0, frame.getDataLength()); } buffer.write(RELPFrame.DELIMITER); return buffer.toByteArray(); } }
RELPEncoder { public byte[] encode(final RELPFrame frame) { final ByteArrayOutputStream buffer = new ByteArrayOutputStream(); byte[] txnr = String.format("%s", frame.getTxnr()).getBytes(charset); buffer.write(txnr, 0, txnr.length); buffer.write(RELPFrame.SEPARATOR); byte[] command = frame.getCommand().getBytes(charset); buffer.write(command, 0, command.length); buffer.write(RELPFrame.SEPARATOR); byte[] dataLength = String.format("%s", frame.getDataLength()).getBytes(charset); buffer.write(dataLength, 0, dataLength.length); if (frame.getDataLength() > 0) { buffer.write(RELPFrame.SEPARATOR); buffer.write(frame.getData(), 0, frame.getDataLength()); } buffer.write(RELPFrame.DELIMITER); return buffer.toByteArray(); } RELPEncoder(final Charset charset); }
RELPEncoder { public byte[] encode(final RELPFrame frame) { final ByteArrayOutputStream buffer = new ByteArrayOutputStream(); byte[] txnr = String.format("%s", frame.getTxnr()).getBytes(charset); buffer.write(txnr, 0, txnr.length); buffer.write(RELPFrame.SEPARATOR); byte[] command = frame.getCommand().getBytes(charset); buffer.write(command, 0, command.length); buffer.write(RELPFrame.SEPARATOR); byte[] dataLength = String.format("%s", frame.getDataLength()).getBytes(charset); buffer.write(dataLength, 0, dataLength.length); if (frame.getDataLength() > 0) { buffer.write(RELPFrame.SEPARATOR); buffer.write(frame.getData(), 0, frame.getDataLength()); } buffer.write(RELPFrame.DELIMITER); return buffer.toByteArray(); } RELPEncoder(final Charset charset); Charset getCharset(); byte[] encode(final RELPFrame frame); }
RELPEncoder { public byte[] encode(final RELPFrame frame) { final ByteArrayOutputStream buffer = new ByteArrayOutputStream(); byte[] txnr = String.format("%s", frame.getTxnr()).getBytes(charset); buffer.write(txnr, 0, txnr.length); buffer.write(RELPFrame.SEPARATOR); byte[] command = frame.getCommand().getBytes(charset); buffer.write(command, 0, command.length); buffer.write(RELPFrame.SEPARATOR); byte[] dataLength = String.format("%s", frame.getDataLength()).getBytes(charset); buffer.write(dataLength, 0, dataLength.length); if (frame.getDataLength() > 0) { buffer.write(RELPFrame.SEPARATOR); buffer.write(frame.getData(), 0, frame.getDataLength()); } buffer.write(RELPFrame.DELIMITER); return buffer.toByteArray(); } RELPEncoder(final Charset charset); Charset getCharset(); byte[] encode(final RELPFrame frame);  }