THRIFT-3200 JS and nodejs do not encode JSON protocol binary fields as base64
Client: Javascript
Patch: Nobuaki Sukegawa
This closes #698
diff --git a/lib/js/src/thrift.js b/lib/js/src/thrift.js
index 9bd1198..664171e 100644
--- a/lib/js/src/thrift.js
+++ b/lib/js/src/thrift.js
@@ -1006,8 +1006,19 @@
},
/** Serializes a string */
- writeBinary: function(str) {
- this.writeString(str);
+ writeBinary: function(binary) {
+ var str = '';
+ if (typeof binary == 'string') {
+ str = binary;
+ } else if (binary instanceof Uint8Array) {
+ var arr = binary;
+ for (var i = 0; i < arr.length; ++i) {
+ str += String.fromCharCode(arr[i]);
+ }
+ } else {
+ throw new TypeError('writeBinary only accepts String or Uint8Array.');
+ }
+ this.tstack.push('"' + btoa(str) + '"');
},
/**
@@ -1309,7 +1320,9 @@
/** Returns the an object with a value property set to the
next value found in the protocol buffer */
readBinary: function() {
- return this.readString();
+ var r = this.readI32();
+ r.value = atob(r.value);
+ return r;
},
/**