本文整理匯總了Java中com.google.protobuf.MessageLite.Builder方法的典型用法代碼示例。如果您正苦於以下問題:Java MessageLite.Builder方法的具體用法?Java MessageLite.Builder怎麽用?Java MessageLite.Builder使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.protobuf.MessageLite
的用法示例。
在下文中一共展示了MessageLite.Builder方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: encode
import com.google.protobuf.MessageLite; //導入方法依賴的package包/類
@Override
protected void encode(
ChannelHandlerContext ctx, MessageLiteOrBuilder msg, List<Object> out) throws Exception {
if (msg instanceof MessageLite) {
out.add(wrappedBuffer(((MessageLite) msg).toByteArray()));
return;
}
if (msg instanceof MessageLite.Builder) {
out.add(wrappedBuffer(((MessageLite.Builder) msg).build().toByteArray()));
}
}
示例2: readBufferedMessage
import com.google.protobuf.MessageLite; //導入方法依賴的package包/類
/** Attempts to read a buffered message from the underlying connection. This is more efficient
* than attempting to actually read from the underlying connection for each message, when ends
* up making a final "empty" read from the non-blocking connection, rather than simply
* consuming all buffered data.
*
* TODO: It would be ideal if there was a way to consume data as we go, instead of buffering
* it all then consuming it. However, this only matters for streams of medium-sized messages
* with a huge backlog, which should be rare? The C++ implementation has a similar issue.
*
* @param builder message builder to be parsed
* @return true if a message was read, false if there is not enough buffered data to read a
* message.
*/
public boolean readBufferedMessage(MessageLite.Builder builder) {
try {
if (nextMessageLength == -1) {
if (connection.available() < 4) {
return false;
}
input.setLimit(4);
nextMessageLength = codedInput.readRawLittleEndian32();
}
assert nextMessageLength >= 0;
if (connection.available() < nextMessageLength) {
assert 0 <= connection.available() && connection.available() < nextMessageLength;
return false;
}
// Parse the response for the next RPC
// TODO: Add .available() to CodedInputStream to avoid many copies to internal buffer?
// or make CodedInputStream wrap a non-blocking interface like C++?
input.setLimit(nextMessageLength);
builder.mergeFrom(codedInput);
assert codedInput.isAtEnd();
codedInput.resetSizeCounter();
nextMessageLength = -1;
return true;
} catch (IOException e) {
throw new RuntimeException(e);
}
}