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


Java CodedInputStream.pushLimit方法代碼示例

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


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

示例1: readFrom

import com.google.protobuf.CodedInputStream; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
@Override
<T> T readFrom(ByteBuffer bb) throws IOException {
  // using the parser with a byte[]-backed coded input stream is the
  // most efficient way to deserialize a protobuf.  it has a direct
  // path to the PB ctor that doesn't create multi-layered streams
  // that internally buffer.
  CodedInputStream cis = CodedInputStream.newInstance(
      bb.array(), bb.position() + bb.arrayOffset(), bb.remaining());
  try {
    cis.pushLimit(cis.readRawVarint32());
    message = message.getParserForType().parseFrom(cis);
    cis.checkLastTagWas(0);
  } finally {
    // advance over the bytes read.
    bb.position(bb.position() + cis.getTotalBytesRead());
  }
  return (T)message;
}
 
開發者ID:hopshadoop,項目名稱:hops,代碼行數:20,代碼來源:RpcWritable.java

示例2: parseField

import com.google.protobuf.CodedInputStream; //導入方法依賴的package包/類
/**
 * Parses the field.
 *
 * @param <T> the generic type
 * @param input the input
 * @param extensionRegistry the extension registry
 * @param type the type
 * @param value the value
 * @return the t
 * @throws IOException Signals that an I/O exception has occurred.
 */
@SuppressWarnings("unchecked")
static <T> T parseField(CodedInputStream input, ExtensionRegistryLite extensionRegistry, WireFormat.FieldType type,
        T value) throws IOException {
    switch (type) {
        case MESSAGE:
            int length = input.readRawVarint32();
            final int oldLimit = input.pushLimit(length);
            Codec<? extends Object> codec = ProtobufProxy.create(value.getClass());
            T ret = (T) codec.decode(input.readRawBytes(length));
            input.popLimit(oldLimit);
            return ret;
        case ENUM:
            return (T) (java.lang.Integer) input.readEnum();
        case GROUP:
            throw new RuntimeException("Groups are not allowed in maps.");
        default:
            return (T) CodedConstant.readPrimitiveField(input, type, true);
    }
}
 
開發者ID:jhunters,項目名稱:jprotobuf,代碼行數:31,代碼來源:MapEntryLite.java

示例3: readPreprocessedBlock

import com.google.protobuf.CodedInputStream; //導入方法依賴的package包/類
private Iterable<RtbImpression> readPreprocessedBlock(BlockContext context) throws IOException {
    List<RtbImpression> impressions = new ArrayList<>();
    try (InputStream is = context.createInputStream(PREPROCESS)) {
        CodedInputStream cis = CodedInputStream.newInstance(is);
        while (!cis.isAtEnd()) {
            int len = cis.readRawVarint32();
            int oldLimit = cis.pushLimit(len);
            impressions.add(RtbImpression.parseFrom(cis));
            cis.popLimit(oldLimit);
        }
    }
    return impressions;
}
 
開發者ID:papyrusglobal,項目名稱:state-channels,代碼行數:14,代碼來源:RtbValidator.java

示例4: readLog

import com.google.protobuf.CodedInputStream; //導入方法依賴的package包/類
private OnlineSectioningLog.ExportedLog readLog(CodedInputStream cin) throws IOException {
	if (cin.isAtEnd()) return null;
	int size = cin.readInt32();
	int limit = cin.pushLimit(size);
	OnlineSectioningLog.ExportedLog ret = OnlineSectioningLog.ExportedLog.parseFrom(cin);
	cin.popLimit(limit);
	cin.resetSizeCounter();
	return ret;
}
 
開發者ID:Jenner4S,項目名稱:unitimes,代碼行數:10,代碼來源:ReplayLogTest.java

示例5: readTable

import com.google.protobuf.CodedInputStream; //導入方法依賴的package包/類
public static TableData.Table readTable(CodedInputStream cin) throws IOException {
	if (cin.isAtEnd()) return null;
	int size = cin.readInt32();
	int limit = cin.pushLimit(size);
	TableData.Table ret = TableData.Table.parseFrom(cin);
	cin.popLimit(limit);
	cin.resetSizeCounter();
	return ret;
}
 
開發者ID:Jenner4S,項目名稱:unitimes,代碼行數:10,代碼來源:SessionRestore.java

示例6: parseInto

import com.google.protobuf.CodedInputStream; //導入方法依賴的package包/類
/**
 * Parses an entry off of the input into the map. This helper avoids allocaton of a {@link MapEntryLite} by parsing
 * directly into the provided {@link MapFieldLite}.
 *
 * @param map the map
 * @param input the input
 * @param extensionRegistry the extension registry
 * @throws IOException Signals that an I/O exception has occurred.
 */
public void parseInto(MapFieldLite<K, V> map, CodedInputStream input, ExtensionRegistryLite extensionRegistry)
        throws IOException {
    int length = input.readRawVarint32();
    final int oldLimit = input.pushLimit(length);
    K key = metadata.defaultKey;
    V value = metadata.defaultValue;

    while (true) {
        int tag = input.readTag();
        if (tag == 0) {
            break;
        }
        if (tag == CodedConstant.makeTag(KEY_FIELD_NUMBER, metadata.keyType.getWireType())) {
            key = parseField(input, extensionRegistry, metadata.keyType, key);
        } else if (tag == CodedConstant.makeTag(VALUE_FIELD_NUMBER, metadata.valueType.getWireType())) {
            value = parseField(input, extensionRegistry, metadata.valueType, value);
        } else {
            if (!input.skipField(tag)) {
                break;
            }
        }
    }

    input.checkLastTagWas(0);
    input.popLimit(oldLimit);
    map.put(key, value);
}
 
開發者ID:jhunters,項目名稱:jprotobuf,代碼行數:37,代碼來源:MapEntryLite.java

示例7: loadData

import com.google.protobuf.CodedInputStream; //導入方法依賴的package包/類
@NonNull
@Override
public FileDataSource loadData(InputStream inputStream, String filePath) throws Exception {
    long propertiesOffset = 0L;
    Track track = new Track();
    CodedInputStream input = CodedInputStream.newInstance(inputStream);
    boolean done = false;
    while (!done) {
        long offset = input.getTotalBytesRead();
        int tag = input.readTag();
        int field = WireFormat.getTagFieldNumber(tag);
        switch (field) {
            case 0:
                done = true;
                break;
            default: {
                throw new com.google.protobuf.InvalidProtocolBufferException("Unsupported proto field: " + tag);
            }
            case FIELD_VERSION: {
                // skip version
                input.skipField(tag);
                break;
            }
            case FIELD_POINT: {
                int length = input.readRawVarint32();
                int oldLimit = input.pushLimit(length);
                readPoint(track, input);
                input.popLimit(oldLimit);
                input.checkLastTagWas(0);
                break;
            }
            case FIELD_NAME: {
                propertiesOffset = offset;
                track.name = input.readBytes().toStringUtf8();
                break;
            }
            case FIELD_COLOR: {
                track.style.color = input.readUInt32();
                break;
            }
            case FIELD_WIDTH: {
                track.style.width = input.readFloat();
                break;
            }
        }
    }
    inputStream.close();
    track.id = 31 * filePath.hashCode() + 1;
    FileDataSource dataSource = new FileDataSource();
    dataSource.name = track.name;
    dataSource.tracks.add(track);
    track.source = dataSource;
    dataSource.propertiesOffset = propertiesOffset;
    return dataSource;
}
 
開發者ID:andreynovikov,項目名稱:trekarta,代碼行數:56,代碼來源:TrackManager.java


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