Jens Geyer | 7393862 | 2014-02-07 22:22:36 +0100 | [diff] [blame] | 1 | /**
|
| 2 | * Licensed to the Apache Software Foundation (ASF) under one
|
| 3 | * or more contributor license agreements. See the NOTICE file
|
| 4 | * distributed with this work for additional information
|
| 5 | * regarding copyright ownership. The ASF licenses this file
|
| 6 | * to you under the Apache License, Version 2.0 (the
|
| 7 | * "License"); you may not use this file except in compliance
|
| 8 | * with the License. You may obtain a copy of the License at
|
| 9 | *
|
| 10 | * http://www.apache.org/licenses/LICENSE-2.0
|
| 11 | *
|
| 12 | * Unless required by applicable law or agreed to in writing,
|
| 13 | * software distributed under the License is distributed on an
|
| 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 15 | * KIND, either express or implied. See the License for the
|
| 16 | * specific language governing permissions and limitations
|
| 17 | * under the License.
|
| 18 | */
|
| 19 |
|
| 20 | using System;
|
| 21 | using System.Collections.Generic;
|
| 22 | using System.Diagnostics;
|
| 23 | using System.IO;
|
| 24 | using System.Linq;
|
| 25 | using System.Text;
|
| 26 | using Thrift.Protocol;
|
| 27 | using Thrift.Transport;
|
| 28 |
|
| 29 | namespace JSONTest
|
| 30 | {
|
| 31 | class Program
|
| 32 | {
|
| 33 | static void Main(string[] args)
|
| 34 | {
|
| 35 | TestThrift2336();
|
| 36 | }
|
| 37 |
|
| 38 | public static void TestThrift2336()
|
| 39 | {
|
| 40 | const string RUSSIAN_TEXT = "\u0420\u0443\u0441\u0441\u043a\u043e\u0435 \u041d\u0430\u0437\u0432\u0430\u043d\u0438\u0435";
|
| 41 | const string RUSSIAN_JSON = "\"\\u0420\\u0443\\u0441\\u0441\\u043a\\u043e\\u0435 \\u041d\\u0430\\u0437\\u0432\\u0430\\u043d\\u0438\\u0435\"";
|
| 42 |
|
| 43 | // prepare buffer with JOSN data
|
| 44 | byte[] rawBytes = new byte[RUSSIAN_JSON.Length];
|
| 45 | for (var i = 0; i < RUSSIAN_JSON.Length; ++i)
|
| 46 | rawBytes[i] = (byte)(RUSSIAN_JSON[i] & (char)0xFF); // only low bytes
|
| 47 |
|
| 48 | // parse and check
|
| 49 | var stm = new MemoryStream(rawBytes);
|
| 50 | var trans = new TStreamTransport(stm, null);
|
| 51 | var prot = new TJSONProtocol(trans);
|
| 52 | Debug.Assert(prot.ReadString() == RUSSIAN_TEXT, "reading JSON with hex-encoded chars > 8 bit");
|
| 53 | }
|
| 54 | }
|
| 55 | }
|