Get the map factory per mergeFrom() call for JavaNano.

pull/204/head
Jisi Liu 10 years ago
parent d9a6f27bc3
commit 12d8a514c8
  1. 5
      javanano/src/main/java/com/google/protobuf/nano/InternalNano.java
  2. 11
      src/google/protobuf/compiler/javanano/javanano_helpers.cc
  3. 2
      src/google/protobuf/compiler/javanano/javanano_helpers.h
  4. 2
      src/google/protobuf/compiler/javanano/javanano_map_field.cc
  5. 5
      src/google/protobuf/compiler/javanano/javanano_message.cc

@ -30,6 +30,8 @@
package com.google.protobuf.nano;
import com.google.protobuf.nano.MapFactories.MapFactory;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.Arrays;
@ -406,12 +408,13 @@ public final class InternalNano {
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 = MapFactories.getMapFactory().forMap(map);
map = mapFactory.forMap(map);
final int length = input.readRawVarint32();
final int oldLimit = input.pushLimit(length);
K key = null;

@ -560,6 +560,17 @@ void SetBitOperationVariables(const string name,
(*variables)["different_" + name] = GenerateDifferentBit(bitIndex);
}
bool HasMapField(const Descriptor* descriptor) {
for (int i = 0; i < descriptor->field_count(); ++i) {
const FieldDescriptor* field = descriptor->field(i);
if (field->type() == FieldDescriptor::TYPE_MESSAGE &&
IsMapEntry(field->message_type())) {
return true;
}
}
return false;
}
} // namespace javanano
} // namespace compiler
} // namespace protobuf

@ -187,6 +187,8 @@ inline bool IsMapEntry(const Descriptor* descriptor) {
descriptor->file()->syntax() == FileDescriptor::SYNTAX_PROTO3;
}
bool HasMapField(const Descriptor* descriptor);
} // namespace javanano
} // namespace compiler
} // namespace protobuf

@ -134,7 +134,7 @@ void MapFieldGenerator::
GenerateMergingCode(io::Printer* printer) const {
printer->Print(variables_,
"this.$name$ = com.google.protobuf.nano.InternalNano.mergeMapEntry(\n"
" input, this.$name$,\n"
" input, this.$name$, mapFactory,\n"
" com.google.protobuf.nano.InternalNano.$key_desc_type$,\n"
" com.google.protobuf.nano.InternalNano.$value_desc_type$,\n"
" $value_default$,\n"

@ -345,6 +345,11 @@ void MessageGenerator::GenerateMergeFromMethods(io::Printer* printer) {
"classname", descriptor_->name());
printer->Indent();
if (HasMapField(descriptor_)) {
printer->Print(
"com.google.protobuf.nano.MapFactories.MapFactory mapFactory =\n"
" com.google.protobuf.nano.MapFactories.getMapFactory();\n");
}
printer->Print(
"while (true) {\n");

Loading…
Cancel
Save