本文整理汇总了Java中com.google.protobuf.GeneratedMessageLite类的典型用法代码示例。如果您正苦于以下问题:Java GeneratedMessageLite类的具体用法?Java GeneratedMessageLite怎么用?Java GeneratedMessageLite使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
GeneratedMessageLite类属于com.google.protobuf包,在下文中一共展示了GeneratedMessageLite类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendRequest
import com.google.protobuf.GeneratedMessageLite; //导入依赖的package包/类
/**
* todo check exception
* */
public void sendRequest(GeneratedMessageLite requset,int sid,int cid,Packetlistener packetlistener){
int seqNo = 0;
try{
//组装包头 header
com.mogujie.tt.protobuf.base.Header header = new DefaultHeader(sid, cid);
int bodySize = requset.getSerializedSize();
header.setLength(SysConstant.PROTOCOL_HEADER_LENGTH + bodySize);
seqNo = header.getSeqnum();
listenerQueue.push(seqNo,packetlistener);
boolean sendRes = msgServerThread.sendRequest(requset,header);
}catch (Exception e){
if(packetlistener !=null){
packetlistener.onFaild();
}
listenerQueue.pop(seqNo);
logger.e("#sendRequest#channel is close!");
}
}
示例2: sendRequest
import com.google.protobuf.GeneratedMessageLite; //导入依赖的package包/类
/**
* @param requset
* @param header
* @return
*/
public boolean sendRequest(GeneratedMessageLite requset,Header header){
int bodySize = requset.getSerializedSize();
if (null != channel) {
byte[] bytes = requset.toByteArray();
byte[] hbytes = header.encode().array();
ByteBuf byteBuf = channel.alloc().buffer(SysConstant.PROTOCOL_HEADER_LENGTH + bodySize);
byteBuf.writeBytes(hbytes);
byteBuf.writeBytes(bytes);
/**底层的状态要提前判断,netty抛出的异常上层catch不到*/
boolean isW = channel.isWritable();
boolean isC = channel.isOpen();
if(!(isW && isC)){
throw new RuntimeException("#sendRequest#channel is close!");
}
//channel.writeAndFlush(buffer.getOrignalBuffer());
channel.writeAndFlush(byteBuf);
logger.d("packet#send ok");
return true;
} else {
logger.e("packet#send failed");
return false;
}
}
示例3: writeOneBlob
import com.google.protobuf.GeneratedMessageLite; //导入依赖的package包/类
/** @param block is either a PrimitiveBlock or a HeaderBlock */
private void writeOneBlob(GeneratedMessageLite block) {
// FIXME lotsa big copies going on here
String blobTypeString;
if (block instanceof Osmformat.HeaderBlock) {
blobTypeString = "OSMHeader";
} else if (block instanceof Osmformat.PrimitiveBlock) {
blobTypeString = "OSMData";
} else {
throw new AssertionError("block must be either a header block or a primitive block.");
}
Fileformat.Blob.Builder blobBuilder = Fileformat.Blob.newBuilder();
byte[] serializedBlock = block.toByteArray();
byte[] deflatedBlock = new byte[serializedBlock.length];
int deflatedSize = deflate(serializedBlock, deflatedBlock);
if (deflatedSize < 0) {
LOG.debug("Deflate did not reduce the size of a block. Saving it uncompressed.");
blobBuilder.setRaw(ByteString.copyFrom(serializedBlock));
} else {
blobBuilder.setZlibData(ByteString.copyFrom(deflatedBlock, 0, deflatedSize));
blobBuilder.setRawSize(serializedBlock.length);
}
byte[] serializedBlob = blobBuilder.build().toByteArray();
Fileformat.BlobHeader blobHeader = Fileformat.BlobHeader.newBuilder()
.setType(blobTypeString).setDatasize(serializedBlob.length).build();
byte[] serializedBlobHeader = blobHeader.toByteArray();
try {
// "Returns a big-endian representation of value in a 4-element byte array"
downstream.write(Ints.toByteArray(serializedBlobHeader.length));
downstream.write(serializedBlobHeader);
downstream.write(serializedBlob);
} catch (IOException e) {
throw new RuntimeException(e);
}
}