wildfire chat server source initial submit
This commit is contained in:
Executable
+21
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"string" : "Lorem ipsum dolor sit amet.",
|
||||
"uint32" : 9000,
|
||||
"inner" : {
|
||||
"int32" : 20161110,
|
||||
"innerInner" : {
|
||||
"long" : {
|
||||
"low": 1051,
|
||||
"high": 151234,
|
||||
"unsigned": false
|
||||
},
|
||||
"enum" : 1,
|
||||
"sint32": -42
|
||||
},
|
||||
"outer" : {
|
||||
"bool" : [ true, false, false, true, false, false, true ],
|
||||
"double": 204.8
|
||||
}
|
||||
},
|
||||
"float": 0.25
|
||||
}
|
||||
Executable
+40
@@ -0,0 +1,40 @@
|
||||
syntax = "proto3";
|
||||
|
||||
message Test {
|
||||
|
||||
string string = 1;
|
||||
uint32 uint32 = 2;
|
||||
Inner inner = 3;
|
||||
float float = 4; // make sure to set something that's fair to JSON
|
||||
|
||||
message Inner {
|
||||
|
||||
int32 int32 = 1;
|
||||
InnerInner innerInner = 2;
|
||||
Outer outer = 3;
|
||||
|
||||
message InnerInner {
|
||||
|
||||
int64 long = 1;
|
||||
Enum enum = 2;
|
||||
sint32 sint32 = 3;
|
||||
}
|
||||
}
|
||||
|
||||
enum Enum {
|
||||
|
||||
ONE = 0;
|
||||
TWO = 1;
|
||||
THREE = 2;
|
||||
FOUR = 3;
|
||||
FIVE = 4;
|
||||
}
|
||||
}
|
||||
|
||||
message Outer {
|
||||
|
||||
repeated bool bool = 1;
|
||||
double double = 2; // make sure to set something that's fair to JSON
|
||||
}
|
||||
|
||||
// bytes cannot be used
|
||||
+881
@@ -0,0 +1,881 @@
|
||||
/*eslint-disable*/
|
||||
/**
|
||||
* @fileoverview
|
||||
* @enhanceable
|
||||
* @public
|
||||
*/
|
||||
// GENERATED CODE -- DO NOT EDIT!
|
||||
|
||||
var jspb = require('google-protobuf');
|
||||
var goog = jspb;
|
||||
var global = Function('return this')();
|
||||
|
||||
goog.exportSymbol('proto.Outer', null, global);
|
||||
goog.exportSymbol('proto.Test', null, global);
|
||||
goog.exportSymbol('proto.Test.Enum', null, global);
|
||||
goog.exportSymbol('proto.Test.Inner', null, global);
|
||||
goog.exportSymbol('proto.Test.Inner.InnerInner', null, global);
|
||||
|
||||
/**
|
||||
* Generated by JsPbCodeGenerator.
|
||||
* @param {Array=} opt_data Optional initial data array, typically from a
|
||||
* server response, or constructed directly in Javascript. The array is used
|
||||
* in place and becomes part of the constructed object. It is not cloned.
|
||||
* If no data is provided, the constructed object will be empty, but still
|
||||
* valid.
|
||||
* @extends {jspb.Message}
|
||||
* @constructor
|
||||
*/
|
||||
proto.Test = function(opt_data) {
|
||||
jspb.Message.initialize(this, opt_data, 0, -1, null, null);
|
||||
};
|
||||
goog.inherits(proto.Test, jspb.Message);
|
||||
if (goog.DEBUG && !COMPILED) {
|
||||
proto.Test.displayName = 'proto.Test';
|
||||
}
|
||||
|
||||
|
||||
if (jspb.Message.GENERATE_TO_OBJECT) {
|
||||
/**
|
||||
* Creates an object representation of this proto suitable for use in Soy templates.
|
||||
* Field names that are reserved in JavaScript and will be renamed to pb_name.
|
||||
* To access a reserved field use, foo.pb_<name>, eg, foo.pb_default.
|
||||
* For the list of reserved names please see:
|
||||
* com.google.apps.jspb.JsClassTemplate.JS_RESERVED_WORDS.
|
||||
* @param {boolean=} opt_includeInstance Whether to include the JSPB instance
|
||||
* for transitional soy proto support: http://goto/soy-param-migration
|
||||
* @return {!Object}
|
||||
*/
|
||||
proto.Test.prototype.toObject = function(opt_includeInstance) {
|
||||
return proto.Test.toObject(opt_includeInstance, this);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Static version of the {@see toObject} method.
|
||||
* @param {boolean|undefined} includeInstance Whether to include the JSPB
|
||||
* instance for transitional soy proto support:
|
||||
* http://goto/soy-param-migration
|
||||
* @param {!proto.Test} msg The msg instance to transform.
|
||||
* @return {!Object}
|
||||
*/
|
||||
proto.Test.toObject = function(includeInstance, msg) {
|
||||
var f, obj = {
|
||||
string: jspb.Message.getFieldWithDefault(msg, 1, ""),
|
||||
uint32: jspb.Message.getFieldWithDefault(msg, 2, 0),
|
||||
inner: (f = msg.getInner()) && proto.Test.Inner.toObject(includeInstance, f),
|
||||
pb_float: +jspb.Message.getFieldWithDefault(msg, 4, 0.0)
|
||||
};
|
||||
|
||||
if (includeInstance) {
|
||||
obj.$jspbMessageInstance = msg;
|
||||
}
|
||||
return obj;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Deserializes binary data (in protobuf wire format).
|
||||
* @param {jspb.ByteSource} bytes The bytes to deserialize.
|
||||
* @return {!proto.Test}
|
||||
*/
|
||||
proto.Test.deserializeBinary = function(bytes) {
|
||||
var reader = new jspb.BinaryReader(bytes);
|
||||
var msg = new proto.Test;
|
||||
return proto.Test.deserializeBinaryFromReader(msg, reader);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Deserializes binary data (in protobuf wire format) from the
|
||||
* given reader into the given message object.
|
||||
* @param {!proto.Test} msg The message object to deserialize into.
|
||||
* @param {!jspb.BinaryReader} reader The BinaryReader to use.
|
||||
* @return {!proto.Test}
|
||||
*/
|
||||
proto.Test.deserializeBinaryFromReader = function(msg, reader) {
|
||||
while (reader.nextField()) {
|
||||
if (reader.isEndGroup()) {
|
||||
break;
|
||||
}
|
||||
var field = reader.getFieldNumber();
|
||||
switch (field) {
|
||||
case 1:
|
||||
var value = /** @type {string} */ (reader.readString());
|
||||
msg.setString(value);
|
||||
break;
|
||||
case 2:
|
||||
var value = /** @type {number} */ (reader.readUint32());
|
||||
msg.setUint32(value);
|
||||
break;
|
||||
case 3:
|
||||
var value = new proto.Test.Inner;
|
||||
reader.readMessage(value,proto.Test.Inner.deserializeBinaryFromReader);
|
||||
msg.setInner(value);
|
||||
break;
|
||||
case 4:
|
||||
var value = /** @type {number} */ (reader.readFloat());
|
||||
msg.setFloat(value);
|
||||
break;
|
||||
default:
|
||||
reader.skipField();
|
||||
break;
|
||||
}
|
||||
}
|
||||
return msg;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Serializes the message to binary data (in protobuf wire format).
|
||||
* @return {!Uint8Array}
|
||||
*/
|
||||
proto.Test.prototype.serializeBinary = function() {
|
||||
var writer = new jspb.BinaryWriter();
|
||||
proto.Test.serializeBinaryToWriter(this, writer);
|
||||
return writer.getResultBuffer();
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Serializes the given message to binary data (in protobuf wire
|
||||
* format), writing to the given BinaryWriter.
|
||||
* @param {!proto.Test} message
|
||||
* @param {!jspb.BinaryWriter} writer
|
||||
*/
|
||||
proto.Test.serializeBinaryToWriter = function(message, writer) {
|
||||
var f = undefined;
|
||||
f = message.getString();
|
||||
if (f.length > 0) {
|
||||
writer.writeString(
|
||||
1,
|
||||
f
|
||||
);
|
||||
}
|
||||
f = message.getUint32();
|
||||
if (f !== 0) {
|
||||
writer.writeUint32(
|
||||
2,
|
||||
f
|
||||
);
|
||||
}
|
||||
f = message.getInner();
|
||||
if (f != null) {
|
||||
writer.writeMessage(
|
||||
3,
|
||||
f,
|
||||
proto.Test.Inner.serializeBinaryToWriter
|
||||
);
|
||||
}
|
||||
f = message.getFloat();
|
||||
if (f !== 0.0) {
|
||||
writer.writeFloat(
|
||||
4,
|
||||
f
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @enum {number}
|
||||
*/
|
||||
proto.Test.Enum = {
|
||||
ONE: 0,
|
||||
TWO: 1,
|
||||
THREE: 2,
|
||||
FOUR: 3,
|
||||
FIVE: 4
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Generated by JsPbCodeGenerator.
|
||||
* @param {Array=} opt_data Optional initial data array, typically from a
|
||||
* server response, or constructed directly in Javascript. The array is used
|
||||
* in place and becomes part of the constructed object. It is not cloned.
|
||||
* If no data is provided, the constructed object will be empty, but still
|
||||
* valid.
|
||||
* @extends {jspb.Message}
|
||||
* @constructor
|
||||
*/
|
||||
proto.Test.Inner = function(opt_data) {
|
||||
jspb.Message.initialize(this, opt_data, 0, -1, null, null);
|
||||
};
|
||||
goog.inherits(proto.Test.Inner, jspb.Message);
|
||||
if (goog.DEBUG && !COMPILED) {
|
||||
proto.Test.Inner.displayName = 'proto.Test.Inner';
|
||||
}
|
||||
|
||||
|
||||
if (jspb.Message.GENERATE_TO_OBJECT) {
|
||||
/**
|
||||
* Creates an object representation of this proto suitable for use in Soy templates.
|
||||
* Field names that are reserved in JavaScript and will be renamed to pb_name.
|
||||
* To access a reserved field use, foo.pb_<name>, eg, foo.pb_default.
|
||||
* For the list of reserved names please see:
|
||||
* com.google.apps.jspb.JsClassTemplate.JS_RESERVED_WORDS.
|
||||
* @param {boolean=} opt_includeInstance Whether to include the JSPB instance
|
||||
* for transitional soy proto support: http://goto/soy-param-migration
|
||||
* @return {!Object}
|
||||
*/
|
||||
proto.Test.Inner.prototype.toObject = function(opt_includeInstance) {
|
||||
return proto.Test.Inner.toObject(opt_includeInstance, this);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Static version of the {@see toObject} method.
|
||||
* @param {boolean|undefined} includeInstance Whether to include the JSPB
|
||||
* instance for transitional soy proto support:
|
||||
* http://goto/soy-param-migration
|
||||
* @param {!proto.Test.Inner} msg The msg instance to transform.
|
||||
* @return {!Object}
|
||||
*/
|
||||
proto.Test.Inner.toObject = function(includeInstance, msg) {
|
||||
var f, obj = {
|
||||
int32: jspb.Message.getFieldWithDefault(msg, 1, 0),
|
||||
innerinner: (f = msg.getInnerinner()) && proto.Test.Inner.InnerInner.toObject(includeInstance, f),
|
||||
outer: (f = msg.getOuter()) && proto.Outer.toObject(includeInstance, f)
|
||||
};
|
||||
|
||||
if (includeInstance) {
|
||||
obj.$jspbMessageInstance = msg;
|
||||
}
|
||||
return obj;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Deserializes binary data (in protobuf wire format).
|
||||
* @param {jspb.ByteSource} bytes The bytes to deserialize.
|
||||
* @return {!proto.Test.Inner}
|
||||
*/
|
||||
proto.Test.Inner.deserializeBinary = function(bytes) {
|
||||
var reader = new jspb.BinaryReader(bytes);
|
||||
var msg = new proto.Test.Inner;
|
||||
return proto.Test.Inner.deserializeBinaryFromReader(msg, reader);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Deserializes binary data (in protobuf wire format) from the
|
||||
* given reader into the given message object.
|
||||
* @param {!proto.Test.Inner} msg The message object to deserialize into.
|
||||
* @param {!jspb.BinaryReader} reader The BinaryReader to use.
|
||||
* @return {!proto.Test.Inner}
|
||||
*/
|
||||
proto.Test.Inner.deserializeBinaryFromReader = function(msg, reader) {
|
||||
while (reader.nextField()) {
|
||||
if (reader.isEndGroup()) {
|
||||
break;
|
||||
}
|
||||
var field = reader.getFieldNumber();
|
||||
switch (field) {
|
||||
case 1:
|
||||
var value = /** @type {number} */ (reader.readInt32());
|
||||
msg.setInt32(value);
|
||||
break;
|
||||
case 2:
|
||||
var value = new proto.Test.Inner.InnerInner;
|
||||
reader.readMessage(value,proto.Test.Inner.InnerInner.deserializeBinaryFromReader);
|
||||
msg.setInnerinner(value);
|
||||
break;
|
||||
case 3:
|
||||
var value = new proto.Outer;
|
||||
reader.readMessage(value,proto.Outer.deserializeBinaryFromReader);
|
||||
msg.setOuter(value);
|
||||
break;
|
||||
default:
|
||||
reader.skipField();
|
||||
break;
|
||||
}
|
||||
}
|
||||
return msg;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Serializes the message to binary data (in protobuf wire format).
|
||||
* @return {!Uint8Array}
|
||||
*/
|
||||
proto.Test.Inner.prototype.serializeBinary = function() {
|
||||
var writer = new jspb.BinaryWriter();
|
||||
proto.Test.Inner.serializeBinaryToWriter(this, writer);
|
||||
return writer.getResultBuffer();
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Serializes the given message to binary data (in protobuf wire
|
||||
* format), writing to the given BinaryWriter.
|
||||
* @param {!proto.Test.Inner} message
|
||||
* @param {!jspb.BinaryWriter} writer
|
||||
*/
|
||||
proto.Test.Inner.serializeBinaryToWriter = function(message, writer) {
|
||||
var f = undefined;
|
||||
f = message.getInt32();
|
||||
if (f !== 0) {
|
||||
writer.writeInt32(
|
||||
1,
|
||||
f
|
||||
);
|
||||
}
|
||||
f = message.getInnerinner();
|
||||
if (f != null) {
|
||||
writer.writeMessage(
|
||||
2,
|
||||
f,
|
||||
proto.Test.Inner.InnerInner.serializeBinaryToWriter
|
||||
);
|
||||
}
|
||||
f = message.getOuter();
|
||||
if (f != null) {
|
||||
writer.writeMessage(
|
||||
3,
|
||||
f,
|
||||
proto.Outer.serializeBinaryToWriter
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Generated by JsPbCodeGenerator.
|
||||
* @param {Array=} opt_data Optional initial data array, typically from a
|
||||
* server response, or constructed directly in Javascript. The array is used
|
||||
* in place and becomes part of the constructed object. It is not cloned.
|
||||
* If no data is provided, the constructed object will be empty, but still
|
||||
* valid.
|
||||
* @extends {jspb.Message}
|
||||
* @constructor
|
||||
*/
|
||||
proto.Test.Inner.InnerInner = function(opt_data) {
|
||||
jspb.Message.initialize(this, opt_data, 0, -1, null, null);
|
||||
};
|
||||
goog.inherits(proto.Test.Inner.InnerInner, jspb.Message);
|
||||
if (goog.DEBUG && !COMPILED) {
|
||||
proto.Test.Inner.InnerInner.displayName = 'proto.Test.Inner.InnerInner';
|
||||
}
|
||||
|
||||
|
||||
if (jspb.Message.GENERATE_TO_OBJECT) {
|
||||
/**
|
||||
* Creates an object representation of this proto suitable for use in Soy templates.
|
||||
* Field names that are reserved in JavaScript and will be renamed to pb_name.
|
||||
* To access a reserved field use, foo.pb_<name>, eg, foo.pb_default.
|
||||
* For the list of reserved names please see:
|
||||
* com.google.apps.jspb.JsClassTemplate.JS_RESERVED_WORDS.
|
||||
* @param {boolean=} opt_includeInstance Whether to include the JSPB instance
|
||||
* for transitional soy proto support: http://goto/soy-param-migration
|
||||
* @return {!Object}
|
||||
*/
|
||||
proto.Test.Inner.InnerInner.prototype.toObject = function(opt_includeInstance) {
|
||||
return proto.Test.Inner.InnerInner.toObject(opt_includeInstance, this);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Static version of the {@see toObject} method.
|
||||
* @param {boolean|undefined} includeInstance Whether to include the JSPB
|
||||
* instance for transitional soy proto support:
|
||||
* http://goto/soy-param-migration
|
||||
* @param {!proto.Test.Inner.InnerInner} msg The msg instance to transform.
|
||||
* @return {!Object}
|
||||
*/
|
||||
proto.Test.Inner.InnerInner.toObject = function(includeInstance, msg) {
|
||||
var f, obj = {
|
||||
pb_long: jspb.Message.getFieldWithDefault(msg, 1, 0),
|
||||
pb_enum: jspb.Message.getFieldWithDefault(msg, 2, 0),
|
||||
sint32: jspb.Message.getFieldWithDefault(msg, 3, 0)
|
||||
};
|
||||
|
||||
if (includeInstance) {
|
||||
obj.$jspbMessageInstance = msg;
|
||||
}
|
||||
return obj;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Deserializes binary data (in protobuf wire format).
|
||||
* @param {jspb.ByteSource} bytes The bytes to deserialize.
|
||||
* @return {!proto.Test.Inner.InnerInner}
|
||||
*/
|
||||
proto.Test.Inner.InnerInner.deserializeBinary = function(bytes) {
|
||||
var reader = new jspb.BinaryReader(bytes);
|
||||
var msg = new proto.Test.Inner.InnerInner;
|
||||
return proto.Test.Inner.InnerInner.deserializeBinaryFromReader(msg, reader);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Deserializes binary data (in protobuf wire format) from the
|
||||
* given reader into the given message object.
|
||||
* @param {!proto.Test.Inner.InnerInner} msg The message object to deserialize into.
|
||||
* @param {!jspb.BinaryReader} reader The BinaryReader to use.
|
||||
* @return {!proto.Test.Inner.InnerInner}
|
||||
*/
|
||||
proto.Test.Inner.InnerInner.deserializeBinaryFromReader = function(msg, reader) {
|
||||
while (reader.nextField()) {
|
||||
if (reader.isEndGroup()) {
|
||||
break;
|
||||
}
|
||||
var field = reader.getFieldNumber();
|
||||
switch (field) {
|
||||
case 1:
|
||||
var value = /** @type {number} */ (reader.readInt64());
|
||||
msg.setLong(value);
|
||||
break;
|
||||
case 2:
|
||||
var value = /** @type {!proto.Test.Enum} */ (reader.readEnum());
|
||||
msg.setEnum(value);
|
||||
break;
|
||||
case 3:
|
||||
var value = /** @type {number} */ (reader.readSint32());
|
||||
msg.setSint32(value);
|
||||
break;
|
||||
default:
|
||||
reader.skipField();
|
||||
break;
|
||||
}
|
||||
}
|
||||
return msg;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Serializes the message to binary data (in protobuf wire format).
|
||||
* @return {!Uint8Array}
|
||||
*/
|
||||
proto.Test.Inner.InnerInner.prototype.serializeBinary = function() {
|
||||
var writer = new jspb.BinaryWriter();
|
||||
proto.Test.Inner.InnerInner.serializeBinaryToWriter(this, writer);
|
||||
return writer.getResultBuffer();
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Serializes the given message to binary data (in protobuf wire
|
||||
* format), writing to the given BinaryWriter.
|
||||
* @param {!proto.Test.Inner.InnerInner} message
|
||||
* @param {!jspb.BinaryWriter} writer
|
||||
*/
|
||||
proto.Test.Inner.InnerInner.serializeBinaryToWriter = function(message, writer) {
|
||||
var f = undefined;
|
||||
f = message.getLong();
|
||||
if (f !== 0) {
|
||||
writer.writeInt64(
|
||||
1,
|
||||
f
|
||||
);
|
||||
}
|
||||
f = message.getEnum();
|
||||
if (f !== 0.0) {
|
||||
writer.writeEnum(
|
||||
2,
|
||||
f
|
||||
);
|
||||
}
|
||||
f = message.getSint32();
|
||||
if (f !== 0) {
|
||||
writer.writeSint32(
|
||||
3,
|
||||
f
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* optional int64 long = 1;
|
||||
* @return {number}
|
||||
*/
|
||||
proto.Test.Inner.InnerInner.prototype.getLong = function() {
|
||||
return /** @type {number} */ (jspb.Message.getFieldWithDefault(this, 1, 0));
|
||||
};
|
||||
|
||||
|
||||
/** @param {number} value */
|
||||
proto.Test.Inner.InnerInner.prototype.setLong = function(value) {
|
||||
jspb.Message.setField(this, 1, value);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* optional Enum enum = 2;
|
||||
* @return {!proto.Test.Enum}
|
||||
*/
|
||||
proto.Test.Inner.InnerInner.prototype.getEnum = function() {
|
||||
return /** @type {!proto.Test.Enum} */ (jspb.Message.getFieldWithDefault(this, 2, 0));
|
||||
};
|
||||
|
||||
|
||||
/** @param {!proto.Test.Enum} value */
|
||||
proto.Test.Inner.InnerInner.prototype.setEnum = function(value) {
|
||||
jspb.Message.setField(this, 2, value);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* optional sint32 sint32 = 3;
|
||||
* @return {number}
|
||||
*/
|
||||
proto.Test.Inner.InnerInner.prototype.getSint32 = function() {
|
||||
return /** @type {number} */ (jspb.Message.getFieldWithDefault(this, 3, 0));
|
||||
};
|
||||
|
||||
|
||||
/** @param {number} value */
|
||||
proto.Test.Inner.InnerInner.prototype.setSint32 = function(value) {
|
||||
jspb.Message.setField(this, 3, value);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* optional int32 int32 = 1;
|
||||
* @return {number}
|
||||
*/
|
||||
proto.Test.Inner.prototype.getInt32 = function() {
|
||||
return /** @type {number} */ (jspb.Message.getFieldWithDefault(this, 1, 0));
|
||||
};
|
||||
|
||||
|
||||
/** @param {number} value */
|
||||
proto.Test.Inner.prototype.setInt32 = function(value) {
|
||||
jspb.Message.setField(this, 1, value);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* optional InnerInner innerInner = 2;
|
||||
* @return {?proto.Test.Inner.InnerInner}
|
||||
*/
|
||||
proto.Test.Inner.prototype.getInnerinner = function() {
|
||||
return /** @type{?proto.Test.Inner.InnerInner} */ (
|
||||
jspb.Message.getWrapperField(this, proto.Test.Inner.InnerInner, 2));
|
||||
};
|
||||
|
||||
|
||||
/** @param {?proto.Test.Inner.InnerInner|undefined} value */
|
||||
proto.Test.Inner.prototype.setInnerinner = function(value) {
|
||||
jspb.Message.setWrapperField(this, 2, value);
|
||||
};
|
||||
|
||||
|
||||
proto.Test.Inner.prototype.clearInnerinner = function() {
|
||||
this.setInnerinner(undefined);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Returns whether this field is set.
|
||||
* @return {!boolean}
|
||||
*/
|
||||
proto.Test.Inner.prototype.hasInnerinner = function() {
|
||||
return jspb.Message.getField(this, 2) != null;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* optional Outer outer = 3;
|
||||
* @return {?proto.Outer}
|
||||
*/
|
||||
proto.Test.Inner.prototype.getOuter = function() {
|
||||
return /** @type{?proto.Outer} */ (
|
||||
jspb.Message.getWrapperField(this, proto.Outer, 3));
|
||||
};
|
||||
|
||||
|
||||
/** @param {?proto.Outer|undefined} value */
|
||||
proto.Test.Inner.prototype.setOuter = function(value) {
|
||||
jspb.Message.setWrapperField(this, 3, value);
|
||||
};
|
||||
|
||||
|
||||
proto.Test.Inner.prototype.clearOuter = function() {
|
||||
this.setOuter(undefined);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Returns whether this field is set.
|
||||
* @return {!boolean}
|
||||
*/
|
||||
proto.Test.Inner.prototype.hasOuter = function() {
|
||||
return jspb.Message.getField(this, 3) != null;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* optional string string = 1;
|
||||
* @return {string}
|
||||
*/
|
||||
proto.Test.prototype.getString = function() {
|
||||
return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 1, ""));
|
||||
};
|
||||
|
||||
|
||||
/** @param {string} value */
|
||||
proto.Test.prototype.setString = function(value) {
|
||||
jspb.Message.setField(this, 1, value);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* optional uint32 uint32 = 2;
|
||||
* @return {number}
|
||||
*/
|
||||
proto.Test.prototype.getUint32 = function() {
|
||||
return /** @type {number} */ (jspb.Message.getFieldWithDefault(this, 2, 0));
|
||||
};
|
||||
|
||||
|
||||
/** @param {number} value */
|
||||
proto.Test.prototype.setUint32 = function(value) {
|
||||
jspb.Message.setField(this, 2, value);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* optional Inner inner = 3;
|
||||
* @return {?proto.Test.Inner}
|
||||
*/
|
||||
proto.Test.prototype.getInner = function() {
|
||||
return /** @type{?proto.Test.Inner} */ (
|
||||
jspb.Message.getWrapperField(this, proto.Test.Inner, 3));
|
||||
};
|
||||
|
||||
|
||||
/** @param {?proto.Test.Inner|undefined} value */
|
||||
proto.Test.prototype.setInner = function(value) {
|
||||
jspb.Message.setWrapperField(this, 3, value);
|
||||
};
|
||||
|
||||
|
||||
proto.Test.prototype.clearInner = function() {
|
||||
this.setInner(undefined);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Returns whether this field is set.
|
||||
* @return {!boolean}
|
||||
*/
|
||||
proto.Test.prototype.hasInner = function() {
|
||||
return jspb.Message.getField(this, 3) != null;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* optional float float = 4;
|
||||
* @return {number}
|
||||
*/
|
||||
proto.Test.prototype.getFloat = function() {
|
||||
return /** @type {number} */ (+jspb.Message.getFieldWithDefault(this, 4, 0.0));
|
||||
};
|
||||
|
||||
|
||||
/** @param {number} value */
|
||||
proto.Test.prototype.setFloat = function(value) {
|
||||
jspb.Message.setField(this, 4, value);
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Generated by JsPbCodeGenerator.
|
||||
* @param {Array=} opt_data Optional initial data array, typically from a
|
||||
* server response, or constructed directly in Javascript. The array is used
|
||||
* in place and becomes part of the constructed object. It is not cloned.
|
||||
* If no data is provided, the constructed object will be empty, but still
|
||||
* valid.
|
||||
* @extends {jspb.Message}
|
||||
* @constructor
|
||||
*/
|
||||
proto.Outer = function(opt_data) {
|
||||
jspb.Message.initialize(this, opt_data, 0, -1, proto.Outer.repeatedFields_, null);
|
||||
};
|
||||
goog.inherits(proto.Outer, jspb.Message);
|
||||
if (goog.DEBUG && !COMPILED) {
|
||||
proto.Outer.displayName = 'proto.Outer';
|
||||
}
|
||||
/**
|
||||
* List of repeated fields within this message type.
|
||||
* @private {!Array<number>}
|
||||
* @const
|
||||
*/
|
||||
proto.Outer.repeatedFields_ = [1];
|
||||
|
||||
|
||||
|
||||
if (jspb.Message.GENERATE_TO_OBJECT) {
|
||||
/**
|
||||
* Creates an object representation of this proto suitable for use in Soy templates.
|
||||
* Field names that are reserved in JavaScript and will be renamed to pb_name.
|
||||
* To access a reserved field use, foo.pb_<name>, eg, foo.pb_default.
|
||||
* For the list of reserved names please see:
|
||||
* com.google.apps.jspb.JsClassTemplate.JS_RESERVED_WORDS.
|
||||
* @param {boolean=} opt_includeInstance Whether to include the JSPB instance
|
||||
* for transitional soy proto support: http://goto/soy-param-migration
|
||||
* @return {!Object}
|
||||
*/
|
||||
proto.Outer.prototype.toObject = function(opt_includeInstance) {
|
||||
return proto.Outer.toObject(opt_includeInstance, this);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Static version of the {@see toObject} method.
|
||||
* @param {boolean|undefined} includeInstance Whether to include the JSPB
|
||||
* instance for transitional soy proto support:
|
||||
* http://goto/soy-param-migration
|
||||
* @param {!proto.Outer} msg The msg instance to transform.
|
||||
* @return {!Object}
|
||||
*/
|
||||
proto.Outer.toObject = function(includeInstance, msg) {
|
||||
var f, obj = {
|
||||
boolList: jspb.Message.getField(msg, 1),
|
||||
pb_double: +jspb.Message.getFieldWithDefault(msg, 2, 0.0)
|
||||
};
|
||||
|
||||
if (includeInstance) {
|
||||
obj.$jspbMessageInstance = msg;
|
||||
}
|
||||
return obj;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Deserializes binary data (in protobuf wire format).
|
||||
* @param {jspb.ByteSource} bytes The bytes to deserialize.
|
||||
* @return {!proto.Outer}
|
||||
*/
|
||||
proto.Outer.deserializeBinary = function(bytes) {
|
||||
var reader = new jspb.BinaryReader(bytes);
|
||||
var msg = new proto.Outer;
|
||||
return proto.Outer.deserializeBinaryFromReader(msg, reader);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Deserializes binary data (in protobuf wire format) from the
|
||||
* given reader into the given message object.
|
||||
* @param {!proto.Outer} msg The message object to deserialize into.
|
||||
* @param {!jspb.BinaryReader} reader The BinaryReader to use.
|
||||
* @return {!proto.Outer}
|
||||
*/
|
||||
proto.Outer.deserializeBinaryFromReader = function(msg, reader) {
|
||||
while (reader.nextField()) {
|
||||
if (reader.isEndGroup()) {
|
||||
break;
|
||||
}
|
||||
var field = reader.getFieldNumber();
|
||||
switch (field) {
|
||||
case 1:
|
||||
var value = /** @type {!Array.<boolean>} */ (reader.readPackedBool());
|
||||
msg.setBoolList(value);
|
||||
break;
|
||||
case 2:
|
||||
var value = /** @type {number} */ (reader.readDouble());
|
||||
msg.setDouble(value);
|
||||
break;
|
||||
default:
|
||||
reader.skipField();
|
||||
break;
|
||||
}
|
||||
}
|
||||
return msg;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Serializes the message to binary data (in protobuf wire format).
|
||||
* @return {!Uint8Array}
|
||||
*/
|
||||
proto.Outer.prototype.serializeBinary = function() {
|
||||
var writer = new jspb.BinaryWriter();
|
||||
proto.Outer.serializeBinaryToWriter(this, writer);
|
||||
return writer.getResultBuffer();
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Serializes the given message to binary data (in protobuf wire
|
||||
* format), writing to the given BinaryWriter.
|
||||
* @param {!proto.Outer} message
|
||||
* @param {!jspb.BinaryWriter} writer
|
||||
*/
|
||||
proto.Outer.serializeBinaryToWriter = function(message, writer) {
|
||||
var f = undefined;
|
||||
f = message.getBoolList();
|
||||
if (f.length > 0) {
|
||||
writer.writePackedBool(
|
||||
1,
|
||||
f
|
||||
);
|
||||
}
|
||||
f = message.getDouble();
|
||||
if (f !== 0.0) {
|
||||
writer.writeDouble(
|
||||
2,
|
||||
f
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* repeated bool bool = 1;
|
||||
* Note that Boolean fields may be set to 0/1 when serialized from a Java server.
|
||||
* You should avoid comparisons like {@code val === true/false} in those cases.
|
||||
* If you change this array by adding, removing or replacing elements, or if you
|
||||
* replace the array itself, then you must call the setter to update it.
|
||||
* @return {!Array.<boolean>}
|
||||
*/
|
||||
proto.Outer.prototype.getBoolList = function() {
|
||||
return /** @type {!Array.<boolean>} */ (jspb.Message.getField(this, 1));
|
||||
};
|
||||
|
||||
|
||||
/** @param {!Array.<boolean>} value */
|
||||
proto.Outer.prototype.setBoolList = function(value) {
|
||||
jspb.Message.setField(this, 1, value || []);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {!boolean} value
|
||||
* @param {number=} opt_index
|
||||
*/
|
||||
proto.Outer.prototype.addBool = function(value, opt_index) {
|
||||
jspb.Message.addToRepeatedField(this, 1, value, opt_index);
|
||||
};
|
||||
|
||||
|
||||
proto.Outer.prototype.clearBoolList = function() {
|
||||
this.setBoolList([]);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* optional double double = 2;
|
||||
* @return {number}
|
||||
*/
|
||||
proto.Outer.prototype.getDouble = function() {
|
||||
return /** @type {number} */ (+jspb.Message.getFieldWithDefault(this, 2, 0.0));
|
||||
};
|
||||
|
||||
|
||||
/** @param {number} value */
|
||||
proto.Outer.prototype.setDouble = function(value) {
|
||||
jspb.Message.setField(this, 2, value);
|
||||
};
|
||||
|
||||
|
||||
goog.object.extend(exports, proto);
|
||||
+240
@@ -0,0 +1,240 @@
|
||||
/*eslint-disable block-scoped-var, id-length, no-control-regex, no-magic-numbers, no-prototype-builtins, no-redeclare, no-shadow, no-var, sort-vars*/
|
||||
"use strict";
|
||||
|
||||
var $protobuf = require("../../minimal");
|
||||
|
||||
var $Reader = $protobuf.Reader, $Writer = $protobuf.Writer, $util = $protobuf.util;
|
||||
|
||||
var $root = $protobuf.roots.test_bench || ($protobuf.roots.test_bench = {});
|
||||
|
||||
$root.Test = (function() {
|
||||
|
||||
function Test(properties) {
|
||||
if (properties)
|
||||
for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i)
|
||||
if (properties[keys[i]] != null)
|
||||
this[keys[i]] = properties[keys[i]];
|
||||
}
|
||||
|
||||
Test.prototype.string = "";
|
||||
Test.prototype.uint32 = 0;
|
||||
Test.prototype.inner = null;
|
||||
Test.prototype.float = 0;
|
||||
|
||||
Test.encode = function encode(message, writer) {
|
||||
if (!writer)
|
||||
writer = $Writer.create();
|
||||
if (message.string != null && message.hasOwnProperty("string"))
|
||||
writer.uint32(10).string(message.string);
|
||||
if (message.uint32 != null && message.hasOwnProperty("uint32"))
|
||||
writer.uint32(16).uint32(message.uint32);
|
||||
if (message.inner != null && message.hasOwnProperty("inner"))
|
||||
$root.Test.Inner.encode(message.inner, writer.uint32(26).fork()).ldelim();
|
||||
if (message.float != null && message.hasOwnProperty("float"))
|
||||
writer.uint32(37).float(message.float);
|
||||
return writer;
|
||||
};
|
||||
|
||||
Test.decode = function decode(reader, length) {
|
||||
if (!(reader instanceof $Reader))
|
||||
reader = $Reader.create(reader);
|
||||
var end = length === undefined ? reader.len : reader.pos + length, message = new $root.Test();
|
||||
while (reader.pos < end) {
|
||||
var tag = reader.uint32();
|
||||
switch (tag >>> 3) {
|
||||
case 1:
|
||||
message.string = reader.string();
|
||||
break;
|
||||
case 2:
|
||||
message.uint32 = reader.uint32();
|
||||
break;
|
||||
case 3:
|
||||
message.inner = $root.Test.Inner.decode(reader, reader.uint32());
|
||||
break;
|
||||
case 4:
|
||||
message.float = reader.float();
|
||||
break;
|
||||
default:
|
||||
reader.skipType(tag & 7);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return message;
|
||||
};
|
||||
|
||||
Test.Inner = (function() {
|
||||
|
||||
function Inner(properties) {
|
||||
if (properties)
|
||||
for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i)
|
||||
if (properties[keys[i]] != null)
|
||||
this[keys[i]] = properties[keys[i]];
|
||||
}
|
||||
|
||||
Inner.prototype.int32 = 0;
|
||||
Inner.prototype.innerInner = null;
|
||||
Inner.prototype.outer = null;
|
||||
|
||||
Inner.encode = function encode(message, writer) {
|
||||
if (!writer)
|
||||
writer = $Writer.create();
|
||||
if (message.int32 != null && message.hasOwnProperty("int32"))
|
||||
writer.uint32(8).int32(message.int32);
|
||||
if (message.innerInner != null && message.hasOwnProperty("innerInner"))
|
||||
$root.Test.Inner.InnerInner.encode(message.innerInner, writer.uint32(18).fork()).ldelim();
|
||||
if (message.outer != null && message.hasOwnProperty("outer"))
|
||||
$root.Outer.encode(message.outer, writer.uint32(26).fork()).ldelim();
|
||||
return writer;
|
||||
};
|
||||
|
||||
Inner.decode = function decode(reader, length) {
|
||||
if (!(reader instanceof $Reader))
|
||||
reader = $Reader.create(reader);
|
||||
var end = length === undefined ? reader.len : reader.pos + length, message = new $root.Test.Inner();
|
||||
while (reader.pos < end) {
|
||||
var tag = reader.uint32();
|
||||
switch (tag >>> 3) {
|
||||
case 1:
|
||||
message.int32 = reader.int32();
|
||||
break;
|
||||
case 2:
|
||||
message.innerInner = $root.Test.Inner.InnerInner.decode(reader, reader.uint32());
|
||||
break;
|
||||
case 3:
|
||||
message.outer = $root.Outer.decode(reader, reader.uint32());
|
||||
break;
|
||||
default:
|
||||
reader.skipType(tag & 7);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return message;
|
||||
};
|
||||
|
||||
Inner.InnerInner = (function() {
|
||||
|
||||
function InnerInner(properties) {
|
||||
if (properties)
|
||||
for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i)
|
||||
if (properties[keys[i]] != null)
|
||||
this[keys[i]] = properties[keys[i]];
|
||||
}
|
||||
|
||||
InnerInner.prototype.long = $util.Long ? $util.Long.fromBits(0,0,false) : 0;
|
||||
InnerInner.prototype["enum"] = 0;
|
||||
InnerInner.prototype.sint32 = 0;
|
||||
|
||||
InnerInner.encode = function encode(message, writer) {
|
||||
if (!writer)
|
||||
writer = $Writer.create();
|
||||
if (message.long != null && message.hasOwnProperty("long"))
|
||||
writer.uint32(8).int64(message.long);
|
||||
if (message["enum"] != null && message.hasOwnProperty("enum"))
|
||||
writer.uint32(16).int32(message["enum"]);
|
||||
if (message.sint32 != null && message.hasOwnProperty("sint32"))
|
||||
writer.uint32(24).sint32(message.sint32);
|
||||
return writer;
|
||||
};
|
||||
|
||||
InnerInner.decode = function decode(reader, length) {
|
||||
if (!(reader instanceof $Reader))
|
||||
reader = $Reader.create(reader);
|
||||
var end = length === undefined ? reader.len : reader.pos + length, message = new $root.Test.Inner.InnerInner();
|
||||
while (reader.pos < end) {
|
||||
var tag = reader.uint32();
|
||||
switch (tag >>> 3) {
|
||||
case 1:
|
||||
message.long = reader.int64();
|
||||
break;
|
||||
case 2:
|
||||
message["enum"] = reader.int32();
|
||||
break;
|
||||
case 3:
|
||||
message.sint32 = reader.sint32();
|
||||
break;
|
||||
default:
|
||||
reader.skipType(tag & 7);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return message;
|
||||
};
|
||||
|
||||
return InnerInner;
|
||||
})();
|
||||
|
||||
return Inner;
|
||||
})();
|
||||
|
||||
Test.Enum = (function() {
|
||||
var valuesById = {}, values = Object.create(valuesById);
|
||||
values[valuesById[0] = "ONE"] = 0;
|
||||
values[valuesById[1] = "TWO"] = 1;
|
||||
values[valuesById[2] = "THREE"] = 2;
|
||||
values[valuesById[3] = "FOUR"] = 3;
|
||||
values[valuesById[4] = "FIVE"] = 4;
|
||||
return values;
|
||||
})();
|
||||
|
||||
return Test;
|
||||
})();
|
||||
|
||||
$root.Outer = (function() {
|
||||
|
||||
function Outer(properties) {
|
||||
this.bool = [];
|
||||
if (properties)
|
||||
for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i)
|
||||
if (properties[keys[i]] != null)
|
||||
this[keys[i]] = properties[keys[i]];
|
||||
}
|
||||
|
||||
Outer.prototype.bool = $util.emptyArray;
|
||||
Outer.prototype.double = 0;
|
||||
|
||||
Outer.encode = function encode(message, writer) {
|
||||
if (!writer)
|
||||
writer = $Writer.create();
|
||||
if (message.bool != null && message.bool.length) {
|
||||
writer.uint32(10).fork();
|
||||
for (var i = 0; i < message.bool.length; ++i)
|
||||
writer.bool(message.bool[i]);
|
||||
writer.ldelim();
|
||||
}
|
||||
if (message.double != null && message.hasOwnProperty("double"))
|
||||
writer.uint32(17).double(message.double);
|
||||
return writer;
|
||||
};
|
||||
|
||||
Outer.decode = function decode(reader, length) {
|
||||
if (!(reader instanceof $Reader))
|
||||
reader = $Reader.create(reader);
|
||||
var end = length === undefined ? reader.len : reader.pos + length, message = new $root.Outer();
|
||||
while (reader.pos < end) {
|
||||
var tag = reader.uint32();
|
||||
switch (tag >>> 3) {
|
||||
case 1:
|
||||
if (!(message.bool && message.bool.length))
|
||||
message.bool = [];
|
||||
if ((tag & 7) === 2) {
|
||||
var end2 = reader.uint32() + reader.pos;
|
||||
while (reader.pos < end2)
|
||||
message.bool.push(reader.bool());
|
||||
} else
|
||||
message.bool.push(reader.bool());
|
||||
break;
|
||||
case 2:
|
||||
message.double = reader.double();
|
||||
break;
|
||||
default:
|
||||
reader.skipType(tag & 7);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return message;
|
||||
};
|
||||
|
||||
return Outer;
|
||||
})();
|
||||
|
||||
module.exports = $root;
|
||||
Executable
+90
@@ -0,0 +1,90 @@
|
||||
"use strict";
|
||||
|
||||
// NOTE: This benchmark partly compares apples and oranges in that it measures protocol buffers,
|
||||
// which is purely a binary format, and JSON, which is purely a string format.
|
||||
//
|
||||
// This matters because strings aren't actually transfered over the network but must still be
|
||||
// converted to binary somewhere down the road. Because this can't be measured reliably, this
|
||||
// benchmark compares both pure string performance of JSON and additional binary conversion of the
|
||||
// same data using node buffers. Actual JSON performance on the network level should be somewhere
|
||||
// in between.
|
||||
|
||||
var newSuite = require("./suite"),
|
||||
payload = require("./data/bench.json");
|
||||
|
||||
var Buffer_from = Buffer.from !== Uint8Array.from && Buffer.from || function(value, encoding) { return new Buffer(value, encoding); };
|
||||
|
||||
// protobuf.js dynamic: load the proto and set up a buffer
|
||||
var pbjsCls = require("..").loadSync(require.resolve("./data/bench.proto")).resolveAll().lookup("Test");
|
||||
var pbjsMsg = payload; // alt: pbjsCls.fromObject(payload);
|
||||
var pbjsBuf = pbjsCls.encode(pbjsMsg).finish();
|
||||
|
||||
// protobuf.js static: load the proto
|
||||
var pbjsStaticCls = require("./data/static_pbjs.js").Test;
|
||||
|
||||
// JSON: set up a string and a buffer
|
||||
var jsonMsg = payload;
|
||||
var jsonStr = JSON.stringify(jsonMsg);
|
||||
var jsonBuf = Buffer_from(jsonStr, "utf8");
|
||||
|
||||
// google-protobuf: load the proto, set up an Uint8Array and a message
|
||||
var jspbCls = require("./data/static_jspb.js").Test;
|
||||
var jspbBuf = new Uint8Array(Array.prototype.slice.call(pbjsBuf));
|
||||
var jspbMsg = jspbCls.deserializeBinary(jspbBuf);
|
||||
|
||||
newSuite("encoding")
|
||||
|
||||
.add("protobuf.js (reflect)", function() {
|
||||
pbjsCls.encode(pbjsMsg).finish();
|
||||
})
|
||||
.add("protobuf.js (static)", function() {
|
||||
pbjsStaticCls.encode(pbjsMsg).finish();
|
||||
})
|
||||
.add("JSON (string)", function() {
|
||||
JSON.stringify(jsonMsg);
|
||||
})
|
||||
.add("JSON (buffer)", function() {
|
||||
Buffer_from(JSON.stringify(jsonMsg), "utf8");
|
||||
})
|
||||
.add("google-protobuf", function() {
|
||||
jspbMsg.serializeBinary();
|
||||
})
|
||||
.run();
|
||||
|
||||
newSuite("decoding")
|
||||
|
||||
.add("protobuf.js (reflect)", function() {
|
||||
pbjsCls.decode(pbjsBuf); // no allocation overhead, if you wondered
|
||||
})
|
||||
.add("protobuf.js (static)", function() {
|
||||
pbjsStaticCls.decode(pbjsBuf);
|
||||
})
|
||||
.add("JSON (string)", function() {
|
||||
JSON.parse(jsonStr);
|
||||
})
|
||||
.add("JSON (buffer)", function() {
|
||||
JSON.parse(jsonBuf.toString("utf8"));
|
||||
})
|
||||
.add("google-protobuf", function() {
|
||||
jspbCls.deserializeBinary(jspbBuf);
|
||||
})
|
||||
.run();
|
||||
|
||||
newSuite("combined")
|
||||
|
||||
.add("protobuf.js (reflect)", function() {
|
||||
pbjsCls.decode(pbjsCls.encode(pbjsMsg).finish());
|
||||
})
|
||||
.add("protobuf.js (static)", function() {
|
||||
pbjsStaticCls.decode(pbjsStaticCls.encode(pbjsMsg).finish());
|
||||
})
|
||||
.add("JSON (string)", function() {
|
||||
JSON.parse(JSON.stringify(jsonMsg));
|
||||
})
|
||||
.add("JSON (buffer)", function() {
|
||||
JSON.parse(Buffer_from(JSON.stringify(jsonMsg), "utf8").toString("utf8"));
|
||||
})
|
||||
.add("google-protobuf", function() {
|
||||
jspbCls.deserializeBinary(jspbMsg.serializeBinary());
|
||||
})
|
||||
.run();
|
||||
Executable
+102
@@ -0,0 +1,102 @@
|
||||
"use strict";
|
||||
|
||||
var fs = require("fs"),
|
||||
path = require("path");
|
||||
|
||||
// A profiling stub to measure encoding / decoding performance using benchmark data.
|
||||
|
||||
var commands = ["encode", "decode", "encode-browser", "decode-browser", "fromjson"];
|
||||
if (commands.indexOf(process.argv[2]) < 0) { // 0: node, 1: prof.js
|
||||
process.stderr.write("usage: " + path.basename(process.argv[1]) + " <" + commands.join("|") + "> [iterations=10000000]\n");
|
||||
return;
|
||||
}
|
||||
|
||||
// Spin up a node process with profiling enabled and process the generated log
|
||||
if (process.execArgv.indexOf("--prof") < 0) {
|
||||
process.stdout.write("cleaning up old logs ...\n");
|
||||
var child_process = require("child_process");
|
||||
var logRe = /^isolate-[0-9A-F]+-v8\.log$/;
|
||||
fs.readdirSync(process.cwd()).forEach(function readdirSync_it(file) {
|
||||
if (logRe.test(file))
|
||||
fs.unlink(file);
|
||||
});
|
||||
process.stdout.write("generating profile (may take a while) ...\n");
|
||||
child_process.execSync("node --prof --trace-deopt " + process.execArgv.join(" ") + " " + process.argv.slice(1).join(" "), {
|
||||
cwd: process.cwd(),
|
||||
stdio: "inherit"
|
||||
});
|
||||
process.stdout.write("processing profile ...\n");
|
||||
fs.readdirSync(process.cwd()).forEach(function readdirSync_it(file) {
|
||||
if (logRe.test(file)) {
|
||||
child_process.execSync("node --prof-process " + file, {
|
||||
cwd: process.cwd(),
|
||||
stdio: "inherit"
|
||||
});
|
||||
// fs.unlink(file);
|
||||
}
|
||||
});
|
||||
process.stdout.write("done.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
// Actual profiling code
|
||||
var protobuf = require("..");
|
||||
|
||||
// protobuf.util.codegen.verbose = true;
|
||||
|
||||
var root, json;
|
||||
|
||||
if (process.argv[2] === "fromjson") {
|
||||
json = require("../tests/data/test.json");
|
||||
if (process.argv.indexOf("--resolve") < 0)
|
||||
for (var k = 0; k < 10000; ++k)
|
||||
protobuf.Root.fromJSON(json);
|
||||
else
|
||||
for (var l = 0; l < 10000; ++l)
|
||||
protobuf.Root.fromJSON(json).resolveAll();
|
||||
return;
|
||||
}
|
||||
|
||||
var Test, data, count;
|
||||
|
||||
if (process.argv.indexOf("--alt") < 0) {
|
||||
root = protobuf.parse(fs.readFileSync(require.resolve("../bench/data/bench.proto")).toString("utf8")).root;
|
||||
Test = root.lookup("Test");
|
||||
json = JSON.stringify(root);
|
||||
data = require("../bench/data/bench.json");
|
||||
count = 10000000;
|
||||
process.stdout.write("bench.proto");
|
||||
} else {
|
||||
root = protobuf.parse(fs.readFileSync(require.resolve("../tests/data/mapbox/vector_tile.proto")).toString("utf8")).root;
|
||||
Test = root.lookup("vector_tile.Tile");
|
||||
data = Test.decode(fs.readFileSync(require.resolve("../tests/data/mapbox/vector_tile.bin")));
|
||||
count = 1000;
|
||||
process.stdout.write("vector_tile.proto");
|
||||
}
|
||||
|
||||
if (process.argv.length > 3 && /^\d+$/.test(process.argv[3]))
|
||||
count = parseInt(process.argv[3], 10);
|
||||
process.stdout.write(" x " + count + "\n");
|
||||
|
||||
function setupBrowser() {
|
||||
protobuf.Writer.create = function create_browser() { return new protobuf.Writer(); };
|
||||
protobuf.Reader.create = function create_browser(buf) { return new protobuf.Reader(buf); };
|
||||
}
|
||||
|
||||
switch (process.argv[2]) {
|
||||
case "encode-browser":
|
||||
setupBrowser();
|
||||
// eslint-disable-line no-fallthrough
|
||||
case "encode":
|
||||
for (var i = 0; i < count; ++i)
|
||||
Test.encode(data).finish();
|
||||
break;
|
||||
case "decode-browser":
|
||||
setupBrowser();
|
||||
// eslint-disable-line no-fallthrough
|
||||
case "decode":
|
||||
var buf = Test.encode(data).finish();
|
||||
for (var j = 0; j < count; ++j)
|
||||
Test.decode(buf);
|
||||
break;
|
||||
}
|
||||
Executable
+45
@@ -0,0 +1,45 @@
|
||||
"use strict";
|
||||
module.exports = newSuite;
|
||||
|
||||
var benchmark = require("benchmark"),
|
||||
chalk = require("chalk");
|
||||
|
||||
var padSize = 23;
|
||||
|
||||
function newSuite(name) {
|
||||
var benches = [];
|
||||
return new benchmark.Suite(name)
|
||||
.on("add", function(event) {
|
||||
benches.push(event.target);
|
||||
})
|
||||
.on("start", function() {
|
||||
process.stdout.write(chalk.white.bold("benchmarking " + name + " performance ...") + "\n\n");
|
||||
})
|
||||
.on("cycle", function(event) {
|
||||
process.stdout.write(String(event.target) + "\n");
|
||||
})
|
||||
.on("complete", function() {
|
||||
if (benches.length > 1) {
|
||||
benches.sort(function(a, b) { return getHz(b) - getHz(a); });
|
||||
var fastest = benches[0],
|
||||
fastestHz = getHz(fastest);
|
||||
process.stdout.write("\n" + chalk.white(pad(fastest.name, padSize)) + " was " + chalk.green("fastest") + "\n");
|
||||
benches.slice(1).forEach(function(bench) {
|
||||
var hz = getHz(bench);
|
||||
var percent = 1 - hz / fastestHz;
|
||||
process.stdout.write(chalk.white(pad(bench.name, padSize)) + " was " + chalk.red((percent * 100).toFixed(1) + "% ops/sec slower (factor " + (fastestHz / hz).toFixed(1) + ")") + "\n");
|
||||
});
|
||||
}
|
||||
process.stdout.write("\n");
|
||||
});
|
||||
}
|
||||
|
||||
function getHz(bench) {
|
||||
return 1 / (bench.stats.mean + bench.stats.moe);
|
||||
}
|
||||
|
||||
function pad(str, len, l) {
|
||||
while (str.length < len)
|
||||
str = l ? str + " " : " " + str;
|
||||
return str;
|
||||
}
|
||||
Reference in New Issue
Block a user