Path: blob/trunk/third_party/closure/goog/proto2/lazydeserializer.js
2868 views
// Copyright 2009 The Closure Library Authors. All Rights Reserved.1//2// Licensed under the Apache License, Version 2.0 (the "License");3// you may not use this file except in compliance with the License.4// You may obtain a copy of the License at5//6// http://www.apache.org/licenses/LICENSE-2.07//8// Unless required by applicable law or agreed to in writing, software9// distributed under the License is distributed on an "AS-IS" BASIS,10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.11// See the License for the specific language governing permissions and12// limitations under the License.1314/**15* @fileoverview Base class for all PB2 lazy deserializer. A lazy deserializer16* is a serializer whose deserialization occurs on the fly as data is17* requested. In order to use a lazy deserializer, the serialized form18* of the data must be an object or array that can be indexed by the tag19* number.20*21*/2223goog.provide('goog.proto2.LazyDeserializer');2425goog.require('goog.asserts');26goog.require('goog.proto2.Message');27goog.require('goog.proto2.Serializer');28293031/**32* Base class for all lazy deserializers.33*34* @constructor35* @extends {goog.proto2.Serializer}36*/37goog.proto2.LazyDeserializer = function() {};38goog.inherits(goog.proto2.LazyDeserializer, goog.proto2.Serializer);394041/** @override */42goog.proto2.LazyDeserializer.prototype.deserialize = function(43descriptor, data) {44var message = descriptor.createMessageInstance();45message.initializeForLazyDeserializer(this, data);46goog.asserts.assert(message instanceof goog.proto2.Message);47return message;48};495051/** @override */52goog.proto2.LazyDeserializer.prototype.deserializeTo = function(message, data) {53throw new Error('Unimplemented');54};555657/**58* Deserializes a message field from the expected format and places the59* data in the given message60*61* @param {goog.proto2.Message} message The message in which to62* place the information.63* @param {goog.proto2.FieldDescriptor} field The field for which to set the64* message value.65* @param {*} data The serialized data for the field.66*67* @return {*} The deserialized data or null for no value found.68*/69goog.proto2.LazyDeserializer.prototype.deserializeField = goog.abstractMethod;707172