public static void FistTest() { Console.WriteLine("Thrift2 Demo"); Console.WriteLine("This demo assumes you have a table called \"example\" with a column family called \"family1\""); String host = "hserver"; int port = 9090; int timeout = 10000; var framed = false; TTransport transport = new TSocket(host, port, timeout); if (framed) { transport = new TFramedTransport(transport); } TProtocol protocol = new TBinaryProtocol(transport); // This is our thrift client. THBaseService.Iface client = new THBaseService.Client(protocol); // open the transport transport.Open(); var table = "t1".ToBytes(); TPut put = new TPut(); put.Row = ("row1".ToBytes()); for (var i = 0; i < 1000; i++) { TColumnValue columnValue = new TColumnValue(); columnValue.Family = ("f1".ToBytes()); columnValue.Qualifier = ("qualifier" + i).ToBytes(); columnValue.Value = ("value" + i).ToBytes(); List <TColumnValue> columnValues = new List <TColumnValue>(); columnValues.Add(columnValue); put.ColumnValues = columnValues; client.put(table, put); } TGet get = new TGet(); get.Row = ("row1".ToBytes()); TResult result = client.get(table, get); Console.WriteLine("row = " + result.Row.ToStr()); foreach (TColumnValue resultColumnValue in result.ColumnValues) { Console.WriteLine("family = " + resultColumnValue.Family.ToStr()); Console.WriteLine("qualifier = " + resultColumnValue.Qualifier.ToStr()); Console.WriteLine("value = " + resultColumnValue.Value.ToStr()); Console.WriteLine("timestamp = " + resultColumnValue.Timestamp); } transport.Close(); }
public async Task ReadAsync(TProtocol iprot, CancellationToken cancellationToken) { iprot.IncrementRecursionDepth(); try { TField field; await iprot.ReadStructBeginAsync(cancellationToken); while (true) { field = await iprot.ReadFieldBeginAsync(cancellationToken); if (field.Type == TType.Stop) { break; } switch (field.ID) { case 1: if (field.Type == TType.Struct) { Put = new TPut(); await Put.ReadAsync(iprot, cancellationToken); } else { await TProtocolUtil.SkipAsync(iprot, field.Type, cancellationToken); } break; case 2: if (field.Type == TType.Struct) { DeleteSingle = new TDelete(); await DeleteSingle.ReadAsync(iprot, cancellationToken); } else { await TProtocolUtil.SkipAsync(iprot, field.Type, cancellationToken); } break; default: await TProtocolUtil.SkipAsync(iprot, field.Type, cancellationToken); break; } await iprot.ReadFieldEndAsync(cancellationToken); } await iprot.ReadStructEndAsync(cancellationToken); } finally { iprot.DecrementRecursionDepth(); } }
static void Main(string[] args) { var thriftsocket = new TSocket("192.168.1.40", 8090, 10000); var client = new THBaseService.Client(new TBinaryProtocol(thriftsocket)); thriftsocket.Open(); var rowKey = new TPut(); rowKey.Row = Encoding.UTF8.GetBytes(Guid.NewGuid().ToString()); var col1 = new TColumnValue(null, null, null); }
public void Read(TProtocol iprot) { TField field; iprot.ReadStructBegin(); while (true) { field = iprot.ReadFieldBegin(); if (field.Type == TType.Stop) { break; } switch (field.ID) { case 1: if (field.Type == TType.Struct) { Put = new TPut(); Put.Read(iprot); } else { TProtocolUtil.Skip(iprot, field.Type); } break; case 2: if (field.Type == TType.Struct) { DeleteSingle = new TDelete(); DeleteSingle.Read(iprot); } else { TProtocolUtil.Skip(iprot, field.Type); } break; default: TProtocolUtil.Skip(iprot, field.Type); break; } iprot.ReadFieldEnd(); } iprot.ReadStructEnd(); }