Java 类com.google.protobuf.nano.MapFactories.MapFactory 实例源码

项目:diskusage    文件:InternalNano.java   
/**
 * 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;
}
项目:LB-Launcher    文件:InternalNano.java   
/**
 * 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;
}
项目:bazel    文件:InternalNano.java   
/**
 * 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;
}