当前位置: 首页>>代码示例>>Java>>正文


Java TMemoryBuffer类代码示例

本文整理汇总了Java中org.apache.thrift.transport.TMemoryBuffer的典型用法代码示例。如果您正苦于以下问题:Java TMemoryBuffer类的具体用法?Java TMemoryBuffer怎么用?Java TMemoryBuffer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


TMemoryBuffer类属于org.apache.thrift.transport包,在下文中一共展示了TMemoryBuffer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: shouldWriteUnion_thatThriftRead

import org.apache.thrift.transport.TMemoryBuffer; //导入依赖的package包/类
@Test
public void shouldWriteUnion_thatThriftRead() throws Exception {
    TMemoryBuffer transport = new TMemoryBuffer(1024);
    TBinaryProtocol protocol = new TBinaryProtocol(transport);
    UnionB fireflyUnionB = new UnionB();
    OrderedStruct fireflyOrderedStruct = new OrderedStruct();
    fireflyOrderedStruct.id = 99;
    fireflyUnionB.os = fireflyOrderedStruct;
    StructTypeAdapterFactory.StructTypeAdapter structTypeAdapter = new StructTypeAdapterFactory.StructTypeAdapter(UnionB.class, thrift);
    structTypeAdapter.write(fireflyUnionB, protocol);

    com.meituan.firefly.testthrift.UnionB thriftUnionB = new com.meituan.firefly.testthrift.UnionB();
    thriftUnionB.read(protocol);

    assertThat(thriftUnionB.getSetField()).isEqualTo(com.meituan.firefly.testthrift.UnionB._Fields.OS);
    assertThat(thriftUnionB.getOs()).isNotNull();
    assertThat(thriftUnionB.getOs().getId()).isEqualTo(99);
}
 
开发者ID:meituan,项目名称:Firefly,代码行数:19,代码来源:StructTypeAdapterTest.java

示例2: main

import org.apache.thrift.transport.TMemoryBuffer; //导入依赖的package包/类
public static void main(String[] args) 
        throws IOException, TTransportException, ClassNotFoundException {
    TMemoryBuffer transport = new TMemoryBuffer(4096);

    Trade trade = new Trade();
    trade.symbol = "F";
    trade.price = 13.10;
    trade.size = 2500;
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(baos);
    oos.writeObject(trade);
    transport.write(baos.toByteArray());

    byte[] buf = new byte[128];
    int bytes_read = transport.read(buf, 0, buf.length);
    ByteArrayInputStream bais = new ByteArrayInputStream(buf);
    ObjectInputStream ois = new ObjectInputStream(bais);
    Trade trade_read = (Trade) ois.readObject();
    System.out.println("Trade(" + bytes_read + "): " + trade_read.symbol
            + " " + trade_read.size + " @ " + trade_read.price);
}
 
开发者ID:RandyAbernethy,项目名称:ThriftBook,代码行数:22,代码来源:MemTrans.java

示例3: thriftRequest

import org.apache.thrift.transport.TMemoryBuffer; //导入依赖的package包/类
private String thriftRequest(byte[] input){
    try{
    
        //Input
        TMemoryBuffer inbuffer = new TMemoryBuffer(input.length);           
        inbuffer.write(input);              
        TProtocol  inprotocol   = new TJSONProtocol(inbuffer);                   
        
        //Output
        TMemoryBuffer outbuffer = new TMemoryBuffer(100);           
        TProtocol outprotocol   = new TJSONProtocol(outbuffer);
        
        TProcessor processor = new Calculator.Processor(new CalculatorHandler());      
        processor.process(inprotocol, outprotocol);
        
        byte[] output = new byte[outbuffer.length()];
        outbuffer.readAll(output, 0, output.length);
    
        return new String(output,"UTF-8");
    }catch(Throwable t){
        return "Error:"+t.getMessage();
    }
     
             
}
 
开发者ID:YinYanfei,项目名称:CadalWorkspace,代码行数:26,代码来源:Httpd.java

示例4: testBinary

