Permalink
Browse files

New: Generate named constructors for runtime messages, see #588

  • Loading branch information...
dcodeIO committed Jan 3, 2017
1 parent 196fdc0 commit cba46c389ed56737184e5bc2bcce07243d52e5ce
@@ -3,3 +3,4 @@ npm-debug.*
node_modules/
docs/
coverage/
sandbox/
@@ -5,6 +5,7 @@ npm-debug.*
node_modules/
docs/
coverage/
sandbox/
examples/
src/util/aspromise/
src/util/base64/
@@ -4,7 +4,7 @@ protobuf.js
**Protocol Buffers** are a language-neutral, platform-neutral, extensible way of serializing structured data for use in communications protocols, data storage, and more, originally designed at Google ([see](https://developers.google.com/protocol-buffers/)).
**protobuf.js** is a pure JavaScript implementation for node and the browser. It efficiently encodes plain objects and custom classes and works out of the box with .proto files.
**protobuf.js** is a pure JavaScript implementation with TypeScript support for node and the browser. It efficiently encodes plain objects and custom classes and works out of the box with .proto files.
[travis-image]: https://img.shields.io/travis/dcodeIO/protobuf.js.svg
[travis-url]: https://travis-ci.org/dcodeIO/protobuf.js

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.
BIN +6 Bytes (100%) dist/noparse/protobuf.min.js.gz
Binary file not shown.

Large diffs are not rendered by default.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.
BIN +2 Bytes (100%) dist/protobuf.min.js.gz
Binary file not shown.

Large diffs are not rendered by default.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
BIN -2 Bytes (100%) dist/runtime/protobuf.min.js.gz
Binary file not shown.
@@ -1,6 +1,6 @@
{
"name": "protobufjs",
"version": "6.4.0",
"version": "6.4.1",
"description": "Protocol Buffers for JavaScript (& TypeScript).",
"author": "Daniel Wirtz <dcode+protobufjs@dcode.io>",
"license": "BSD-3-Clause",
@@ -36,11 +36,9 @@ function create(type, ctor) {
if (typeof ctor !== "function")
throw TypeError("ctor must be a function");
} else
ctor = (function(MessageCtor) {
return function Message(properties) {
MessageCtor.call(this, properties);
};
})(Message);
ctor = util.codegen("p")("return ctor.call(this,p)").eof(type.name, {
ctor: Message
});
// Let's pretend...
ctor.constructor = Class;
@@ -97,6 +95,15 @@ Class.create = create;
// Static methods on Message are instance methods on Class and vice versa.
Class.prototype = Message;
/**
* Creates a message from a JSON object by converting strings and numbers to their respective field types.
* @name Class#from
* @function
* @param {Object.<string,*>} object JSON object
* @param {MessageConversionOptions} [options] Options
* @returns {Message} Message instance
*/
/**
* Encodes a message of this type.
* @name Class#encode
@@ -138,3 +145,13 @@ Class.prototype = Message;
* @param {Message|Object} message Message or plain object to verify
* @returns {?string} `null` if valid, otherwise the reason why it is not
*/
/**
* Converts an object or runtime message of this type.
* @name Class#convert
* @function
* @param {Message|Object} source Source object or runtime message
* @param {ConverterImpl} impl Converter implementation to use, i.e. {@link converters.json} or {@link converters.message}
* @param {Object.<string,*>} [options] Conversion options
* @returns {Message|Object} Converted object or runtime message
*/

0 comments on commit cba46c3

Please sign in to comment.