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


Java MessageLite.Builder方法代碼示例

本文整理匯總了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()));
    }
}
 
開發者ID:ninelook,項目名稱:wecard-server,代碼行數:12,代碼來源:ProtobufEncoder.java

示例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);
    }
}
 
開發者ID:s-store,項目名稱:sstore-soft,代碼行數:44,代碼來源:ProtoConnection.java


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