Debian Codegraph @

closure-library/closure/goog/proto2/lazydeserializer.js

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