lazydeserializer.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // Copyright 2009 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 Base class for all PB2 lazy deserializer. A lazy deserializer
  16. * is a serializer whose deserialization occurs on the fly as data is
  17. * requested. In order to use a lazy deserializer, the serialized form
  18. * of the data must be an object or array that can be indexed by the tag
  19. * number.
  20. *
  21. */
  22. goog.provide('goog.proto2.LazyDeserializer');
  23. goog.require('goog.asserts');
  24. goog.require('goog.proto2.Message');
  25. goog.require('goog.proto2.Serializer');
  26. /**
  27. * Base class for all lazy deserializers.
  28. *
  29. * @constructor
  30. * @extends {goog.proto2.Serializer}
  31. */
  32. goog.proto2.LazyDeserializer = function() {};
  33. goog.inherits(goog.proto2.LazyDeserializer, goog.proto2.Serializer);
  34. /** @override */
  35. goog.proto2.LazyDeserializer.prototype.deserialize = function(
  36. descriptor, data) {
  37. var message = descriptor.createMessageInstance();
  38. message.initializeForLazyDeserializer(this, data);
  39. goog.asserts.assert(message instanceof goog.proto2.Message);
  40. return message;
  41. };
  42. /** @override */
  43. goog.proto2.LazyDeserializer.prototype.deserializeTo = function(message, data) {
  44. throw new Error('Unimplemented');
  45. };
  46. /**
  47. * Deserializes a message field from the expected format and places the
  48. * data in the given message
  49. *
  50. * @param {goog.proto2.Message} message The message in which to
  51. * place the information.
  52. * @param {goog.proto2.FieldDescriptor} field The field for which to set the
  53. * message value.
  54. * @param {*} data The serialized data for the field.
  55. *
  56. * @return {*} The deserialized data or null for no value found.
  57. */
  58. goog.proto2.LazyDeserializer.prototype.deserializeField = goog.abstractMethod;