blob: 7bdb7f5f2c6277c872b05187a1792fa5f88e3e1d [file] [log] [blame]
Jens Geyer73938622014-02-07 22:22:36 +01001/**
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
20using System;
21using System.Collections.Generic;
22using System.Diagnostics;
23using System.IO;
24using System.Linq;
25using System.Text;
26using Thrift.Protocol;
27using Thrift.Transport;
28
29namespace 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}