code: public static byte[] encode(final TaskNode root) {
      try (final ByteArrayOutputStream bstream = new ByteArrayOutputStream();
           final DataOutputStream dstream = new DataOutputStream(bstream)) {
        encodeHelper(dstream, root);
        return bstream.toByteArray();
  
      } catch (final IOException e) {
        throw new RuntimeException("Exception while encoding topology of " + root.getTaskId(), e);
      }
    }
docs: Recursively encode TaskNodes of a Topology into a byte array.
  
  @param root the root node of the subtree to encode
  @return encoded byte array