Adding mapbox-gl branch
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
// Copyright 2007 The Closure Library Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS-IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
/**
|
||||
* @fileoverview Protocol buffer serializer.
|
||||
* @author arv@google.com (Erik Arvidsson)
|
||||
*/
|
||||
|
||||
goog.provide('goog.proto');
|
||||
|
||||
|
||||
goog.require('goog.proto.Serializer');
|
||||
|
||||
|
||||
/**
|
||||
* Instance of the serializer object.
|
||||
* @type {goog.proto.Serializer}
|
||||
* @private
|
||||
*/
|
||||
goog.proto.serializer_ = null;
|
||||
|
||||
|
||||
/**
|
||||
* Serializes an object or a value to a protocol buffer string.
|
||||
* @param {Object} object The object to serialize.
|
||||
* @return {string} The serialized protocol buffer string.
|
||||
*/
|
||||
goog.proto.serialize = function(object) {
|
||||
if (!goog.proto.serializer_) {
|
||||
goog.proto.serializer_ = new goog.proto.Serializer;
|
||||
}
|
||||
return goog.proto.serializer_.serialize(object);
|
||||
};
|
||||
@@ -0,0 +1,70 @@
|
||||
// Copyright 2007 The Closure Library Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS-IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
/**
|
||||
* @fileoverview Protocol buffer serializer.
|
||||
* @author arv@google.com (Erik Arvidsson)
|
||||
*/
|
||||
|
||||
|
||||
// TODO(arv): Serialize booleans as 0 and 1
|
||||
|
||||
|
||||
goog.provide('goog.proto.Serializer');
|
||||
|
||||
|
||||
goog.require('goog.json.Serializer');
|
||||
goog.require('goog.string');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Object that can serialize objects or values to a protocol buffer string.
|
||||
* @constructor
|
||||
* @extends {goog.json.Serializer}
|
||||
* @final
|
||||
*/
|
||||
goog.proto.Serializer = function() {
|
||||
goog.json.Serializer.call(this);
|
||||
};
|
||||
goog.inherits(goog.proto.Serializer, goog.json.Serializer);
|
||||
|
||||
|
||||
/**
|
||||
* Serializes an array to a protocol buffer string. This overrides the JSON
|
||||
* method to output empty slots when the value is null or undefined.
|
||||
* @param {Array<*>} arr The array to serialize.
|
||||
* @param {Array<string>} sb Array used as a string builder.
|
||||
* @override
|
||||
*/
|
||||
goog.proto.Serializer.prototype.serializeArray = function(arr, sb) {
|
||||
var l = arr.length;
|
||||
sb.push('[');
|
||||
var emptySlots = 0;
|
||||
var sep = '';
|
||||
for (var i = 0; i < l; i++) {
|
||||
if (arr[i] == null) { // catches undefined as well
|
||||
emptySlots++;
|
||||
} else {
|
||||
if (emptySlots > 0) {
|
||||
sb.push(goog.string.repeat(',', emptySlots));
|
||||
emptySlots = 0;
|
||||
}
|
||||
sb.push(sep);
|
||||
this.serializeInternal(arr[i], sb);
|
||||
sep = ',';
|
||||
}
|
||||
}
|
||||
sb.push(']');
|
||||
};
|
||||
@@ -0,0 +1,22 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<!--
|
||||
Copyright 2007 The Closure Library Authors. All Rights Reserved.
|
||||
|
||||
Use of this source code is governed by the Apache License, Version 2.0.
|
||||
See the COPYING file for details.
|
||||
-->
|
||||
<head>
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||||
<title>
|
||||
Closure Unit Tests - goog.proto
|
||||
</title>
|
||||
<script src="../base.js">
|
||||
</script>
|
||||
<script>
|
||||
goog.require('goog.protoTest');
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,38 @@
|
||||
// Copyright 2007 The Closure Library Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS-IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
goog.provide('goog.protoTest');
|
||||
goog.setTestOnly('goog.protoTest');
|
||||
|
||||
goog.require('goog.proto');
|
||||
goog.require('goog.testing.jsunit');
|
||||
|
||||
var serialize = goog.proto.serialize;
|
||||
|
||||
function testArraySerialize() {
|
||||
|
||||
assertEquals('Empty array', serialize([]), '[]');
|
||||
|
||||
assertEquals('Normal array', serialize([0, 1, 2]), '[0,1,2]');
|
||||
assertEquals('Empty start', serialize([, 1, 2]), '[,1,2]');
|
||||
assertEquals('Empty start', serialize([,,, 3, 4]), '[,,,3,4]');
|
||||
assertEquals('Empty middle', serialize([0,, 2]), '[0,,2]');
|
||||
assertEquals('Empty middle', serialize([0,,, 3]), '[0,,,3]');
|
||||
assertEquals('Empty end', serialize([0, 1, 2]), '[0,1,2]');
|
||||
assertEquals('Empty end', serialize([0, 1, 2,,]), '[0,1,2]');
|
||||
assertEquals('Empty start and end', serialize([,, 2,, 4]), '[,,2,,4]');
|
||||
assertEquals('All elements empty', serialize([,,,]), '[]');
|
||||
|
||||
assertEquals('Nested', serialize([, 1, [, 1, [, 1]]]), '[,1,[,1,[,1]]]');
|
||||
}
|
||||
Reference in New Issue
Block a user