/** * Pack collection of notifications to binary array. Note that all notification packed together should be from the * same node, e.g. having the same {@link NodeInfo} (see {@link #getFrom()}, so from data is not packed to this * array and snould be transfered outside it. * * @param notifications notificatins to pack * * @return */ static byte[] pack(Collection<Notification> notifications) { Boss.Writer writer = new Boss.Writer(); try { for (Notification n : notifications) { write(writer, n); } return writer.toByteArray(); } catch (IOException e) { throw new RuntimeException("failed to pack notification", e); } }
private final byte[] packNotifications(NodeInfo from, Collection<Notification> notifications) { Boss.Writer w = new Boss.Writer(); try { w.write(1) // packet type code .write(from.getNumber()) // from number .write(notifications.size()); // count notifications notifications.forEach(n -> { try { Notification.write(w, n); } catch (IOException e) { throw new RuntimeException("notificaiton pack failure", e); } }); return w.toByteArray(); } catch (IOException e) { throw new RuntimeException("notificaiton pack failure", e); } }
private final byte[] packNotifications(NodeInfo from, Collection<Notification> notifications) { Boss.Writer w = new Boss.Writer(); try { w.write(1) // packet type code .write(from.getNumber()) // from number .write(notifications.size()); // count notifications notifications.forEach(n -> { try { Notification.write(w, n); } catch (IOException e) { throw new RuntimeException("notificaiton pack failure", e); } }); return w.toByteArray(); } catch (IOException e) { throw new RuntimeException("notificaiton pack failure", e); } }