{"size": 1921, "ext": "js", "max_stars_repo_path": "lib/message/request/joinGroup.js", "max_stars_repo_name": "apparatus/Kafkaesque", "max_stars_repo_stars_event_min_datetime": "2016-08-01T21:37:41.000Z", "max_stars_repo_stars_event_max_datetime": "2020-03-03T18:15:41.000Z", "max_issues_repo_path": "lib/message/request/joinGroup.js", "max_issues_repo_name": "apparatus/Kafkaesque", "max_issues_repo_issues_event_min_datetime": "2016-08-02T05:30:31.000Z", "max_issues_repo_issues_event_max_datetime": "2017-10-23T09:13:07.000Z", "max_forks_repo_path": "lib/message/request/joinGroup.js", "max_forks_repo_name": "pelger/Kafkaesque", "max_forks_repo_forks_event_min_datetime": "2015-02-09T15:52:48.000Z", "max_forks_repo_forks_event_max_datetime": "2016-06-01T11:16:07.000Z"}
{"max_stars_count": 20, "max_issues_count": 16, "max_forks_count": 8, "avg_line_length": 25.9594594595, "max_line_length": 80, "alphanum_fraction": 0.7303487767}
/*
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

'use strict';

var common = require('./common');
var BufferBuilder = require('buffer-builder');
var crc32 = require('buffer-crc32');


var sessionTimeout = function (timeInMs) {
  this.buf.appendUInt32BE(timeInMs);

  return this;
}


var member = function (memberId) {
  common.appendString(this.buf, memberId);

  return this;
}


var subscription = function (topics) {
  //protocoltype
  common.appendString(this.buf, 'consumer');

  //length of the group protocols array
  this.buf.appendUInt32BE(0x00000001)

  common.appendString(this.buf, 'range');

  // metadata
  var bytes = new BufferBuilder();
  bytes.appendUInt16BE(0x0000); // version

  bytes.appendUInt32BE(topics.length);
  topics.forEach(function (topic) {
    common.appendString(bytes, topic);
  });

  // userdata bytes
  bytes.appendUInt32BE(0);
  // we could actually put some json in the userdata bytes section using this...

  this.buf.appendUInt32BE(bytes.length)
  this.buf.appendBuffer(bytes);

  return this;
}


exports.encode = function() {
  var ret = common.encode(common.JOINGROUP_API);

  ret.sessionTimeout = sessionTimeout;
  ret.member = member;
  ret.subscription = subscription;

  return ret;
};
