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


Java GeneratedMessageLite类代码示例

本文整理汇总了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!");
    }
}
 
开发者ID:ccfish86,项目名称:sctalk,代码行数:22,代码来源:IMSocketManager.java

示例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;
      }
  }
 
开发者ID:ccfish86,项目名称:sctalk,代码行数:33,代码来源:SocketThread.java

示例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);
    }

}
 
开发者ID:conveyal,项目名称:osm-lib,代码行数:41,代码来源:PBFOutput.java


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