Skip to content

Commit 52cd8b5

Browse files
committed
Added Message#asJSON option for bytes conversion
1 parent ce41d0e commit 52cd8b5

File tree

10 files changed

+29
-26
lines changed

10 files changed

+29
-26
lines changed

dist/protobuf.js

Lines changed: 9 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/protobuf.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/protobuf.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/protobuf.min.js.gz

46 Bytes
Binary file not shown.

dist/protobuf.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@
5050
"long": "^3.2.0"
5151
},
5252
"devDependencies": {
53+
"@types/long": "^3.0.31",
54+
"@types/node": "0.0.3",
5355
"benchmark": "^2.1.2",
5456
"browserify": "^13.1.1",
5557
"bundle-collapser": "^1.2.1",
@@ -69,7 +71,7 @@
6971
"tap-spec": "^4.1.1",
7072
"tape": "^4.6.3",
7173
"tsd-jsdoc": "dcodeIO/tsd-jsdoc",
72-
"typescript": "^2.2.0-dev.20161202",
74+
"typescript": "^2.2.0-dev.20161212",
7375
"vinyl-buffer": "^1.0.0",
7476
"vinyl-fs": "^2.4.4",
7577
"vinyl-source-stream": "^1.1.0",

scripts/minimal-env.js

Lines changed: 0 additions & 16 deletions
This file was deleted.

src/field.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,11 @@ FieldPrototype.jsonConvert = function(value, options) {
266266
? typeof value === "number"
267267
? value
268268
: util.Long.fromValue(value).toNumber()
269-
: util.Long.fromValue(value, this.type.charAt(0) === "u").toString();
269+
: util.Long.fromValue(value, this.type.charAt(0) === "u").toString()
270+
else if (options.bytes && this.type === "bytes")
271+
return options.bytes === Array
272+
? Array.prototype.slice.call(value)
273+
: util.base64.encode(value, 0, value.length);
270274
}
271275
return value;
272276
};

src/message.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ var MessagePrototype = Message.prototype;
3333
* @param {*} [options.enum=Number] Enum value conversion type.
3434
* Valid values are `String` and `Number` (the global types).
3535
* Defaults to the numeric ids.
36+
* @param {*} [options.bytes] Bytes value conversion type.
37+
* Valid values are `Array` and `String` (the global types).
38+
* Defaults to return the underlying buffer type.
3639
* @param {boolean} [options.defaults=false] Also sets default values on the resulting object
3740
* @returns {Object.<string,*>} JSON object
3841
*/

types/protobuf.js.d.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* protobuf.js v6.1.0 TypeScript definitions
3-
* Generated Mon, 12 Dec 2016 22:50:39 UTC
3+
* Generated Mon, 12 Dec 2016 23:18:49 UTC
44
*/
55
declare module "protobufjs" {
66

@@ -508,6 +508,9 @@ declare module "protobufjs" {
508508
* @param {*} [options.enum=Number] Enum value conversion type.
509509
* Valid values are `String` and `Number` (the global types).
510510
* Defaults to the numeric ids.
511+
* @param {*} [options.bytes] Bytes value conversion type.
512+
* Valid values are `Array` and `String` (the global types).
513+
* Defaults to return the underlying buffer type.
511514
* @param {boolean} [options.defaults=false] Also sets default values on the resulting object
512515
* @returns {Object.<string,*>} JSON object
513516
*/

0 commit comments

Comments
 (0)