當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。