本文整理匯總了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;
}
}
示例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;
}
}
示例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);
}