use of net.sergeych.boss.Boss in project universa by UniversaBlockchain.
the class Notification method unpack.
/**
* Unpack notifications from the binary form and link it with sending node (this information should be transferred
* aside from the packed notification to not to produce redundant copies of it, all notifications from the same
* node are packed together). Use {@link #pack(Collection)} to get packed binary.
*
* @param from node that has send notifications
* @param packed representation
* @return
* @throws IOException
*/
static List<Notification> unpack(NodeInfo from, byte[] packed) throws IOException {
ArrayList<Notification> notifications = new ArrayList<>();
Boss.Reader r = new Boss.Reader(packed);
try {
while (true) {
// boss reader throws EOFException
Notification n = read(from, r);
if (n != null)
notifications.add(n);
}
} catch (EOFException x) {
// normal, all data decoded
} catch (InvocationTargetException | IllegalAccessException | InstantiationException | NullPointerException | NoSuchMethodException e) {
throw new IOException("Failed to decoded notification", e);
}
return notifications;
}
Aggregations