Skip to content

Commit

Permalink
Added Message#asJSON option for bytes conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
dcodeIO committed Dec 12, 2016
1 parent ce41d0e commit 52cd8b5
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 26 deletions.
11 changes: 9 additions & 2 deletions dist/protobuf.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/protobuf.js.map

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions dist/protobuf.min.js

Large diffs are not rendered by default.

Binary file modified dist/protobuf.min.js.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion dist/protobuf.min.js.map

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
"long": "^3.2.0"
},
"devDependencies": {
"@types/long": "^3.0.31",
"@types/node": "0.0.3",
"benchmark": "^2.1.2",
"browserify": "^13.1.1",
"bundle-collapser": "^1.2.1",
Expand All @@ -69,7 +71,7 @@
"tap-spec": "^4.1.1",
"tape": "^4.6.3",
"tsd-jsdoc": "dcodeIO/tsd-jsdoc",
"typescript": "^2.2.0-dev.20161202",
"typescript": "^2.2.0-dev.20161212",
"vinyl-buffer": "^1.0.0",
"vinyl-fs": "^2.4.4",
"vinyl-source-stream": "^1.1.0",
Expand Down
16 changes: 0 additions & 16 deletions scripts/minimal-env.js

This file was deleted.

6 changes: 5 additions & 1 deletion src/field.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,11 @@ FieldPrototype.jsonConvert = function(value, options) {
? typeof value === "number"
? value
: util.Long.fromValue(value).toNumber()
: util.Long.fromValue(value, this.type.charAt(0) === "u").toString();
: util.Long.fromValue(value, this.type.charAt(0) === "u").toString()
else if (options.bytes && this.type === "bytes")
return options.bytes === Array
? Array.prototype.slice.call(value)
: util.base64.encode(value, 0, value.length);
}
return value;
};
3 changes: 3 additions & 0 deletions src/message.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ var MessagePrototype = Message.prototype;
* @param {*} [options.enum=Number] Enum value conversion type.
* Valid values are `String` and `Number` (the global types).
* Defaults to the numeric ids.
* @param {*} [options.bytes] Bytes value conversion type.
* Valid values are `Array` and `String` (the global types).
* Defaults to return the underlying buffer type.
* @param {boolean} [options.defaults=false] Also sets default values on the resulting object
* @returns {Object.<string,*>} JSON object
*/
Expand Down
5 changes: 4 additions & 1 deletion types/protobuf.js.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* protobuf.js v6.1.0 TypeScript definitions
* Generated Mon, 12 Dec 2016 22:50:39 UTC
* Generated Mon, 12 Dec 2016 23:18:49 UTC
*/
declare module "protobufjs" {

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

0 comments on commit 52cd8b5

Please sign in to comment.