當前位置: 首頁>>代碼示例>>Java>>正文


Java ByteString.newCodedInput方法代碼示例

本文整理匯總了Java中com.google.protobuf.ByteString.newCodedInput方法的典型用法代碼示例。如果您正苦於以下問題:Java ByteString.newCodedInput方法的具體用法?Java ByteString.newCodedInput怎麽用?Java ByteString.newCodedInput使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.google.protobuf.ByteString的用法示例。


在下文中一共展示了ByteString.newCodedInput方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: parseRequest

import com.google.protobuf.ByteString; //導入方法依賴的package包/類
@Override public Request parseRequest(byte[] bytes) throws IOException {
  ByteString byteString = UnsafeByteOperations.unsafeWrap(bytes);
  CodedInputStream inputStream = byteString.newCodedInput();
  // Enable aliasing to avoid an extra copy to get at the serialized Request inside of the
  // WireMessage.
  inputStream.enableAliasing(true);
  WireMessage wireMsg = WireMessage.parseFrom(inputStream);

  String serializedMessageClassName = wireMsg.getName();

  try {
    RequestTranslator translator = getParserForRequest(serializedMessageClassName);

    // The ByteString should be logical offsets into the original byte array
    return translator.transform(wireMsg.getWrappedMessage());
  } catch (RuntimeException e) {
    if (LOG.isDebugEnabled()) {
      LOG.debug("Failed to parse request message '{}'", TextFormat.shortDebugString(wireMsg));
    }
    throw e;
  }
}
 
開發者ID:apache,項目名稱:calcite-avatica,代碼行數:23,代碼來源:ProtobufTranslationImpl.java

示例2: parseResponse

import com.google.protobuf.ByteString; //導入方法依賴的package包/類
@Override public Response parseResponse(byte[] bytes) throws IOException {
  ByteString byteString = UnsafeByteOperations.unsafeWrap(bytes);
  CodedInputStream inputStream = byteString.newCodedInput();
  // Enable aliasing to avoid an extra copy to get at the serialized Response inside of the
  // WireMessage.
  inputStream.enableAliasing(true);
  WireMessage wireMsg = WireMessage.parseFrom(inputStream);

  String serializedMessageClassName = wireMsg.getName();
  try {
    ResponseTranslator translator = getParserForResponse(serializedMessageClassName);

    return translator.transform(wireMsg.getWrappedMessage());
  } catch (RuntimeException e) {
    if (LOG.isDebugEnabled()) {
      LOG.debug("Failed to parse response message '{}'", TextFormat.shortDebugString(wireMsg));
    }
    throw e;
  }
}
 
開發者ID:apache,項目名稱:calcite-avatica,代碼行數:21,代碼來源:ProtobufTranslationImpl.java

示例3: mergeFrom

import com.google.protobuf.ByteString; //導入方法依賴的package包/類
/**
 * This version of protobuf's mergeFrom avoids the hard-coded 64MB limit for decoding
 * buffers when working with ByteStrings
 * @param builder current message builder
 * @param bs ByteString containing the 
 * @throws IOException 
 */
public static void mergeFrom(Message.Builder builder, ByteString bs) throws IOException {
  final CodedInputStream codedInput = bs.newCodedInput();
  codedInput.setSizeLimit(bs.size());
  builder.mergeFrom(codedInput);
  codedInput.checkLastTagWas(0);
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:14,代碼來源:ProtobufUtil.java


注:本文中的com.google.protobuf.ByteString.newCodedInput方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。