B2G/gecko/dom/system/gonk/tests/header_helpers.js
/**
 * Create a parcel suitable for postRILMessage().
 *
 * @param fakeParcelSize
 *        Value to be written to parcel size field for testing
 *        incorrect/incomplete parcel reading. Replaced with correct
 *        one determined length of data if negative.
 * @param response
 *        Response code of the incoming parcel.
 * @param request
 *        Request code of the incoming parcel.
 * @param data
 *        Extra data to be appended.
 *
 * @return an Uint8Array carrying all parcel data.
 */
Create a parcel suitable for postRILMessage().
@param fakeParcelSize
Value to be written to parcel size field for testing
incorrect/incomplete parcel reading. Replaced with correct
one determined length of data if negative.
@param response
Response code of the incoming parcel.
@param request
Request code of the incoming parcel.
@param data
Extra data to be appended.

@return an Uint8Array carrying all parcel data.
Create a parcel suitable for postRILMessage () . @param fakeParcelSize Value to be written to parcel size field for testing incorrect / incomplete parcel reading . Replaced with correct one determined length of data if negative . @param response Response code of the incoming parcel . @param request Request code of the incoming parcel . @param data Extra data to be appended . @return an Uint8Array carrying all parcel data .
function newIncomingParcel(fakeParcelSize, response, request, data) {
  const UINT32_SIZE = 4;
  const PARCEL_SIZE_SIZE = 4;
  let realParcelSize = data.length + 2 * UINT32_SIZE;
  let buffer = new ArrayBuffer(realParcelSize + PARCEL_SIZE_SIZE);
  let bytes = new Uint8Array(buffer);
  let writeIndex = 0;
  function writeUint8(value) {
    bytes[writeIndex] = value;
    ++writeIndex;
  }
  function writeUint32(value) {
    writeUint8(value & 0xff);
    writeUint8((value >> 8) & 0xff);
    writeUint8((value >> 16) & 0xff);
    writeUint8((value >> 24) & 0xff);
  }
  function writeParcelSize(value) {
    writeUint8((value >> 24) & 0xff);
    writeUint8((value >> 16) & 0xff);
    writeUint8((value >> 8) & 0xff);
    writeUint8(value & 0xff);
  }
  if (fakeParcelSize < 0) {
    fakeParcelSize = realParcelSize;
  }
  writeParcelSize(fakeParcelSize);
  writeUint32(response);
  writeUint32(request);
  for (let ii = 0; ii < data.length; ++ii) {
    writeUint8(data[ii]);
  }
  return bytes;
}
function newIncomingParcel ( fakeParcelSize , response , request , data ) { const UINT32_SIZE = 4 ; const PARCEL_SIZE_SIZE = 4 ; let realParcelSize = data . length + 2 * UINT32_SIZE ; let buffer = new ArrayBuffer ( realParcelSize + PARCEL_SIZE_SIZE ) ; let bytes = new Uint8Array ( buffer ) ; let writeIndex = 0 ; function writeUint8 ( value ) { bytes [ writeIndex ] = value ; ++ writeIndex ; } function writeUint32 ( value ) { writeUint8 ( value & 0xff ) ; writeUint8 ( ( value >> 8 ) & 0xff ) ; writeUint8 ( ( value >> 16 ) & 0xff ) ; writeUint8 ( ( value >> 24 ) & 0xff ) ; } function writeParcelSize ( value ) { writeUint8 ( ( value >> 24 ) & 0xff ) ; writeUint8 ( ( value >> 16 ) & 0xff ) ; writeUint8 ( ( value >> 8 ) & 0xff ) ; writeUint8 ( value & 0xff ) ; } if ( fakeParcelSize < 0 ) { fakeParcelSize = realParcelSize ; } writeParcelSize ( fakeParcelSize ) ; writeUint32 ( response ) ; writeUint32 ( request ) ; for ( let ii = 0 ; ii < data . length ; ++ ii ) { writeUint8 ( data [ ii ] ) ; } return bytes ; }
Create a parcel suitable for postRILMessage().
Create a parcel suitable for postRILMessage () .
// write parcel data