code: @Override
    public byte[] encode(final T writable) {
      try (final ByteArrayOutputStream bos = new ByteArrayOutputStream();
           final DataOutputStream dos = new DataOutputStream(bos)) {
        writable.write(dos);
        return bos.toByteArray();
      } catch (final IOException ex) {
        LOG.log(Level.SEVERE, "Cannot encode object " + writable, ex);
        throw new RemoteRuntimeException(ex);
      }
    }
docs: Encodes Hadoop Writable object into a byte array.
  
  @param writable the object to encode.
  @return serialized object as byte array.
  @throws RemoteRuntimeException if serialization fails.