lib/types.js
function listBuilder(list, bufb, codec, width) {
  if (!Array.isArray(list)) {
    throw new errors.EncodingError(list, 'Unsure how to encode non-array as list');
  }

  if (!width && list.length === 0) {
    bufb.appendUInt8(0x45);
    return;
  }

  // Encode all elements into a temp buffer to allow us to front-load appropriate size and count.
  var tempBuilder = new Builder();
  var _len = list.length;
  for (var _i = 0; _i < _len; ++_i) codec.encode(list[_i], tempBuilder);
  var tempBuffer = tempBuilder.get();

  // Code, size, length, data
  if (width === 1 || (tempBuffer.length < 0xFF && list.length < 0xFF && width !== 4)) {
    // list8
    if (!width) bufb.appendUInt8(0xC0);
    bufb.appendUInt8(tempBuffer.length + 1);
    bufb.appendUInt8(list.length);
  } else {
    // list32
    if (!width) bufb.appendUInt8(0xD0);
    bufb.appendUInt32BE(tempBuffer.length + 4);
    bufb.appendUInt32BE(list.length);
  }

  bufb.appendBuffer(tempBuffer);
}
function listBuilder(list, bufb, codec, width) {
  if (!Array.isArray(list)) {
    throw new errors.EncodingError(list, 'Unsure how to encode non-array as list');
  }

  if (!width && list.length === 0) {
    bufb.appendUInt8(0x45);
    return;
  }

  // Encode all elements into a temp buffer to allow us to front-load appropriate size and count.
  var tempBuilder = new Builder();
  var _len = list.length;
  for (var _i = 0; _i < _len; ++_i) codec.encode(list[_i], tempBuilder);
  var tempBuffer = tempBuilder.get();

  // Code, size, length, data
  if (width === 1 || (tempBuffer.length < 0xFF && list.length < 0xFF && width !== 4)) {
    // list8
    if (!width) bufb.appendUInt8(0xC0);
    bufb.appendUInt8(tempBuffer.length + 1);
    bufb.appendUInt8(list.length);
  } else {
    // list32
    if (!width) bufb.appendUInt8(0xD0);
    bufb.appendUInt32BE(tempBuffer.length + 4);
    bufb.appendUInt32BE(list.length);
  }

  bufb.appendBuffer(tempBuffer);
}
function listBuilder ( list , bufb , codec , width ) { if ( ! Array . isArray ( list ) ) { throw new errors . EncodingError ( list , 'Unsure how to encode non-array as list' ) ; } if ( ! width && list . length === 0 ) { bufb . appendUInt8 ( 0x45 ) ; return ; } // Encode all elements into a temp buffer to allow us to front-load appropriate size and count. var tempBuilder = new Builder ( ) ; var _len = list . length ; for ( var _i = 0 ; _i < _len ; ++ _i ) codec . encode ( list [ _i ] , tempBuilder ) ; var tempBuffer = tempBuilder . get ( ) ; // Code, size, length, data if ( width === 1 || ( tempBuffer . length < 0xFF && list . length < 0xFF && width !== 4 ) ) { // list8 if ( ! width ) bufb . appendUInt8 ( 0xC0 ) ; bufb . appendUInt8 ( tempBuffer . length + 1 ) ; bufb . appendUInt8 ( list . length ) ; } else { // list32 if ( ! width ) bufb . appendUInt8 ( 0xD0 ) ; bufb . appendUInt32BE ( tempBuffer . length + 4 ) ; bufb . appendUInt32BE ( list . length ) ; } bufb . appendBuffer ( tempBuffer ) ; }
Decoder methods decode an incoming buffer into an appropriate concrete JS entity.

@function decoder
@param {Buffer} buf          Buffer to decode, stripped of prefix code (e.g. 0xA1 0x03 'foo' would
have the 0xA1 stripped)
@param {Codec} [codec]       If needed, the codec to decode sub-values for composite types.
@return                      Decoded value
 
Encoder for list types, specified in AMQP 1.0 as:

<pre>
+----------= count items =----------+
|                                   |
n OCTETs   n OCTETs |                                   |
+----------+----------+--------------+------------+-------+
|   size   |  count   |      ...    /|    item    |\ ...  |
+----------+----------+------------/ +------------+ \-----+
/ /              \ \
/ /                \ \
/ /                  \ \
+-------------+----------+
| constructor |   data   |
+-------------+----------+

Subcategory     n
=================
0xC             1
0xD             4
</pre>

@param {Array} val           Value to encode.
@param {Builder} bufb        Buffer-encoder to write encoded list into.
@param {Codec} codec         Codec to use for encoding list entries.
@param {Number} [width]      Should be 1 or 4.  If given, encoder assumes code already written,
and will ensure array is encoded to the given byte-width type. Useful for arrays.
@private
Decoder methods decode an incoming buffer into an appropriate concrete JS entity .