/**
 * native-message.js
 */
"use strict";
{
  /* api */
  const {isFunction, isString} = require("./common");
  const os = require("os");

  /* constants */
  const BYTE_LEN = 4;
  const CHAR = "utf8";
  const IS_BE = os.endianness() === "BE";

  /* Input */
  class Input {
    /**
     * decode message from buffer
     */
    constructor() {
      this._input;
      this._length;
    }

    /**
     * buffer to message
     * @returns {Array} - message array
     */
    _decoder() {
      let arr = [];
      !this._length && this._input && this._input.length >= BYTE_LEN && (
        this._length = IS_BE && this._input.readUIntBE(0, BYTE_LEN) ||
                       this._input.readUIntLE(0, BYTE_LEN),
        this._input = this._input.slice(BYTE_LEN)
      );
      if (this._length && this._input && this._input.length >= this._length) {
        const buf = this._input.slice(0, this._length);
        arr.push(JSON.parse(buf.toString(CHAR)));
        this._input = this._input.length > this._length &&
                      this._input.slice(this._length) || null;
        this._length = null;
        if (this._input) {
          const cur = this._decoder();
          cur.length && (arr = arr.concat(cur));
        }
      }
      return arr;
    }

    /**
     * decode message
     * @param {string|Buffer} chunk - chunk
     * @param {Function} callback - callback
     * @returns {void}
     */
    decode(chunk, callback) {
      const buf = (isString(chunk) || Buffer.isBuffer(chunk)) &&
                    Buffer.from(chunk);
      buf &&
        (this._input = this._input && Buffer.concat([this._input, buf]) || buf);
      if (isFunction(callback)) {
        const arr = this._decoder();
        arr.length && arr.forEach(msg => msg && callback(msg));
      }
    }
  }

  /* Output */
  class Output {
    /* encode message to buffer */
    constructor() {
      this._output;
    }

    /**
     * message to buffer
     * @returns {?Buffer} - buffered message
     */
    _encoder() {
      let msg = JSON.stringify(this._output);
      if (isString(msg)) {
        const buf = Buffer.from(msg);
        const len = Buffer.alloc(BYTE_LEN);
        IS_BE && len.writeUIntBE(buf.length, 0, BYTE_LEN) ||
        len.writeUIntLE(buf.length, 0, BYTE_LEN);
        msg = Buffer.concat([len, buf]);
      }
      this._output = null;
      return Buffer.isBuffer(msg) && msg || null;
    }

    /**
     * encode message
     * @param {Object} msg - message
     * @returns {?Buffer} - buffered message
     */
    encode(msg) {
      this._output = msg;
      msg = this._encoder();
      return Buffer.isBuffer(msg) && msg || null;
    }
  }

  module.exports = {
    Input, Output,
  };
}

@@ -63,20 +63,8 @@
 st %7B
-isFunction, 
 isSt
@@ -1335,67 +1335,40 @@
  * @
-param %7BFunction%7D callback - callback%0A     * @returns %7Bvoid%7D
+returns %7B?Array%7D - message array
 %0A   
@@ -1392,18 +1392,8 @@
 hunk
-, callback
 ) %7B%0A
@@ -1497,16 +1497,36 @@
 chunk);%0A
+      let msg = %5B%5D;%0A
       bu
@@ -1621,53 +1621,61 @@
     
-if (isFunction(callback)) %7B%0A        const arr
+this._input && this._input.length %3E= BYTE_LEN && (msg
  = t
@@ -1688,24 +1688,25 @@
 ecoder()
+)
 ;%0A      
   arr.le
@@ -1697,21 +1697,26 @@
 ;%0A      
-  arr
+return msg
 .length 
@@ -1722,57 +1722,20 @@
  && 
-arr.forEach(msg =%3E msg && callback(msg));%0A      %7D
+msg %7C%7C null;
 %0A   

Add return value to Input.decode()