import org.apache.thrift.transport.TMemoryBuffer; //导入依赖的package包/类
public void testBinary() throws Exception {
  for (byte[] b : Arrays.asList(new byte[0], new byte[]{0,1,2,3,4,5,6,7,8,9,10}, new byte[]{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14}, new byte[128])) {
    if (canBeUsedNaked()) {
      internalTestNakedBinary(b);
    }
    internalTestBinaryField(b);
  }

  if (canBeUsedNaked()) {
    byte[] data = {1, 2, 3, 4, 5, 6};

    TMemoryBuffer buf = new TMemoryBuffer(0);
    TProtocol proto = getFactory().getProtocol(buf);
    ByteBuffer bb = ByteBuffer.wrap(data);
    bb.get();
    proto.writeBinary(bb.slice());
    assertEquals(ByteBuffer.wrap(data, 1, 5), proto.readBinary());
  }
}
 
开发者ID:YinYanfei,项目名称:CadalWorkspace,代码行数:20,代码来源:ProtocolTestBase.java

示例5: testMessage

import org.apache.thrift.transport.TMemoryBuffer; //导入依赖的package包/类
public void testMessage() throws Exception {
  List<TMessage> msgs = Arrays.asList(new TMessage[]{
    new TMessage("short message name", TMessageType.CALL, 0),
    new TMessage("1", TMessageType.REPLY, 12345),
    new TMessage("loooooooooooooooooooooooooooooooooong", TMessageType.EXCEPTION, 1 << 16),
    new TMessage("Janky", TMessageType.CALL, 0),
  });

  for (TMessage msg : msgs) {
    TMemoryBuffer buf = new TMemoryBuffer(0);
    TProtocol proto = getFactory().getProtocol(buf);
    TMessage output = null;

    proto.writeMessageBegin(msg);
    proto.writeMessageEnd();

    output = proto.readMessageBegin();

    assertEquals(msg, output);
  }
}
 
开发者ID:YinYanfei,项目名称:CadalWorkspace,代码行数:22,代码来源:ProtocolTestBase.java

示例6: internalTestStructField

import org.apache.thrift.transport.TMemoryBuffer; //导入依赖的package包/类
private void internalTestStructField(StructFieldTestCase testCase) throws Exception {
  TMemoryBuffer buf = new TMemoryBuffer(0);
  TProtocol proto = getFactory().getProtocol(buf);

  TField field = new TField("test_field", testCase.type_, testCase.id_);
  proto.writeStructBegin(new TStruct("test_struct"));
  proto.writeFieldBegin(field);
  testCase.writeMethod(proto);
  proto.writeFieldEnd();
  proto.writeStructEnd();

  proto.readStructBegin();
  TField readField = proto.readFieldBegin();
  assertEquals(testCase.id_, readField.id);
  assertEquals(testCase.type_, readField.type);
  testCase.readMethod(proto);
  proto.readStructEnd();
}
 
开发者ID:YinYanfei,项目名称:CadalWorkspace,代码行数:19,代码来源:ProtocolTestBase.java

示例7: thriftRequest

import org.apache.thrift.transport.TMemoryBuffer; //导入依赖的package包/类
private String thriftRequest(byte[] input){
    try{
    
        //Input
        TMemoryBuffer inbuffer = new TMemoryBuffer(input.length);           
        inbuffer.write(input);              
        TProtocol  inprotocol   = new TJSONProtocol(inbuffer);                   
        
        //Output
        TMemoryBuffer outbuffer = new TMemoryBuffer(100);           
        TProtocol outprotocol   = new TJSONProtocol(outbuffer);
        
        TProcessor processor = new ThriftTest.Processor(new TestHandler());      
        processor.process(inprotocol, outprotocol);
        
        byte[] output = new byte[outbuffer.length()];
        outbuffer.readAll(output, 0, output.length);
    
        return new String(output,"UTF-8");
    }catch(Throwable t){
        return "Error:"+t.getMessage();
    }
     
             
}
 
开发者ID:YinYanfei,项目名称:CadalWorkspace,代码行数:26,代码来源:Httpd.java

示例8: makeRequest

