Permalink
Browse files

Added Namespace#getEnum and changed #lookupEnum to the same behavior,…

… see #576
  • Loading branch information...
dcodeIO committed Dec 19, 2016
1 parent 7fac9d6 commit ef43acff547c0cd84cfb7a892fe94504a586e491
@@ -1,6 +1,6 @@
This license applies to all parts of protobuf.js except those files explicitly
including or referencing a different license or files located in a directory
containing a different LICENSE file.
This license applies to all parts of protobuf.js except those files either
explicitly including or referencing a different license or located in a
directory containing a different LICENSE file.
Apache License
Version 2.0, January 2004

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 +8 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.

Large diffs are not rendered by default.

Oops, something went wrong.

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -16,6 +16,7 @@ var Type, // cyclic
var nestedTypes, // contains cyclics
nestedError;
function initNested() {
/* istanbul ignore next */
@@ -163,6 +164,19 @@ NamespacePrototype.get = function get(name) {
return this.nested[name] || null;
};
/**
* Gets the values of the nested {@link Enum|enum} of the specified name.
* This methods differs from {@link Namespace#get} in that it returns an enum's values directly and throws instead of returning `null`.
* @param {string} name Nested enum name
* @returns {Object.<string,number>} Enum values
* @throws {Error} If there is no such enum
*/
NamespacePrototype.getEnum = function getEnum(name) {
if (this.nested && this.nested[name] instanceof Enum)
return this.nested[name].values;
throw Error("no such enum");
};
/**
* Adds a nested object to this namespace.
* @param {ReflectionObject} object Nested object to add
@@ -352,15 +366,15 @@ NamespacePrototype.lookupService = function lookupService(path) {
};
/**
* Looks up the {@link Enum|enum} at the specified path, relative to this namespace.
* Besides its signature, this methods differs from {@link Namespace#lookup} in that it throws instead of returning `null`.
* Looks up the values of the {@link Enum|enum} at the specified path, relative to this namespace.
* Besides its signature, this methods differs from {@link Namespace#lookup} in that it returns the enum's values directly and throws instead of returning `null`.
* @param {string|string[]} path Path to look up
* @returns {Type} Looked up enum
* @returns {Object.<string,number>} Enum values
* @throws {Error} If `path` does not point to an enum
*/
NamespacePrototype.lookupEnum = function lookupEnum(path) {
var found = this.lookup(path, Enum);
if (!found)
throw Error("no such enum");
return found;
return found.values;
};
@@ -50,8 +50,6 @@ function Op(fn, len, val) {
this.val = val; // type varies
}
Writer.Op = Op;
/* istanbul ignore next */
function noop() {} // eslint-disable-line no-empty-function
@@ -91,8 +89,6 @@ function State(writer) {
this.next = writer.states;
}
Writer.State = State;
/**
* Constructs a new writer instance.
* @classdesc Wire format writer using `Uint8Array` if available, otherwise `Array`.
@@ -159,7 +155,7 @@ Writer.alloc = function alloc(size) {
// Use Uint8Array buffer pool in the browser, just like node does with buffers
if (ArrayImpl !== Array)
Writer.alloc = util.pool(Writer.alloc, ArrayImpl.prototype.subarray || ArrayImpl.prototype.slice);
Writer.alloc = util.pool(Writer.alloc, ArrayImpl.prototype.subarray);
/** @alias Writer.prototype */
var WriterPrototype = Writer.prototype;
@@ -504,6 +500,6 @@ WriterPrototype.finish = function finish() {
pos += head.len;
head = head.next;
}
this.head = this.tail = null; // gc
// this.head = this.tail = null;
return buf;
};
@@ -34,7 +34,7 @@ BufferWriter.alloc = function alloc_buffer(size) {
})(size);
};
var writeBytesBuffer = Buffer && Buffer.from && Buffer.prototype.set.name !== "deprecated"
var writeBytesBuffer = Buffer && Buffer.from && Buffer.prototype.set.name[0] === "s" // node v4: set.name == "deprecated"
? function writeBytesBuffer_set(val, buf, pos) {
buf.set(val, pos); // faster than copy (requires node > 0.12)
}
@@ -1,5 +1,5 @@
// $> pbts --name protobufjs --out types/protobuf.js.d.ts src
// Generated Sun, 18 Dec 2016 22:48:04 UTC
// Generated Mon, 19 Dec 2016 12:17:04 UTC
declare module "protobufjs" {
/**
@@ -726,6 +726,15 @@ declare module "protobufjs" {
*/
get(name: string): ReflectionObject;
/**
* Gets the values of the nested {@link Enum|enum} of the specified name.
* This methods differs from {@link Namespace#get} in that it returns an enum's values directly and throws instead of returning `null`.
* @param {string} name Nested enum name
* @returns {Object.<string,number>} Enum values
* @throws {Error} If there is no such enum
*/
getEnum(name: string): { [k: string]: number };
/**
* Adds a nested object to this namespace.
* @param {ReflectionObject} object Nested object to add
@@ -797,13 +806,13 @@ declare module "protobufjs" {
lookupService(path: (string|string[])): Service;
/**
* Looks up the {@link Enum|enum} at the specified path, relative to this namespace.
* Besides its signature, this methods differs from {@link Namespace#lookup} in that it throws instead of returning `null`.
* Looks up the values of the {@link Enum|enum} at the specified path, relative to this namespace.
* Besides its signature, this methods differs from {@link Namespace#lookup} in that it returns the enum's values directly and throws instead of returning `null`.
* @param {string|string[]} path Path to look up
* @returns {Type} Looked up enum
* @returns {Object.<string,number>} Enum values
* @throws {Error} If `path` does not point to an enum
*/
lookupEnum(path: (string|string[])): Type;
lookupEnum(path: (string|string[])): { [k: string]: number };
}
/**

0 comments on commit ef43acf

Please sign in to comment.