Search in sources :

Example 1 with Boss

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;
}
Also used : IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) Boss(net.sergeych.boss.Boss) EOFException(java.io.EOFException)

Aggregations

EOFException (java.io.EOFException)1 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Boss (net.sergeych.boss.Boss)1