import org.apache.thrift.transport.TMemoryBuffer; //导入依赖的package包/类
/** This doesn't use thrift sequence ids because scrooge doesn't */
@Override protected ThriftClientRequest makeRequest(List<byte[]> spans) throws TException {
  int encodedSize = InternalScribeCodec.messageSizeInBytes(category, spans);
  TMemoryBuffer mem = new TMemoryBuffer(encodedSize);
  TBinaryProtocol prot = new TBinaryProtocol(mem);
  InternalScribeCodec.writeLogRequest(category, spans, 0, prot);
  return new ThriftClientRequest(mem.getArray(), false);
}
 
开发者ID:openzipkin,项目名称:zipkin-finagle,代码行数:9,代码来源:ScribeSender.java

示例9: testThriftBaseReadWrite

import org.apache.thrift.transport.TMemoryBuffer; //导入依赖的package包/类
@Test
public void testThriftBaseReadWrite() {
	TBinaryProtocol protocol = new TBinaryProtocol(new TMemoryBuffer(16));
	ArgsThriftBase args = new ArgsThriftBase(testString);
	ResultThriftBase result = new ResultThriftBase();
	try {
		args.write(protocol);
		result.read(protocol);
		assertEquals(args.getStr(), result.getStr(), testString);
	} catch (TException e) {
		fail();
	}
}
 
开发者ID:venwyhk,项目名称:ikasoa,代码行数:14,代码来源:ServiceTest.java

示例10: serialize

import org.apache.thrift.transport.TMemoryBuffer; //导入依赖的package包/类
static byte[] serialize(AccessControlEntry ace) throws IOException {
    TMemoryBuffer transport = new TMemoryBuffer(BUFFER_SIZE);
    TJSONProtocol protocol = new TJSONProtocol(transport);
    try {
        ace.write(protocol);
        transport.flush();
        return transport.toString(UTF_8.name()).getBytes(UTF_8);
    } catch (TException e) {
        throw new IOException("Failed to serialize access control entry : ", e);
    } catch (UnsupportedEncodingException uee) {
        throw new IOException("Failed to serialize acesss control entry : ", uee);
    }
}
 
开发者ID:twitter,项目名称:distributedlog,代码行数:14,代码来源:ZKAccessControl.java

示例11: translator_test_base

import org.apache.thrift.transport.TMemoryBuffer; //导入依赖的package包/类
private void translator_test_base(TProtocolFactory protocolFactory, final String token, MessageTransalator translator) throws TException, InstantiationException, IllegalAccessException {
    TMemoryBuffer externalServiceBuffer = new TMemoryBufferWithLength(1024);

    ExternalTestService.Client externalServiceClient
            = new ExternalTestService.Client(protocolFactory.getProtocol(externalServiceBuffer));

    externalServiceClient.send_getSomeData(
            new AuthToken().setToken(token).setChecksum(128),
            new RequestData().setSomeStringField("somevalue").setSomeIntField(8)
    );

    TMemoryBuffer internalServiceBuffer = new TMemoryBufferWithLength(1024);

    InternalTestService.Client internalServiceClient
            = new InternalTestService.Client(protocolFactory.getProtocol(internalServiceBuffer));

    internalServiceClient.send_getSomeData(
            new UserData().setId("user1"),
            new RequestData().setSomeStringField("somevalue").setSomeIntField(8)
    );

    byte[] externalServiceMessage = Arrays.copyOf(externalServiceBuffer.getArray(), externalServiceBuffer.length());
    byte[] internalServiceMessage = Arrays.copyOf(internalServiceBuffer.getArray(), internalServiceBuffer.length());

    Assert.assertTrue(
            "Translated external message must be the same as internal message",
            Arrays.equals(
                    translator.process(externalServiceMessage),
                    internalServiceMessage
            )
    );
}
 
开发者ID:aatarasoff,项目名称:thrift-api-gateway-core,代码行数:33,代码来源:MessageTranslatorTests.java

示例12: shouldReadStruct_thatThriftWrite

