///<summary> /// Write out contents of byte array b as a JSON string with base-64 encoded /// data ///</summary> private void WriteJSONBase64(byte[] b) { context.Write(); trans.Write(QUOTE); int len = b.Length; int off = 0; // Ignore padding int bound = len >= 2 ? len - 2 : 0; for (int i = len - 1; i >= bound && b[i] == '='; --i) { --len; } while (len >= 3) { // Encode 3 bytes at a time TBase64Utils.encode(b, off, 3, tempBuffer, 0); trans.Write(tempBuffer, 0, 4); off += 3; len -= 3; } if (len > 0) { // Encode remainder TBase64Utils.encode(b, off, len, tempBuffer, 0); trans.Write(tempBuffer, 0, len + 1); } trans.Write(QUOTE); }
/// <summary> /// Write out contents of byte array b as a JSON string with base-64 encoded /// data /// </summary> private void WriteJSONBase64(byte[] b) { context.Write(); trans.Write(QUOTE); int len = b.Length; int off = 0; while (len >= 3) { // Encode 3 bytes at a time TBase64Utils.encode(b, off, 3, tempBuffer, 0); trans.Write(tempBuffer, 0, 4); off += 3; len -= 3; } if (len > 0) { // Encode remainder TBase64Utils.encode(b, off, len, tempBuffer, 0); trans.Write(tempBuffer, 0, len + 1); } trans.Write(QUOTE); }
private void WriteJSONBase64(byte[] b) { this.context.Write(); this.trans.Write(TJSONProtocol.QUOTE); int length = (int)b.Length; int num = 0; while (length >= 3) { TBase64Utils.encode(b, num, 3, this.tempBuffer, 0); this.trans.Write(this.tempBuffer, 0, 4); num = num + 3; length = length - 3; } if (length > 0) { TBase64Utils.encode(b, num, length, this.tempBuffer, 0); this.trans.Write(this.tempBuffer, 0, length + 1); } this.trans.Write(TJSONProtocol.QUOTE); }