streamparser.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // Copyright 2015 The Closure Library Authors. All Rights Reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS-IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. /**
  15. * @fileoverview the private interface for implementing parsers responsible
  16. * for decoding the input stream (e.g. an HTTP body) to objects per their
  17. * specified content-types, e.g. JSON, Protobuf.
  18. *
  19. * A default JSON parser is provided,
  20. *
  21. * A Protobuf stream parser is also provided.
  22. */
  23. goog.provide('goog.net.streams.StreamParser');
  24. /**
  25. * This interface represents a stream parser.
  26. *
  27. * @interface
  28. * @package
  29. */
  30. goog.net.streams.StreamParser = function() {};
  31. /**
  32. * Checks if the parser is aborted due to invalid input.
  33. *
  34. * @return {boolean} true if the input is still valid.
  35. */
  36. goog.net.streams.StreamParser.prototype.isInputValid = goog.abstractMethod;
  37. /**
  38. * Checks the error message.
  39. *
  40. * @return {?string} any debug info on the first invalid input, or null if
  41. * the input is still valid.
  42. */
  43. goog.net.streams.StreamParser.prototype.getErrorMessage = goog.abstractMethod;
  44. /**
  45. * Parse the new input.
  46. *
  47. * Note that there is no Parser state to indicate the end of a stream.
  48. *
  49. * @param {string|!ArrayBuffer|!Array<number>} input The input data
  50. * @throws {!Error} if the input is invalid, and the parser will remain invalid
  51. * once an error has been thrown.
  52. * @return {?Array<string|!Object>} any parsed objects (atomic messages)
  53. * in an array, or null if more data needs be read to parse any new object.
  54. */
  55. goog.net.streams.StreamParser.prototype.parse = goog.abstractMethod;