import org.apache.thrift.transport.TMemoryBuffer; //导入依赖的package包/类
@Test
public void shouldReadStruct_thatThriftWrite() throws Exception {
    TMemoryBuffer transport = new TMemoryBuffer(1024);
    TBinaryProtocol protocol = new TBinaryProtocol(transport);
    com.meituan.firefly.testthrift.OrderedStruct thriftOrderedStruct = new com.meituan.firefly.testthrift.OrderedStruct(99);
    thriftOrderedStruct.write(protocol);

    StructTypeAdapterFactory.StructTypeAdapter structTypeAdapter = new StructTypeAdapterFactory.StructTypeAdapter(OrderedStruct.class, thrift);
    OrderedStruct fireflyOrderedStruct = (OrderedStruct) structTypeAdapter.read(protocol);
    assertThat(fireflyOrderedStruct).isNotNull();
    assertThat(fireflyOrderedStruct.id).isEqualTo(99);
}
 
开发者ID:meituan,项目名称:Firefly,代码行数:13,代码来源:StructTypeAdapterTest.java

示例13: shouldWriteStruct_thatThriftRead

import org.apache.thrift.transport.TMemoryBuffer; //导入依赖的package包/类
@Test
public void shouldWriteStruct_thatThriftRead() throws Exception {
    TMemoryBuffer transport = new TMemoryBuffer(1024);
    TBinaryProtocol protocol = new TBinaryProtocol(transport);
    OrderedStruct fireflyOrderedStruct = new OrderedStruct();
    fireflyOrderedStruct.id = 99;

    StructTypeAdapterFactory.StructTypeAdapter structTypeAdapter = new StructTypeAdapterFactory.StructTypeAdapter(OrderedStruct.class, thrift);
    structTypeAdapter.write(fireflyOrderedStruct, protocol);
    com.meituan.firefly.testthrift.OrderedStruct thriftOrderedStruct = new com.meituan.firefly.testthrift.OrderedStruct();
    thriftOrderedStruct.read(protocol);
    assertThat(thriftOrderedStruct.id).isEqualTo(99);
}
 
开发者ID:meituan,项目名称:Firefly,代码行数:14,代码来源:StructTypeAdapterTest.java

示例14: shouldReadMixStruct_thatThriftWrite

import org.apache.thrift.transport.TMemoryBuffer; //导入依赖的package包/类
@Test
public void shouldReadMixStruct_thatThriftWrite() throws Exception {
    TMemoryBuffer transport = new TMemoryBuffer(1024);
    TBinaryProtocol protocol = new TBinaryProtocol(transport);
    com.meituan.firefly.testthrift.MixStruct thriftMixStruct = new com.meituan.firefly.testthrift.MixStruct(1, 2);
    thriftMixStruct.write(protocol);

    StructTypeAdapterFactory.StructTypeAdapter structTypeAdapter = new StructTypeAdapterFactory.StructTypeAdapter(MixStruct.class, thrift);
    MixStruct fireflyMixStruct = (MixStruct) structTypeAdapter.read(protocol);
    assertThat(fireflyMixStruct).isNotNull();
    assertThat(fireflyMixStruct.id).isEqualTo(1);
    assertThat(fireflyMixStruct.uid).isEqualTo(2);
}
 
开发者ID:meituan,项目名称:Firefly,代码行数:14,代码来源:StructTypeAdapterTest.java

示例15: shouldWriteMixStruct_thatThriftRead

import org.apache.thrift.transport.TMemoryBuffer; //导入依赖的package包/类
@Test
public void shouldWriteMixStruct_thatThriftRead() throws Exception {
    TMemoryBuffer transport = new TMemoryBuffer(1024);
    TBinaryProtocol protocol = new TBinaryProtocol(transport);
    MixStruct fireflyMixStruct = new MixStruct();
    fireflyMixStruct.id = 1;
    fireflyMixStruct.uid = 2;

    StructTypeAdapterFactory.StructTypeAdapter structTypeAdapter = new StructTypeAdapterFactory.StructTypeAdapter(MixStruct.class, thrift);
    structTypeAdapter.write(fireflyMixStruct, protocol);
    com.meituan.firefly.testthrift.MixStruct thriftMixStruct = new com.meituan.firefly.testthrift.MixStruct();
    thriftMixStruct.read(protocol);
    assertThat(thriftMixStruct.id).isEqualTo(1);
    assertThat(thriftMixStruct.uid).isEqualTo(2);
}
 
开发者ID:meituan,项目名称:Firefly,代码行数:16,代码来源:StructTypeAdapterTest.java


注:本文中的org.apache.thrift.transport.TMemoryBuffer类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。