コード例 #1
0
ファイル: TJSONProtocol.cs プロジェクト: cica0/SourceCode
        ///<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);
        }
コード例 #2
0
        /// <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);
        }
コード例 #3
0
ファイル: TJSONProtocol.cs プロジェクト: noahvans/HiveThrift
        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);
        }