lib/protocol/protocol.js
function decodeMemberAssignment (assignmentBytes) {
  var assignment = {
    partitions: {}
  };

  Binary.parse(assignmentBytes)
    .word16bs('version')
    .tap(function (vars) {
      assignment.version = vars.version;
    })
    .word32bs('partitionAssignment')
    .loop(function (end, vars) {
      if (vars.partitionAssignment-- === 0) return end();

      var topic;
      var partitions = [];

      this.word16bs('topic')
        .tap(function (vars) {
          this.buffer('topic', vars.topic);
          topic = vars.topic.toString();
        })
        .word32bs('partitionsNum')
        .loop(function (end, vars) {
          if (vars.partitionsNum-- === 0) return end();
          this.word32bs('partition').tap(function (vars) {
            partitions.push(vars.partition);
          });
        });
      assignment.partitions[topic] = partitions;
    })
    .word32bs('userData')
    .tap(function (vars) {
      if (vars.userData == null || vars.userData === -1) {
        return;
      }
      this.buffer('userData', vars.userData);
      try {
        assignment.userData = JSON.parse(vars.userData.toString());
      } catch (e) {
        assignment.userData = 'JSON Parse error';
      }
    });

  return assignment;
}
function decodeMemberAssignment (assignmentBytes) {
  var assignment = {
    partitions: {}
  };

  Binary.parse(assignmentBytes)
    .word16bs('version')
    .tap(function (vars) {
      assignment.version = vars.version;
    })
    .word32bs('partitionAssignment')
    .loop(function (end, vars) {
      if (vars.partitionAssignment-- === 0) return end();

      var topic;
      var partitions = [];

      this.word16bs('topic')
        .tap(function (vars) {
          this.buffer('topic', vars.topic);
          topic = vars.topic.toString();
        })
        .word32bs('partitionsNum')
        .loop(function (end, vars) {
          if (vars.partitionsNum-- === 0) return end();
          this.word32bs('partition').tap(function (vars) {
            partitions.push(vars.partition);
          });
        });
      assignment.partitions[topic] = partitions;
    })
    .word32bs('userData')
    .tap(function (vars) {
      if (vars.userData == null || vars.userData === -1) {
        return;
      }
      this.buffer('userData', vars.userData);
      try {
        assignment.userData = JSON.parse(vars.userData.toString());
      } catch (e) {
        assignment.userData = 'JSON Parse error';
      }
    });

  return assignment;
}
function decodeMemberAssignment ( assignmentBytes ) { var assignment = { partitions : { } } ; Binary . parse ( assignmentBytes ) . word16bs ( 'version' ) . tap ( function ( vars ) { assignment . version = vars . version ; } ) . word32bs ( 'partitionAssignment' ) . loop ( function ( end , vars ) { if ( vars . partitionAssignment -- === 0 ) return end ( ) ; var topic ; var partitions = [ ] ; this . word16bs ( 'topic' ) . tap ( function ( vars ) { this . buffer ( 'topic' , vars . topic ) ; topic = vars . topic . toString ( ) ; } ) . word32bs ( 'partitionsNum' ) . loop ( function ( end , vars ) { if ( vars . partitionsNum -- === 0 ) return end ( ) ; this . word32bs ( 'partition' ) . tap ( function ( vars ) { partitions . push ( vars . partition ) ; } ) ; } ) ; assignment . partitions [ topic ] = partitions ; } ) . word32bs ( 'userData' ) . tap ( function ( vars ) { if ( vars . userData == null || vars . userData === - 1 ) { return ; } this . buffer ( 'userData' , vars . userData ) ; try { assignment . userData = JSON . parse ( vars . userData . toString ( ) ) ; } catch ( e ) { assignment . userData = 'JSON Parse error' ; } } ) ; return assignment ; }
/*
MemberAssignment => Version PartitionAssignment
Version => int16
PartitionAssignment => [Topic [Partition]]
Topic => string
Partition => int32
UserData => bytes
/ * MemberAssignment = > Version PartitionAssignment Version = > int16 PartitionAssignment = > [ Topic [ Partition ]] Topic = > string Partition = > int32 UserData = > bytes