lib/protocol/protocol.js
function NativeProtocol(protocolVersion) {

  var _protocolVersion = protocolVersion || DEFAULT_PROTOCOL_VERSION;

  if (!(this instanceof NativeProtocol))
    return new NativeProtocol();

  stream.Duplex.call(this);

  Object.defineProperties(this, {
    'protocolVersion': {
      set: function(val) {
        if (typeof val !== 'number' || val < 1 || val > DEFAULT_PROTOCOL_VERSION) {
          throw new Error('Invalid protocol version is set: ' + val);
        }
        _protocolVersion = val;
      },
      get: function() { return _protocolVersion; }
    }
  });
  this._messageQueue = [];
  this._readBuf = new Buffer(8); // for header
  this.lastRead = 0;
}
function NativeProtocol(protocolVersion) {

  var _protocolVersion = protocolVersion || DEFAULT_PROTOCOL_VERSION;

  if (!(this instanceof NativeProtocol))
    return new NativeProtocol();

  stream.Duplex.call(this);

  Object.defineProperties(this, {
    'protocolVersion': {
      set: function(val) {
        if (typeof val !== 'number' || val < 1 || val > DEFAULT_PROTOCOL_VERSION) {
          throw new Error('Invalid protocol version is set: ' + val);
        }
        _protocolVersion = val;
      },
      get: function() { return _protocolVersion; }
    }
  });
  this._messageQueue = [];
  this._readBuf = new Buffer(8); // for header
  this.lastRead = 0;
}
function NativeProtocol ( protocolVersion ) { var _protocolVersion = protocolVersion || DEFAULT_PROTOCOL_VERSION ; if ( ! ( this instanceof NativeProtocol ) ) return new NativeProtocol ( ) ; stream . Duplex . call ( this ) ; Object . defineProperties ( this , { 'protocolVersion' : { set : function ( val ) { if ( typeof val !== 'number' || val < 1 || val > DEFAULT_PROTOCOL_VERSION ) { throw new Error ( 'Invalid protocol version is set: ' + val ) ; } _protocolVersion = val ; } , get : function ( ) { return _protocolVersion ; } } } ) ; this . _messageQueue = [ ] ; this . _readBuf = new Buffer ( 8 ) ; // for header this . lastRead = 0 ; }
NativeProtocol class.

Protocol is implemented as node.js' stream.Duplex, so piping with
socket like:

<code>
var conn = net.connect(..);
conn.pipe(protocol).pipe(conn);
</code>

to hook up to network connection.

@constructor
@param {object} options - options to configure protocol
NativeProtocol class .