parse(input) {
    asserts.assert(
        input instanceof Array || input instanceof ArrayBuffer ||
        input instanceof Uint8Array);

    var parser = this;
    var inputBytes;
    var pos = 0;

    if (input instanceof Uint8Array || input instanceof Array) {
      inputBytes = input;
    } else {
      inputBytes = new Uint8Array(input);
    }

    while (pos < inputBytes.length) {
      switch (parser.state_) {
        case Parser.State_.INVALID: {
          parser.error_(inputBytes, pos, 'stream already broken');
          break;
        }
        case Parser.State_.INIT: {
          processFrameByte(inputBytes[pos]);
          break;
        }
        case Parser.State_.LENGTH: {
          processLengthByte(inputBytes[pos]);
          break;
        }
        case Parser.State_.MESSAGE: {
          processMessageByte(inputBytes[pos]);
          break;
        }
        default: {
          throw new Error('unexpected parser state: ' + parser.state_);
        }
      }

      parser.streamPos_++;
      pos++;
    }

    var msgs = parser.result_;
    parser.result_ = [];
    return msgs.length > 0 ? msgs : null;

    /**
     * @param {number} b A frame byte to process
     */
    function processFrameByte(b) {
      if (b == FrameType.DATA) {
        parser.frame_ = b;
      } else if (b == FrameType.TRAILER) {
        parser.frame_ = b;
      } else {
        parser.error_(inputBytes, pos, 'invalid frame byte');
      }

      parser.state_ = Parser.State_.LENGTH;
      parser.length_ = 0;
      parser.countLengthBytes_ = 0;
    }

    /**
     * @param {number} b A length byte to process
     */
    function processLengthByte(b) {
      parser.countLengthBytes_++;
      parser.length_ = (parser.length_ << 8) + b;

      if (parser.countLengthBytes_ == 4) {  // no more length byte
        parser.state_ = Parser.State_.MESSAGE;
        parser.countMessageBytes_ = 0;
        if (typeof Uint8Array !== 'undefined') {
          parser.messageBuffer_ = new Uint8Array(parser.length_);
        } else {
          parser.messageBuffer_ = new Array(parser.length_);
        }

        if (parser.length_ == 0) {  // empty message
          finishMessage();
        }
      }
    }

    /**
     * @param {number} b A message byte to process
     */
    function processMessageByte(b) {
      parser.messageBuffer_[parser.countMessageBytes_++] = b;
      if (parser.countMessageBytes_ == parser.length_) {
        finishMessage();
      }
    }

    /**
     * Finishes up building the current message and resets parser state
     */
    function finishMessage() {
      var message = {};
      message[parser.frame_] = parser.messageBuffer_;
      parser.result_.push(message);
      parser.state_ = Parser.State_.INIT;
    }
  }
Parse the new input.

Note that there is no Parser state to indicate the end of a stream.

@param {string|!ArrayBuffer|!Uint8Array|!Array<number>} input The input
    data
@throws {!Error} Throws an error message if the input is invalid.
@return {?Array<string|!Object>} any parsed objects (atomic messages)
   in an array, or null if more data needs be read to parse any new object.
@override