本文整理匯總了Java中com.google.protobuf.nano.MapFactories.MapFactory類的典型用法代碼示例。如果您正苦於以下問題:Java MapFactory類的具體用法?Java MapFactory怎麽用?Java MapFactory使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
MapFactory類屬於com.google.protobuf.nano.MapFactories包,在下文中一共展示了MapFactory類的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: mergeMapEntry
import com.google.protobuf.nano.MapFactories.MapFactory; //導入依賴的package包/類
/**
* Merges the map entry into the map field. Note this is only supposed to
* be called by generated messages.
*
* @param map the map field; may be null, in which case a map will be
* instantiated using the {@link MapFactories.MapFactory}
* @param input the input byte buffer
* @param keyType key type, as defined in InternalNano.TYPE_*
* @param valueType value type, as defined in InternalNano.TYPE_*
* @param value an new instance of the value, if the value is a TYPE_MESSAGE;
* otherwise this parameter can be null and will be ignored.
* @param keyTag wire tag for the key
* @param valueTag wire tag for the value
* @return the map field
* @throws IOException
*/
@SuppressWarnings("unchecked")
public static final <K, V> Map<K, V> mergeMapEntry(
CodedInputByteBufferNano input,
Map<K, V> map,
MapFactory mapFactory,
int keyType,
int valueType,
V value,
int keyTag,
int valueTag) throws IOException {
map = mapFactory.forMap(map);
final int length = input.readRawVarint32();
final int oldLimit = input.pushLimit(length);
K key = null;
while (true) {
int tag = input.readTag();
if (tag == 0) {
break;
}
if (tag == keyTag) {
key = (K) input.readPrimitiveField(keyType);
} else if (tag == valueTag) {
if (valueType == TYPE_MESSAGE) {
input.readMessage((MessageNano) value);
} else {
value = (V) input.readPrimitiveField(valueType);
}
} else {
if (!input.skipField(tag)) {
break;
}
}
}
input.checkLastTagWas(0);
input.popLimit(oldLimit);
if (key == null) {
// key can only be primitive types.
key = (K) primitiveDefaultValue(keyType);
}
if (value == null) {
// message type value will be initialized by code-gen.
value = (V) primitiveDefaultValue(valueType);
}
map.put(key, value);
return map;
}