Search in sources :

Example 6 with TStruct

use of org.apache.thrift.protocol.TStruct in project dubbo by alibaba.

the class ThriftNativeCodec method encodeRequest.

protected void encodeRequest(Channel channel, ChannelBuffer buffer, Request request) throws IOException {
    Invocation invocation = (Invocation) request.getData();
    TProtocol protocol = newProtocol(channel.getUrl(), buffer);
    try {
        protocol.writeMessageBegin(new TMessage(invocation.getMethodName(), TMessageType.CALL, thriftSeq.getAndIncrement()));
        protocol.writeStructBegin(new TStruct(invocation.getMethodName() + "_args"));
        for (int i = 0; i < invocation.getParameterTypes().length; i++) {
            Class<?> type = invocation.getParameterTypes()[i];
        }
    } catch (TException e) {
        throw new IOException(e.getMessage(), e);
    }
}
Also used : TException(org.apache.thrift.TException) Invocation(com.alibaba.dubbo.rpc.Invocation) TProtocol(org.apache.thrift.protocol.TProtocol) TMessage(org.apache.thrift.protocol.TMessage) IOException(java.io.IOException) TStruct(org.apache.thrift.protocol.TStruct)

Example 7 with TStruct

use of org.apache.thrift.protocol.TStruct in project hive by apache.

the class TestTCTLSeparatedProtocol method testQuotedWrites.

@Test
public void testQuotedWrites() throws Exception {
    TMemoryBuffer trans = new TMemoryBuffer(4096);
    TCTLSeparatedProtocol prot = new TCTLSeparatedProtocol(trans, 4096);
    Properties schema = new Properties();
    schema.setProperty(serdeConstants.QUOTE_CHAR, "\"");
    schema.setProperty(serdeConstants.FIELD_DELIM, ",");
    prot.initialize(new Configuration(), schema);
    String testStr = "\"hello, world!\"";
    prot.writeStructBegin(new TStruct());
    prot.writeFieldBegin(new TField());
    prot.writeString(testStr);
    prot.writeFieldEnd();
    prot.writeFieldBegin(new TField());
    prot.writeListBegin(new TList());
    prot.writeString("elem1");
    prot.writeString("elem2");
    prot.writeListEnd();
    prot.writeFieldEnd();
    prot.writeStructEnd();
    prot.writeString("\n");
    trans.flush();
    byte[] b = new byte[4096];
    int len = trans.read(b, 0, b.length);
    trans = new TMemoryBuffer(4096);
    trans.write(b, 0, len);
    prot = new TCTLSeparatedProtocol(trans, 1024);
    prot.initialize(new Configuration(), schema);
    prot.readStructBegin();
    prot.readFieldBegin();
    final String firstRead = prot.readString();
    prot.readFieldEnd();
    testStr = testStr.replace("\"", "");
    assertEquals(testStr, firstRead);
    // the 2 element list
    prot.readFieldBegin();
    TList l = prot.readListBegin();
    assertTrue(l.size == 2);
    assertTrue(prot.readString().equals("elem1"));
    assertTrue(prot.readString().equals("elem2"));
    prot.readListEnd();
    prot.readFieldEnd();
    // should return nulls at end
    prot.readFieldBegin();
    assertNull(prot.readString());
    prot.readFieldEnd();
    // should return nulls at end
    prot.readFieldBegin();
    assertNull(prot.readString());
    prot.readFieldEnd();
    prot.readStructEnd();
}
Also used : TList(org.apache.thrift.protocol.TList) TMemoryBuffer(org.apache.thrift.transport.TMemoryBuffer) TConfiguration(org.apache.thrift.TConfiguration) Configuration(org.apache.hadoop.conf.Configuration) TField(org.apache.thrift.protocol.TField) Properties(java.util.Properties) TStruct(org.apache.thrift.protocol.TStruct) TCTLSeparatedProtocol(org.apache.hadoop.hive.serde2.thrift.TCTLSeparatedProtocol) Test(org.junit.Test)

Example 8 with TStruct

use of org.apache.thrift.protocol.TStruct in project dubbo by alibaba.

the class ThriftNativeCodec method encodeRequest.

protected void encodeRequest(Channel channel, ChannelBuffer buffer, Request request) throws IOException {
    Invocation invocation = (Invocation) request.getData();
    TProtocol protocol = newProtocol(channel.getUrl(), buffer);
    try {
        protocol.writeMessageBegin(new TMessage(invocation.getMethodName(), TMessageType.CALL, thriftSeq.getAndIncrement()));
        protocol.writeStructBegin(new TStruct(invocation.getMethodName() + "_args"));
        for (int i = 0; i < invocation.getParameterTypes().length; i++) {
            Class<?> type = invocation.getParameterTypes()[i];
        }
    } catch (TException e) {
        throw new IOException(e.getMessage(), e);
    }
}
Also used : TException(org.apache.thrift.TException) Invocation(org.apache.dubbo.rpc.Invocation) TProtocol(org.apache.thrift.protocol.TProtocol) TMessage(org.apache.thrift.protocol.TMessage) IOException(java.io.IOException) TStruct(org.apache.thrift.protocol.TStruct)

Aggregations

TStruct (org.apache.thrift.protocol.TStruct)8 TField (org.apache.thrift.protocol.TField)6 Properties (java.util.Properties)3 Configuration (org.apache.hadoop.conf.Configuration)3 TCTLSeparatedProtocol (org.apache.hadoop.hive.serde2.thrift.TCTLSeparatedProtocol)3 TConfiguration (org.apache.thrift.TConfiguration)3 TException (org.apache.thrift.TException)3 TProtocol (org.apache.thrift.protocol.TProtocol)3 TMemoryBuffer (org.apache.thrift.transport.TMemoryBuffer)3 Test (org.junit.Test)3 IOException (java.io.IOException)2 TList (org.apache.thrift.protocol.TList)2 TMap (org.apache.thrift.protocol.TMap)2 TMessage (org.apache.thrift.protocol.TMessage)2 Invocation (com.alibaba.dubbo.rpc.Invocation)1 PField (net.morimekta.providence.descriptor.PField)1 Invocation (org.apache.dubbo.rpc.Invocation)1 ThriftField (org.apache.parquet.thrift.struct.ThriftField)1