public static TCompactProtocol CompactProtocolForPayload(Byte[] payload, int offset = 1) { var inStream = new MemoryStream(payload, offset, payload.Length - offset); var tProto = new TCompactProtocol(new TStreamTransport(inStream, inStream)); return(tProto); }
public static T FromBytes(byte[] bytes) { TMemoryBuffer trans = new TMemoryBuffer(bytes); TProtocol prot = new TCompactProtocol(trans); return(Proto <T> .Read(prot)); }
/// <summary> /// Make a complete payload from <see cref="FbnsConnectionData"/> using Thrift. /// </summary> /// <returns>Payload</returns> public static async Task <IByteBuffer> BuildPayload(FbnsConnectionData data) { _memoryBufferTransport = new TMemoryBufferTransport(); _thrift = new TCompactProtocol(_memoryBufferTransport); _payloadData = data; var rawPayload = await ToThrift(); // zlib deflate var dataStream = new MemoryStream(512); using (var zlibStream = new ZlibStream(dataStream, CompressionMode.Compress, CompressionLevel.Level9, true)) { await zlibStream.WriteAsync(rawPayload, 0, rawPayload.Length); } var readData = new byte[dataStream.Length]; dataStream.Position = 0; await dataStream.ReadAsync(readData, 0, readData.Length); dataStream.Dispose(); var compressed = Unpooled.CopiedBuffer(readData); return(compressed); }
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 void GlobalSetup() { _Stream = new MemoryStream(); var transport = new TStreamTransport(_Stream, _Stream, null); _Protocol = new TCompactProtocol(transport); }
static void Main(string[] args) { TTransport trans = new TNamedPipeClientTransport("TradeStream"); trans.Open(); TProtocol proto = new TCompactProtocol(trans); PNWF.TradeStream.Client client = new PNWF.TradeStream.Client(proto); try { for (int i = 0; i < 100; i++) { List <PNWF.Trade> trades = client.GetNextTrade(""); foreach (PNWF.Trade trade in trades) { Console.Out.WriteLine(trade.Date_time.Hour.ToString("D2") + ":" + trade.Date_time.Minute.ToString("D2") + ":" + trade.Date_time.Second.ToString("D2") + " " + trade.Fish + "-" + trade.Market.ToString() + " " + trade.Price); } } } catch (TTransportException ex) { Console.WriteLine("Exception: " + ex.Message); } }
public override long Send(IList <ILogEntity> logEntities) { if (logEntities == null || logEntities.Count <= 0) { return(0); } TLogPackage logPackage = this.CreateLogPackage(logEntities); var trans = new THttpClient(uri); trans.ConnectTimeout = SENDER_TIMEOUT; trans.DataSizeLimit = TransDataSizeLimit; //var protocol = new TBinaryProtocol(httpClient); var protocol = new TCompactProtocol(trans); trans.Open(); var client = new LogTransferService.Client(protocol); client.Log(logPackage); long data_size = trans.DataSize; trans.Close(); return(data_size); }
public byte[] Pack() { stream = new MemoryStream(); if (transport == null) { transport = new TStreamTransport(null, stream); } else { transport.OutputStream = stream; } if (protocol == null) { protocol = new TCompactProtocol(transport); } else { protocol.reset(); protocol.Transport = transport; } protocol.WriteStructBegin(struc); fieldWriter.Name = "context"; fieldWriter.Type = TType.Map; fieldWriter.ID = 1; protocol.WriteFieldBegin(fieldWriter); { protocol.WriteMapBegin(new TMap(TType.String, TType.Struct, context.Count)); foreach (string _iter44 in context.Keys) { protocol.WriteString(_iter44); context[_iter44].Write(fieldWriter, protocol); } protocol.WriteMapEnd(); } protocol.WriteFieldEnd(); fieldWriter.Name = "events"; fieldWriter.Type = TType.Map; fieldWriter.ID = 2; protocol.WriteFieldBegin(fieldWriter); { protocol.WriteMapBegin(new TMap(TType.String, TType.Struct, events.Count)); foreach (string _iter44 in events.Keys) { protocol.WriteString(_iter44); events[_iter44].Write(fieldWriter, protocol); } protocol.WriteMapEnd(); } protocol.WriteFieldEnd(); protocol.WriteFieldStop(); protocol.WriteStructEnd(); return(stream.ToArray()); }
next() { message_wrapper rv = null; amqp_msg = (BasicDeliverEventArgs)consumer.Queue.Dequeue(); if (amqp_msg.Body.Length != 0) { MemoryStream stream = new MemoryStream(amqp_msg.Body); var proto = new TCompactProtocol(new TStreamTransport(stream, stream)); int delta_stream_id = (int)proto.ReadI32(); bool read_in_delta_mode; if (delta_stream_id < 0) { read_in_delta_mode = false; delta_stream_id = -delta_stream_id; } else { read_in_delta_mode = true; } uint type_id = (uint)proto.ReadI32(); Dictionary <uint, Dictionary <int, message_wrapper> > old_subject = null; if (!previous_messages.TryGetValue(amqp_msg.RoutingKey, out old_subject)) { var deltas = new Dictionary <int, message_wrapper>(); deltas[delta_stream_id] = new message_wrapper(message_factory.from_type_id(type_id)); old_subject = new Dictionary <uint, Dictionary <int, message_wrapper> >(); old_subject[type_id] = deltas; previous_messages[amqp_msg.RoutingKey] = old_subject; } Dictionary <int, message_wrapper> old_type_id = null; if (!old_subject.TryGetValue(type_id, out old_type_id)) { var deltas = new Dictionary <int, message_wrapper>(); deltas[delta_stream_id] = new message_wrapper(message_factory.from_type_id(type_id)); old_subject[type_id] = deltas; } if (!old_type_id.TryGetValue(delta_stream_id, out rv)) { old_type_id[delta_stream_id] = rv = new message_wrapper(message_factory.from_type_id(type_id)); } rv.msg.read_in_delta_mode = read_in_delta_mode; if (rv.non_delta_seen == false && read_in_delta_mode == false) { rv.non_delta_seen = true; } rv.msg.Read(proto); } return(rv); }
public static byte[] ToBytes(T value) { TMemoryBuffer trans = new TMemoryBuffer(); TProtocol prot = new TCompactProtocol(trans); Proto <T> .Write(prot, value); return(trans.GetBuffer()); }
public async static void startClient() { TTransport transport = null; try { string ip = "127.0.0.1"; string port = "6667"; string username = "******"; string password = "******"; // Make socket transport = new TSocketTransport(ip, int.Parse(port)); if (!transport.IsOpen) { await transport.OpenAsync(); } TProtocol protocol = new TCompactProtocol(transport); TSIService.Client client = new TSIService.Client(protocol); var result = await client.openSessionAsync(new TSOpenSessionReq() { Client_protocol = TSProtocolVersion.IOTDB_SERVICE_PROTOCOL_V2, Username = username, Password = password }); //await client.testInsertTabletAsync(new TSInsertTabletReq() //{ // DeviceId = "11", // Measurements = new System.Collections.Generic.List<string>() // { // "001" // }, // SessionId = result.SessionId, // Size = 10, // Timestamps =new byte[] { Convert.ToByte(DateTime.Now) }, // Values = new byte[] { Convert.ToByte(2.33d) } //}); Console.WriteLine("Thrift client result =: " + result.SessionId); } catch (Exception e) { Console.WriteLine(e.StackTrace); } finally { if (null != transport) { //close transport.Close(); } } }
public static byte[] Serialize(TAbstractBase s) { var t = new TMemoryBuffer(); var p = new TCompactProtocol(t); s.Write(p); return(t.GetBuffer()); }
public static T Deserialize <T>(byte[] buffer) where T : new() { using (TMemoryBuffer trans = new TMemoryBuffer(buffer)) { TProtocol proto = new TCompactProtocol(trans); TBase deserialized = (TBase) new T(); deserialized.Read(proto); return((T)deserialized); } }
protected RjdbcService.Client start(string server, int port) { RjdbcService.Client client; TSocket socket = new TSocket(server, port); TProtocol protocol = new TCompactProtocol(socket); client = new RjdbcService.Client(protocol); socket.Open(); return(client); }
private TProtocol getTProtocol(string ipAddress, int port, int timeout) { TSocket socketTransport = new TSocket(ipAddress, port, timeout); mTransport = new TFramedTransport(socketTransport); TProtocol protocol = new TCompactProtocol(mTransport); mTransport.Open(); return(protocol); }
publish(string topic_name, message_base msg, bool send_as_delta = false, int delta_stream_id = 1, long message_sequence_number = 0, long micros_since_epoch = 0) { if (delta_stream_id < 1) { throw new ArgumentException("delta_stream_id must be greater than 0"); } stream = new MemoryStream(); var proto = new TCompactProtocol(new TStreamTransport(stream, stream)); if (send_as_delta == false) { msg.set_modified_flag(); delta_stream_id = -delta_stream_id; } proto.WriteI32(delta_stream_id); proto.WriteI32((int)msg.get_type_id()); msg.Write(proto); IModel channel; if (!publishing_channels.TryGetValue(topic_name, out channel)) { channel = conn.CreateModel(); if (props == null) { props = channel.CreateBasicProperties(); } publishing_channels[topic_name] = channel; } // publishing_channel.QueueDeclare(topic_name, false, false, false, null); // not too fast at the moment (bare bones example), TODO later will set topic_name elsewhere so as not to resend it everytime // explicit since epoch in microseconds time for the server's requirements if (micros_since_epoch != 0 && message_sequence_number != 0) { var dictionary = new Dictionary <string, object>(); dictionary.Add("XXXXXX", message_sequence_number); props.ContentType = "X"; props.Headers = dictionary; props.Timestamp = new AmqpTimestamp(micros_since_epoch); channel.BasicPublish("", topic_name, props, stream.ToArray()); } else { channel.BasicPublish("", topic_name, null, stream.ToArray()); } msg.clear_modified_flag(); //Console.WriteLine("thrift size: " + stream.Length); //Console.WriteLine("thrift size: " + stream.ToArray().Length.ToString()); }
public byte[] ThriftCompact() { using (var stream = new MemoryStream()) { TProtocol tProtocol = new TCompactProtocol(new TStreamTransport(stream, stream)); this.thriftObject.Write(tProtocol); return(stream.ToArray()); } }
public ThriftClient(TSocket tSocket, Type clientType) { Host = tSocket.Host; Port = tSocket.Port; IsUse = false; IsAvailable = true; TCompactProtocol protocol = new TCompactProtocol(tSocket); object[] args = new object[] { protocol }; Client = (IDisposable)Activator.CreateInstance(clientType, args); }
public StreamBuffer GetStream() { TMemoryBuffer membuf = new TMemoryBuffer(); TCompactProtocol protocal = new TCompactProtocol(membuf); Write(protocal); byte[] buf = membuf.GetBuffer(); StreamBuffer stream = new StreamBuffer((int)_messageId, buf); return(stream); }
public override T Deserialize(dynamic bytes) { using (var ms = new MemoryStream(bytes)) { var tproto = new TCompactProtocol(new TStreamTransport(ms, ms)); ReuseDeserObj.Read(tproto); DoCopyIfNotCheating(ReuseDeserObj); } return(RegenAppObj); }
public static byte[] SerializeGetBytes(object value) { using (TMemoryBuffer trans = new TMemoryBuffer()) { TProtocol proto = new TCompactProtocol(trans); TBase trade = (TBase)value; trade.Write(proto); byte[] bytes = trans.GetBuffer(); return(bytes); } }
public override void Test(UpdateDelegate action) { TTransport transport = new TSocket(m_Ip, 7915); TProtocol protocol = new TCompactProtocol(transport); PrintServices.Client client = new PrintServices.Client(protocol); m_StrTransport = "TSocket"; m_StrProtocol = "TProtocolCompact"; HandleAdd(transport, client, action); }
public static T Deserialize <T>(Stream stream) where T : TBase, new() { using (var thriftTransport = new TStreamTransport(stream, null)) { var binaryProtocol = new TCompactProtocol(thriftTransport); var person = new T(); person.Read(binaryProtocol); return((T)person); } }
public static Stream Serialize(object value) { using (TMemoryBuffer trans = new TMemoryBuffer()) { TProtocol proto = new TCompactProtocol(trans); TBase trade = (TBase)value; trade.Write(proto); byte[] bytes = trans.GetBuffer(); var memoryStream = new MemoryStream(bytes); return(memoryStream); } }
public override dynamic Serialize(object thisObj) { DoCopyIfNotCheating((T)thisObj); using (var ms = new MemoryStream()) { var tproto = new TCompactProtocol(new TStreamTransport(ms, ms)); CodeGenObjSer.Write(tproto); SerBytes = ms.ToArray(); } return(SerBytes); }
public static ProtoBase ConstructThriftProto(StreamBuffer sb) { MessageId messageId = (MessageId)sb.m_protocolHeader.ProtocolID; if (s_protoConstructorDic.ContainsKey(messageId)) { TMemoryBuffer membuf = new TMemoryBuffer(sb.ByteBuffer); TCompactProtocol inProto = new TCompactProtocol(membuf); ProtoBase proto = s_protoConstructorDic[messageId].Invoke(inProto); return(proto); } return(null); }
public ThriftClient(string host, int port) { if (host == null) { throw new ArgumentNullException("host"); } _transport = new TFramedTransport(new TSocket(host, port)); TProtocol protocol = new TCompactProtocol(_transport); _client = new ThriftSourceProtocol.Client(protocol); _transport.Open(); }
public static byte[] Serialize <T>(T data) where T : TBase { using (var memStream = new MemoryStream()) using (var binaryReader = new BinaryReader(memStream)) using (var thriftTransport = new TStreamTransport(null, memStream)) { var binaryProtocol = new TCompactProtocol(thriftTransport); data.Write(binaryProtocol); //TODO Refactor memStream.Position = 0; return(binaryReader.ReadBytes((int)memStream.Length)); } }
public static void Main(string[] args) { try { //Accumulo details String accumuloProxyServerIP = "192.168.1.44"; //IP int accumuloProxyServerPort = 42424; //Port Number //Connect to Accumulo proxy server TTransport transport = new TSocket(accumuloProxyServerIP, accumuloProxyServerPort); transport = new TFramedTransport(transport); TCompactProtocol protocol = new TCompactProtocol(transport); transport.Open(); String principal = "root"; //Application ID Dictionary <string, string> passwd = new Dictionary <string, string>(); passwd.Add("password", "xxxxx"); //Password AccumuloProxy.Client client = new AccumuloProxy.Client(protocol); byte[] loginToken = client.login(principal, passwd); //Login token //{{ //Read a range of rows from Accumulo var bScanner = new BatchScanOptions(); Range range = new Range(); range.Start = new Key(); range.Start.Row = GetBytes("d001"); //Need the \0 only if you need to get a single row back //Otherwise, its not needed range.Stop = new Key(); range.Stop.Row = GetBytes("d001\0"); bScanner.Ranges = new List <Range>(); bScanner.Ranges.Add(range); String scanId = client.createBatchScanner(loginToken, "departments", bScanner); var more = true; while (more) { var scan = client.nextK(scanId, 10); more = scan.More; foreach (var entry in scan.Results) { Console.WriteLine("Row = " + GetString(entry.Key.Row)); Console.WriteLine("{0} {1}:{2} [{3}] {4} {5}", GetString(entry.Key.Row), GetString(entry.Key.ColFamily), GetString(entry.Key.ColQualifier), GetString(entry.Key.ColVisibility), GetString(entry.Value), (long)entry.Key.Timestamp); } } client.closeScanner(scanId); client.Dispose(); transport.Close(); }catch (Exception e) { Console.WriteLine(e); } //}} }
public void Read(TField reader, TCompactProtocol protocol) { protocol.ReadStructBegin(); while (true) { reader = protocol.ReadFieldBegin(); if (reader.Type == TType.Stop) { break; } switch (reader.ID) { case 1: if (reader.Type == TType.Map) { if (properties == null) { properties = new ADAGEDataPropertyInfoDictionary(); } else { properties.Clear(); } TMap _map17 = protocol.ReadMapBegin(); for (int _i18 = 0; _i18 < _map17.Count; ++_i18) { tempKey = protocol.ReadString(); tempValue = new ADAGEDataPropertyInfo(); tempValue.Read(reader, protocol); properties[tempKey] = tempValue; } protocol.ReadMapEnd(); } else { TProtocolUtil.Skip(protocol, reader.Type); } break; default: TProtocolUtil.Skip(protocol, reader.Type); break; } protocol.ReadFieldEnd(); } protocol.ReadStructEnd(); }