本文整理汇总了Java中com.alibaba.dubbo.rpc.protocol.thrift.ThriftCodec.MAGIC属性的典型用法代码示例。如果您正苦于以下问题:Java ThriftCodec.MAGIC属性的具体用法?Java ThriftCodec.MAGIC怎么用?Java ThriftCodec.MAGIC使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类com.alibaba.dubbo.rpc.protocol.thrift.ThriftCodec
的用法示例。
在下文中一共展示了ThriftCodec.MAGIC属性的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: process
public boolean process( TProtocol in, TProtocol out ) throws TException {
short magic = in.readI16();
if ( magic != ThriftCodec.MAGIC ) {
logger.error(
new StringBuilder( 24 )
.append( "Unsupported magic " )
.append( magic ).toString() );
return false;
}
in.readI32();
in.readI16();
byte version = in.readByte();
String serviceName = in.readString();
long id = in.readI64();
ByteArrayOutputStream bos = new ByteArrayOutputStream( 1024 );
TIOStreamTransport transport = new TIOStreamTransport( bos );
TProtocol protocol = protocolFactory.getProtocol( transport );
TProcessor processor = processorMap.get( serviceName );
if ( processor == null ) {
logger.error(
new StringBuilder( 32 )
.append( "Could not find processor for service " )
.append( serviceName )
.toString() );
return false;
}
// todo if exception
boolean result = processor.process( in, protocol );
ByteArrayOutputStream header = new ByteArrayOutputStream( 512 );
TIOStreamTransport headerTransport = new TIOStreamTransport( header );
TProtocol headerProtocol = protocolFactory.getProtocol( headerTransport );
headerProtocol.writeI16( magic );
headerProtocol.writeI32( Integer.MAX_VALUE );
headerProtocol.writeI16( Short.MAX_VALUE );
headerProtocol.writeByte( version );
headerProtocol.writeString( serviceName );
headerProtocol.writeI64( id );
headerProtocol.getTransport().flush();
out.writeI16( magic );
out.writeI32( bos.size() + header.size() );
out.writeI16( ( short ) ( 0xffff & header.size() ) );
out.writeByte( version );
out.writeString( serviceName );
out.writeI64( id );
out.getTransport().write( bos.toByteArray() );
out.getTransport().flush();
return result;
}
示例2: process
public boolean process(TProtocol in, TProtocol out) throws TException {
short magic = in.readI16();
if (magic != ThriftCodec.MAGIC) {
logger.error(
new StringBuilder(24)
.append("Unsupported magic ")
.append(magic).toString());
return false;
}
in.readI32();
in.readI16();
byte version = in.readByte();
String serviceName = in.readString();
long id = in.readI64();
ByteArrayOutputStream bos = new ByteArrayOutputStream(1024);
TIOStreamTransport transport = new TIOStreamTransport(bos);
TProtocol protocol = protocolFactory.getProtocol(transport);
TProcessor processor = processorMap.get(serviceName);
if (processor == null) {
logger.error(
new StringBuilder(32)
.append("Could not find processor for service ")
.append(serviceName)
.toString());
return false;
}
// todo if exception
boolean result = processor.process(in, protocol);
ByteArrayOutputStream header = new ByteArrayOutputStream(512);
TIOStreamTransport headerTransport = new TIOStreamTransport(header);
TProtocol headerProtocol = protocolFactory.getProtocol(headerTransport);
headerProtocol.writeI16(magic);
headerProtocol.writeI32(Integer.MAX_VALUE);
headerProtocol.writeI16(Short.MAX_VALUE);
headerProtocol.writeByte(version);
headerProtocol.writeString(serviceName);
headerProtocol.writeI64(id);
headerProtocol.getTransport().flush();
out.writeI16(magic);
out.writeI32(bos.size() + header.size());
out.writeI16((short) (0xffff & header.size()));
out.writeByte(version);
out.writeString(serviceName);
out.writeI64(id);
out.getTransport().write(bos.toByteArray());
out.getTransport().flush();
return result;
}