public void ProcessRequest(Stream input, Stream output) { TTransport transport = new TStreamTransport(input,output); TProtocol inputProtocol = null; TProtocol outputProtocol = null; try { inputProtocol = inputProtocolFactory.GetProtocol(transport); outputProtocol = outputProtocolFactory.GetProtocol(transport); while (processor.Process(inputProtocol, outputProtocol)) { } } catch (TTransportException) { // Client died, just move on } catch (TApplicationException tx) { Console.Error.Write(tx); } catch (Exception x) { Console.Error.Write(x); } transport.Close(); }
public override void Map(string inputLine, MapperContext context) { var delivery = new Delivery(); double result = 0.0; context.Log("MAPPER:::START"); context.Log(inputLine); context.Log("UTF-8: " + Encoding.UTF8.GetBytes(inputLine).Length); context.Log("ASCII: " + Encoding.ASCII.GetBytes(inputLine).Length); // Read the incoming string as a Thrift Binary serialized object var inputStream = new MemoryStream(Encoding.UTF8.GetBytes(inputLine)); using (var transport = new TStreamTransport(inputStream, null)) { delivery.Read(new TBinaryProtocol(transport)); context.Log("MAPPER:::AFTER_READ"); // Get the driven kilometers from the vehicle's odometer sensor var sensorData = delivery.Vehicle.SensorHistory; var minOdo = sensorData.Min(d => d.OdoMeter); var maxOdo = sensorData.Max(d => d.OdoMeter); result = maxOdo - minOdo; context.Log("MAPPER:::BEFORE_STREAM_CLOSE"); } context.Log("MAPPER:::AFTER_STREAM_CLOSE"); // Emit the vehicle id, and the driven kilometers. if (result > 0.1) { context.EmitKeyValue(delivery.Vehicle.VehicleId, result.ToString(CultureInfo.InvariantCulture)); } context.Log("MAPPER:::END"); }
private ThriftMsgSerialize() { TStreamTransport serializeTransport = new TStreamTransport(null, OUTPUT_STREAM); SERIALIZE_PROTOCOL = new TCompactProtocol(serializeTransport); TStreamTransport deserializeTransport = new TStreamTransport(INPUT_STREAM, null); DESERIALIZE_PROTOCOL = new TCompactProtocol(deserializeTransport); }
public static long Serialize(TBase message, ref byte[] buffer, int offset) { MemoryStream outputStream = new MemoryStream(buffer, offset, buffer.Length - offset); TStreamTransport transport = new TStreamTransport(null, outputStream); TBinaryProtocol binaryProtocol = new TBinaryProtocol(transport); message.Write(binaryProtocol); return outputStream.Position; }
public static void DeSerialize(TBase tbase, byte[] bytes) { if (tbase == null || bytes == null) { return; } using (Stream inputStream = new MemoryStream(64)) { inputStream.Write(bytes, 0, bytes.Length); inputStream.Position = 0; TStreamTransport transport = new TStreamTransport(inputStream, null); TProtocol protocol = new TCompactProtocol(transport); tbase.Read(protocol); } }
public static void TestThrift2336() { const string RUSSIAN_TEXT = "\u0420\u0443\u0441\u0441\u043a\u043e\u0435 \u041d\u0430\u0437\u0432\u0430\u043d\u0438\u0435"; const string RUSSIAN_JSON = "\"\\u0420\\u0443\\u0441\\u0441\\u043a\\u043e\\u0435 \\u041d\\u0430\\u0437\\u0432\\u0430\\u043d\\u0438\\u0435\""; // prepare buffer with JSON data byte[] rawBytes = new byte[RUSSIAN_JSON.Length]; for (var i = 0; i < RUSSIAN_JSON.Length; ++i) rawBytes[i] = (byte)(RUSSIAN_JSON[i] & (char)0xFF); // only low bytes // parse and check var stm = new MemoryStream(rawBytes); var trans = new TStreamTransport(stm, null); var prot = new TJSONProtocol(trans); Debug.Assert(prot.ReadString() == RUSSIAN_TEXT, "reading JSON with hex-encoded chars > 8 bit"); }
public static byte[] Serialize(TBase tbase) { if (tbase == null) { return null; } using (Stream outputStream = new MemoryStream(64)) { TStreamTransport transport = new TStreamTransport(null, outputStream); TProtocol protocol = new TCompactProtocol(transport); tbase.Write(protocol); byte[] bytes = new byte[outputStream.Length]; outputStream.Position = 0; outputStream.Read(bytes, 0, bytes.Length); return bytes; } }
internal static object Deserialize(string ClientFunction, byte[] data) { MemoryStream serialstream = new MemoryStream(data); TTransport transport = new TStreamTransport(serialstream, serialstream); transport.Open(); TProtocol protocol = new TCompactProtocol(transport); TalkService.Client Client = new TalkService.Client(protocol); MethodInfo CallingFunction = Client.GetType().GetMethod(ClientFunction); try { return CallingFunction.Invoke(Client, null); } catch (TargetInvocationException E) { if (E.InnerException is TalkException) { throw E.InnerException; } } return null; }
internal static byte[] SerializeOperation(Operation O) { var serialstream = new MemoryStream(4096); TTransport transport = new TStreamTransport(serialstream, serialstream); transport.Open(); TProtocol protocol = new TCompactProtocol(transport); var client = new TalkService.Client(protocol); //.MakeGenericMethod( //hook.Invoke(Client, parameters); O.Write(protocol); byte[] data = serialstream.ToArray(); //MemoryStream serialstream = new MemoryStream(4096); //TTransport transport = new TStreamTransport(serialstream, serialstream); transport.Open(); return data; }
//This shit only exists because the internal LINE client transport doesn't handle //more than a single connection at a time, so if it was being used for long polling, //we'd be f****d because it would probably freeze the entire thing and prevent any //other calls from happening. It's not something I'm proud to have written but it //works wonders if you need to call something in parallel. It's just expensive. :O internal static byte[] Serialize(string clientFunction, object[] parameters) { var serialstream = new MemoryStream(4096); TTransport transport = new TStreamTransport(serialstream, serialstream); transport.Open(); TProtocol protocol = new TCompactProtocol(transport); var client = new TalkService.Client(protocol); //.MakeGenericMethod( //hook.Invoke(Client, parameters); MethodInfo callingFunction = client.GetType().GetMethod(clientFunction); callingFunction.Invoke(client, parameters); byte[] data = serialstream.ToArray(); //MemoryStream serialstream = new MemoryStream(4096); //TTransport transport = new TStreamTransport(serialstream, serialstream); transport.Open(); return data; }
public override async Task ProcessRequestAsync(HttpContext context) { var transport = new TStreamTransport(context.Request.InputStream, context.Response.OutputStream); try { var input = _inputProtocolFactory.GetProtocol(transport); var output = _outputProtocolFactory.GetProtocol(transport); while (await _processor.ProcessAsync(input, output)) { } } catch (TTransportException) { // Client died, just move on } finally { transport.Close(); } }
public void ProcessRequest(Stream input, Stream output) { TTransport transport = new TStreamTransport(input,output); try { var inputProtocol = inputProtocolFactory.GetProtocol(transport); var outputProtocol = outputProtocolFactory.GetProtocol(transport); while (processor.Process(inputProtocol, outputProtocol)) { } } catch (TTransportException) { // Client died, just move on } finally { transport.Close(); } }
public void ProcessRequest(Stream input, Stream output) { TTransport transport = new TStreamTransport(input, output); try { var inputProtocol = inputProtocolFactory.GetProtocol(transport); var outputProtocol = outputProtocolFactory.GetProtocol(transport); while (processor.Process(inputProtocol, outputProtocol)) { } } catch (TTransportException) { // Client died, just move on } finally { transport.Close(); } }
public override async Task ProcessRequestAsync(HttpContext context) { var transport = new TStreamTransport(context.Request.InputStream, context.Response.OutputStream); try { var input = _inputProtocolFactory.GetProtocol(transport); var output = _outputProtocolFactory.GetProtocol(transport); while (await _processor.ProcessAsync(input, output)) { } } catch (TTransportException) { // Client died, just move on } finally { transport.Close(); } }
public static void TestThrift2365() { var rnd = new Random(); for (var len = 0; len < 10; ++len) { byte[] dataWritten = new byte[len]; rnd.NextBytes(dataWritten); Stream stm = new MemoryStream(); TTransport trans = new TStreamTransport(null, stm); TProtocol prot = new TJSONProtocol(trans); prot.WriteBinary(dataWritten); stm.Position = 0; trans = new TStreamTransport(stm, null); prot = new TJSONProtocol(trans); byte[] dataRead = prot.ReadBinary(); Debug.Assert(dataRead.Length == dataWritten.Length); for (var i = 0; i < dataRead.Length; ++i) Debug.Assert(dataRead[i] == dataWritten[i]); } }
internal static object Deserialize(string clientFunction, byte[] data) { var serialstream = new MemoryStream(data); TTransport transport = new TStreamTransport(serialstream, serialstream); transport.Open(); TProtocol protocol = new TCompactProtocol(transport); var client = new TalkService.Client(protocol); MethodInfo callingFunction = client.GetType().GetMethod(clientFunction); //Magic to redirect the possible exception to the end user's code //or at least the nearest TalkException catch try { return callingFunction.Invoke(client, null); } catch (TargetInvocationException E) { if (E.InnerException is TalkException) { throw E.InnerException; } } return null; }
public async Task Run(string sendAddress, string sendToken) { try { var relayClient = new RelayClient(sendAddress, TokenProvider.CreateSharedAccessSignatureTokenProvider(sendToken)); var relayConnection = relayClient.Connect(); TTransport transport = new TStreamTransport(relayConnection, relayConnection); TProtocol protocol = new TBinaryProtocol(transport); Calculator.Client client = new Calculator.Client(protocol); transport.Open(); try { client.ping(); Console.WriteLine("ping()"); int sum = client.add(1, 1); Console.WriteLine("1+1={0}", sum); Work work = new Work(); work.Op = Operation.DIVIDE; work.Num1 = 1; work.Num2 = 0; try { int quotient = client.calculate(1, work); Console.WriteLine("Whoa we can divide by 0"); } catch (InvalidOperation io) { Console.WriteLine("Invalid operation: " + io.Why); } work.Op = Operation.SUBTRACT; work.Num1 = 15; work.Num2 = 10; try { int diff = client.calculate(1, work); Console.WriteLine("15-10={0}", diff); } catch (InvalidOperation io) { Console.WriteLine("Invalid operation: " + io.Why); } SharedStruct log = client.getStruct(1); Console.WriteLine("Check log: {0}", log.Value); } finally { transport.Close(); } } catch (TApplicationException x) { Console.WriteLine(x.StackTrace); } }
static void TestSearilize() { MemoryStream inStream = new MemoryStream(); MemoryStream outStream = new MemoryStream(); var streamTrans = new Thrift.Transport.TStreamTransport(inStream, outStream); var jsonProto = new Thrift.Protocol.TJSONProtocol(streamTrans); var obj = CreateTestReserve(0); obj.Write(jsonProto); byte[] buffer = new byte[outStream.Length]; outStream.Position = 0; outStream.Read(buffer, 0, buffer.Length); using (FileStream fs = new FileStream(".\\1.json", FileMode.Create, FileAccess.Write)) { fs.Write(buffer, 0, buffer.Length); } inStream.Close(); outStream.Close(); }
public static void TestThrift3403() { string GCLEF_TEXT = "\ud834\udd1e"; const string GCLEF_JSON = "\"\\ud834\\udd1e\""; // parse and check var stm = new MemoryStream(Encoding.UTF8.GetBytes(GCLEF_JSON)); var trans = new TStreamTransport(stm, null); var prot = new TJSONProtocol(trans); Debug.Assert(prot.ReadString() == GCLEF_TEXT, "reading JSON with surrogate pair hex-encoded chars"); }
public TBufferedTransport(TStreamTransport transport, int bufSize) { this.bufSize = bufSize; this.transport = transport; InitBuffers(); }
public TBufferedTransport(TStreamTransport transport) :this(transport, 1024) { }
public TBufferedTransport(TStreamTransport transport, int bufSize) { this.bufSize = bufSize; this.transport = transport; this.InitBuffers(); }
public TBufferedTransport(TStreamTransport transport) : this(transport, 1024) { }
public static void Deserialize(byte[] buffer, TBase message) { MemoryStream inputStream = new MemoryStream(buffer); TStreamTransport transport = new TStreamTransport(inputStream, null); TBinaryProtocol binaryProtocol = new TBinaryProtocol(transport); message.Read(binaryProtocol); }