Skip to content

Commit

Permalink
Use base64 by default to represent binary data in JSON (affects assig…
Browse files Browse the repository at this point in the history
…nment and toRaw), see #191
  • Loading branch information
dcodeIO committed Oct 29, 2014
1 parent 518b372 commit 2dcaa5a
Show file tree
Hide file tree
Showing 37 changed files with 121 additions and 123 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "protobuf",
"description": "Protocol Buffers for JavaScript. Finally.",
"version": "3.7.0",
"version": "3.8.0",
"main": "dist/ProtoBuf.js",
"license": "Apache-2.0",
"homepage": "http://dcode.io/",
Expand Down
26 changes: 13 additions & 13 deletions dist/ProtoBuf.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
* @const
* @expose
*/
ProtoBuf.VERSION = "3.7.0";
ProtoBuf.VERSION = "3.8.0";

/**
* Wire types.
Expand Down Expand Up @@ -2139,33 +2139,33 @@
/**
* Clones a message object to a raw object.
* @param {*} obj Object to clone
* @param {boolean} includeBuffers Whether to include native buffer data or not
* @param {boolean} includeBinaryAsBase64 Whether to include binary data as base64 strings or not
* @returns {*} Cloned object
* @inner
*/
function cloneRaw(obj, includeBuffers) {
function cloneRaw(obj, includeBinaryAsBase64) {
var clone = {};
for (var i in obj)
if (obj.hasOwnProperty(i)) {
if (obj[i] === null || typeof obj[i] !== 'object')
clone[i] = obj[i];
else if (obj[i] instanceof ByteBuffer) {
if (includeBuffers)
clone[i] = obj.toBuffer();
if (includeBinaryAsBase64)
clone[i] = obj[i].toBase64();
} else // is a non-null object
clone[i] = cloneRaw(obj[i], includeBuffers);
clone[i] = cloneRaw(obj[i], includeBinaryAsBase64);
}
return clone;
}

/**
* Returns the message's raw payload.
* @param {boolean=} includeBuffers Whether to include native buffer data or not, defaults to `false`
* @param {boolean=} includeBinaryAsBase64 Whether to include binary data as base64 strings or not, defaults to `false`
* @returns {Object.<string,*>} Raw payload
* @expose
*/
MessagePrototype.toRaw = function(includeBuffers) {
return cloneRaw(this, !!includeBuffers);
MessagePrototype.toRaw = function(includeBinaryAsBase64) {
return cloneRaw(this, !!includeBinaryAsBase64);
};

/**
Expand Down Expand Up @@ -2723,9 +2723,9 @@

// Length-delimited bytes
case ProtoBuf.TYPES["bytes"]:
return value && value instanceof ByteBuffer
? value
: ByteBuffer.wrap(value);
if (ByteBuffer.isByteBuffer(value))
return value;
return ByteBuffer.wrap(value, "base64");

// Constant enum value
case ProtoBuf.TYPES["enum"]: {
Expand Down Expand Up @@ -4326,7 +4326,7 @@
return ProtoBuf;
}

/* CommonJS */ if (typeof require === 'function' && typeof module === 'object' && module && module.id && typeof exports === 'object' && exports)
/* CommonJS */ if (typeof require === 'function' && typeof module === 'object' && module && typeof exports === 'object' && exports)
module['exports'] = init(require("bytebuffer"));
/* AMD */ else if (typeof define === 'function' && define["amd"])
define(["ByteBuffer"], init);
Expand Down
58 changes: 29 additions & 29 deletions dist/ProtoBuf.min.js

Large diffs are not rendered by default.

Binary file modified dist/ProtoBuf.min.js.gz
Binary file not shown.
4 changes: 2 additions & 2 deletions dist/ProtoBuf.min.map

Large diffs are not rendered by default.

26 changes: 13 additions & 13 deletions dist/ProtoBuf.noparse.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
* @const
* @expose
*/
ProtoBuf.VERSION = "3.7.0";
ProtoBuf.VERSION = "3.8.0";

/**
* Wire types.
Expand Down Expand Up @@ -1227,33 +1227,33 @@
/**
* Clones a message object to a raw object.
* @param {*} obj Object to clone
* @param {boolean} includeBuffers Whether to include native buffer data or not
* @param {boolean} includeBinaryAsBase64 Whether to include binary data as base64 strings or not
* @returns {*} Cloned object
* @inner
*/
function cloneRaw(obj, includeBuffers) {
function cloneRaw(obj, includeBinaryAsBase64) {
var clone = {};
for (var i in obj)
if (obj.hasOwnProperty(i)) {
if (obj[i] === null || typeof obj[i] !== 'object')
clone[i] = obj[i];
else if (obj[i] instanceof ByteBuffer) {
if (includeBuffers)
clone[i] = obj.toBuffer();
if (includeBinaryAsBase64)
clone[i] = obj[i].toBase64();
} else // is a non-null object
clone[i] = cloneRaw(obj[i], includeBuffers);
clone[i] = cloneRaw(obj[i], includeBinaryAsBase64);
}
return clone;
}

/**
* Returns the message's raw payload.
* @param {boolean=} includeBuffers Whether to include native buffer data or not, defaults to `false`
* @param {boolean=} includeBinaryAsBase64 Whether to include binary data as base64 strings or not, defaults to `false`
* @returns {Object.<string,*>} Raw payload
* @expose
*/
MessagePrototype.toRaw = function(includeBuffers) {
return cloneRaw(this, !!includeBuffers);
MessagePrototype.toRaw = function(includeBinaryAsBase64) {
return cloneRaw(this, !!includeBinaryAsBase64);
};

/**
Expand Down Expand Up @@ -1811,9 +1811,9 @@

// Length-delimited bytes
case ProtoBuf.TYPES["bytes"]:
return value && value instanceof ByteBuffer
? value
: ByteBuffer.wrap(value);
if (ByteBuffer.isByteBuffer(value))
return value;
return ByteBuffer.wrap(value, "base64");

// Constant enum value
case ProtoBuf.TYPES["enum"]: {
Expand Down Expand Up @@ -3336,7 +3336,7 @@
return ProtoBuf;
}

/* CommonJS */ if (typeof require === 'function' && typeof module === 'object' && module && module.id && typeof exports === 'object' && exports)
/* CommonJS */ if (typeof require === 'function' && typeof module === 'object' && module && typeof exports === 'object' && exports)
module['exports'] = init(require("bytebuffer"));
/* AMD */ else if (typeof define === 'function' && define["amd"])
define(["ByteBuffer"], init);
Expand Down
Loading

0 comments on commit 2dcaa5a

Please sign in to comment.