/** {@inheritDoc} */
 @Override
 public long inLongOutLong(int type, long val) throws Exception {
   try {
     return target.processInLongOutLong(type, val);
   } catch (Exception e) {
     throw target.convertException(e);
   }
 }
 /** {@inheritDoc} */
 @Override
 public Object outObject(int type) throws Exception {
   try {
     return wrapProxy(target.processOutObject(type));
   } catch (Exception e) {
     throw target.convertException(e);
   }
 }
  /** {@inheritDoc} */
  @Override
  public Object inStreamOutObject(int type, long memPtr) throws Exception {
    try (PlatformMemory mem = memPtr != 0 ? platformCtx.memory().get(memPtr) : null) {
      BinaryRawReaderEx reader = mem != null ? platformCtx.reader(mem) : null;

      return wrapProxy(target.processInStreamOutObject(type, reader));
    } catch (Exception e) {
      throw target.convertException(e);
    }
  }
  /** {@inheritDoc} */
  @Override
  public long inStreamOutLong(int type, long memPtr) throws Exception {
    try (PlatformMemory mem = platformCtx.memory().get(memPtr)) {
      BinaryRawReaderEx reader = platformCtx.reader(mem);

      return target.processInStreamOutLong(type, reader, mem);
    } catch (Exception e) {
      throw target.convertException(e);
    }
  }
  /** {@inheritDoc} */
  @Override
  public void outStream(int type, long memPtr) throws Exception {
    try (PlatformMemory mem = platformCtx.memory().get(memPtr)) {
      PlatformOutputStream out = mem.output();

      BinaryRawWriterEx writer = platformCtx.writer(out);

      target.processOutStream(type, writer);

      out.synchronize();
    } catch (Exception e) {
      throw target.convertException(e);
    }
  }
  /** {@inheritDoc} */
  @Override
  public void inStreamOutStream(int type, long inMemPtr, long outMemPtr) throws Exception {
    try (PlatformMemory inMem = platformCtx.memory().get(inMemPtr)) {
      BinaryRawReaderEx reader = platformCtx.reader(inMem);

      try (PlatformMemory outMem = platformCtx.memory().get(outMemPtr)) {
        PlatformOutputStream out = outMem.output();

        BinaryRawWriterEx writer = platformCtx.writer(out);

        target.processInStreamOutStream(type, reader, writer);

        out.synchronize();
      }
    } catch (Exception e) {
      throw target.convertException(e);
    }
  }
  /** {@inheritDoc} */
  @Override
  public Object inObjectStreamOutObjectStream(int type, Object arg, long inMemPtr, long outMemPtr)
      throws Exception {
    PlatformMemory inMem = null;
    PlatformMemory outMem = null;

    try {
      BinaryRawReaderEx reader = null;

      if (inMemPtr != 0) {
        inMem = platformCtx.memory().get(inMemPtr);

        reader = platformCtx.reader(inMem);
      }

      PlatformOutputStream out = null;
      BinaryRawWriterEx writer = null;

      if (outMemPtr != 0) {
        outMem = platformCtx.memory().get(outMemPtr);

        out = outMem.output();

        writer = platformCtx.writer(out);
      }

      PlatformTarget res =
          target.processInObjectStreamOutObjectStream(type, unwrapProxy(arg), reader, writer);

      if (out != null) out.synchronize();

      return wrapProxy(res);
    } catch (Exception e) {
      throw target.convertException(e);
    } finally {
      try {
        if (inMem != null) inMem.close();
      } finally {
        if (outMem != null) outMem.close();
      }
    }
  }