lib/tmspReader.js
function Request(reqBytes){
  var parsed;
  var err

  try {
    parsed = types.Request.decode(reqBytes);
  } catch (e) {
    err = e;
  }


  //Check for request errors here
  if(err){
    this.BadRequest = true;
    this.errCode = types.CodeType.EncodingError;
    this.errMsg = "The request failed to be decoded"
  } else if(!types.methodLookup[parsed.type]){
    //Request type not recognized
    //Make a request object for the error
    this.BadRequest = true;
    this.errCode = types.CodeType.UnknownRequest;
    this.errMsg = "The request type was not understood"
  } else {

    this.BadRequest = false; 
    this.type = parsed.type;
    this.method = types.methodLookup[this.type];
    this.data = parsed.data.buffer.slice(parsed.data.offset);
    this.dataLength = parsed.data.limit - parsed.data.offset;
    this.dataLittle = parsed.data.littleEndian;
    this.key = parsed.key;
    this.value = parsed.value;
  }
}
function Request(reqBytes){
  var parsed;
  var err

  try {
    parsed = types.Request.decode(reqBytes);
  } catch (e) {
    err = e;
  }


  //Check for request errors here
  if(err){
    this.BadRequest = true;
    this.errCode = types.CodeType.EncodingError;
    this.errMsg = "The request failed to be decoded"
  } else if(!types.methodLookup[parsed.type]){
    //Request type not recognized
    //Make a request object for the error
    this.BadRequest = true;
    this.errCode = types.CodeType.UnknownRequest;
    this.errMsg = "The request type was not understood"
  } else {

    this.BadRequest = false; 
    this.type = parsed.type;
    this.method = types.methodLookup[this.type];
    this.data = parsed.data.buffer.slice(parsed.data.offset);
    this.dataLength = parsed.data.limit - parsed.data.offset;
    this.dataLittle = parsed.data.littleEndian;
    this.key = parsed.key;
    this.value = parsed.value;
  }
}
function Request ( reqBytes ) { var parsed ; var err try { parsed = types . Request . decode ( reqBytes ) ; } catch ( e ) { err = e ; } //Check for request errors here if ( err ) { this . BadRequest = true ; this . errCode = types . CodeType . EncodingError ; this . errMsg = "The request failed to be decoded" } else if ( ! types . methodLookup [ parsed . type ] ) { //Request type not recognized //Make a request object for the error this . BadRequest = true ; this . errCode = types . CodeType . UnknownRequest ; this . errMsg = "The request type was not understood" } else { this . BadRequest = false ; this . type = parsed . type ; this . method = types . methodLookup [ this . type ] ; this . data = parsed . data . buffer . slice ( parsed . data . offset ) ; this . dataLength = parsed . data . limit - parsed . data . offset ; this . dataLittle = parsed . data . littleEndian ; this . key = parsed . key ; this . value = parsed . value ; } }
The Request object unlike in http requests is static So this stream is built to return it rather then the standard buffer. this means any consumer of this stream would need to take account of this fact
The Request object unlike in http requests is static So this stream is built to return it rather then the standard buffer . this means any consumer of this stream would need to take account of this fact