lib/marshal/index.js
function compositeSerializer(serializers){
  return function(vals, sliceStart){
    var i = 0, buffers = [], totalLength = 0,
        valLength = vals.length, val;

    if(!Array.isArray(vals)){
      vals = [vals];
      valLength = vals.length;
    }

    for(; i < valLength; i += 1){
      if (Array.isArray(vals[i])){
        val = [serializers[i](vals[i][0]), vals[i][1]];
        totalLength += val[0].length + 3;
      } else {
        val = serializers[i](vals[i]);
        totalLength += val.length + 3;
      }

      buffers.push(val);
    }

    var buf = new Buffer(totalLength),
        buffersLength = buffers.length,
        writtenLength = 0, eoc, inclusive;

    i = 0;
    for(; i < buffersLength; i += 1){
      val = buffers[i];
      eoc = new Buffer('00', 'hex');
      inclusive = true;

      if (Array.isArray(val)){
        inclusive = val[1];
        val = val[0];
        if(inclusive){
          if (sliceStart){
            eoc = new Buffer('ff', 'hex');
          } else if (sliceStart === false){
            eoc = new Buffer('01', 'hex');
          }
        } else {
          if (sliceStart){
            eoc = new Buffer('01', 'hex');
          } else if (sliceStart === false){
            eoc = new Buffer('ff', 'hex');
          }
        }
      } else if (i === buffersLength - 1){
      if (sliceStart){
          eoc = new Buffer('ff', 'hex');
        } else if (sliceStart === false){
          eoc = new Buffer('01', 'hex');
        }
      }

      buf.writeUInt16BE(val.length, writtenLength);
      writtenLength += 2;
      val.copy(buf, writtenLength, 0);
      writtenLength += val.length;
      eoc.copy(buf, writtenLength, 0);
      writtenLength += 1;
    }

    return buf;
  };
}
function compositeSerializer(serializers){
  return function(vals, sliceStart){
    var i = 0, buffers = [], totalLength = 0,
        valLength = vals.length, val;

    if(!Array.isArray(vals)){
      vals = [vals];
      valLength = vals.length;
    }

    for(; i < valLength; i += 1){
      if (Array.isArray(vals[i])){
        val = [serializers[i](vals[i][0]), vals[i][1]];
        totalLength += val[0].length + 3;
      } else {
        val = serializers[i](vals[i]);
        totalLength += val.length + 3;
      }

      buffers.push(val);
    }

    var buf = new Buffer(totalLength),
        buffersLength = buffers.length,
        writtenLength = 0, eoc, inclusive;

    i = 0;
    for(; i < buffersLength; i += 1){
      val = buffers[i];
      eoc = new Buffer('00', 'hex');
      inclusive = true;

      if (Array.isArray(val)){
        inclusive = val[1];
        val = val[0];
        if(inclusive){
          if (sliceStart){
            eoc = new Buffer('ff', 'hex');
          } else if (sliceStart === false){
            eoc = new Buffer('01', 'hex');
          }
        } else {
          if (sliceStart){
            eoc = new Buffer('01', 'hex');
          } else if (sliceStart === false){
            eoc = new Buffer('ff', 'hex');
          }
        }
      } else if (i === buffersLength - 1){
      if (sliceStart){
          eoc = new Buffer('ff', 'hex');
        } else if (sliceStart === false){
          eoc = new Buffer('01', 'hex');
        }
      }

      buf.writeUInt16BE(val.length, writtenLength);
      writtenLength += 2;
      val.copy(buf, writtenLength, 0);
      writtenLength += val.length;
      eoc.copy(buf, writtenLength, 0);
      writtenLength += 1;
    }

    return buf;
  };
}
function compositeSerializer ( serializers ) { return function ( vals , sliceStart ) { var i = 0 , buffers = [ ] , totalLength = 0 , valLength = vals . length , val ; if ( ! Array . isArray ( vals ) ) { vals = [ vals ] ; valLength = vals . length ; } for ( ; i < valLength ; i += 1 ) { if ( Array . isArray ( vals [ i ] ) ) { val = [ serializers [ i ] ( vals [ i ] [ 0 ] ) , vals [ i ] [ 1 ] ] ; totalLength += val [ 0 ] . length + 3 ; } else { val = serializers [ i ] ( vals [ i ] ) ; totalLength += val . length + 3 ; } buffers . push ( val ) ; } var buf = new Buffer ( totalLength ) , buffersLength = buffers . length , writtenLength = 0 , eoc , inclusive ; i = 0 ; for ( ; i < buffersLength ; i += 1 ) { val = buffers [ i ] ; eoc = new Buffer ( '00' , 'hex' ) ; inclusive = true ; if ( Array . isArray ( val ) ) { inclusive = val [ 1 ] ; val = val [ 0 ] ; if ( inclusive ) { if ( sliceStart ) { eoc = new Buffer ( 'ff' , 'hex' ) ; } else if ( sliceStart === false ) { eoc = new Buffer ( '01' , 'hex' ) ; } } else { if ( sliceStart ) { eoc = new Buffer ( '01' , 'hex' ) ; } else if ( sliceStart === false ) { eoc = new Buffer ( 'ff' , 'hex' ) ; } } } else if ( i === buffersLength - 1 ) { if ( sliceStart ) { eoc = new Buffer ( 'ff' , 'hex' ) ; } else if ( sliceStart === false ) { eoc = new Buffer ( '01' , 'hex' ) ; } } buf . writeUInt16BE ( val . length , writtenLength ) ; writtenLength += 2 ; val . copy ( buf , writtenLength , 0 ) ; writtenLength += val . length ; eoc . copy ( buf , writtenLength , 0 ) ; writtenLength += 1 ; } return buf ; } ; }
Creates a serializer for composite types
@private
@memberOf Marshal
Creates a serializer for composite types