aboutsummaryrefslogtreecommitdiff
path: root/src/google/protobuf/compiler/csharp/csharp_repeated_enum_field.cc
diff options
context:
space:
mode:
authorJon Skeet <skeet@pobox.com>2015-06-09 19:30:44 +0100
committerJon Skeet <skeet@pobox.com>2015-06-09 19:30:44 +0100
commite38294a62d7f37c0661273a9a26fda16d557423f (patch)
tree316989251907553408e7b32a12792f496333e075 /src/google/protobuf/compiler/csharp/csharp_repeated_enum_field.cc
parentf52426827e4d5e8da7d205af538799740b5199b9 (diff)
downloadprotobuf-e38294a62d7f37c0661273a9a26fda16d557423f.tar.gz
protobuf-e38294a62d7f37c0661273a9a26fda16d557423f.tar.bz2
protobuf-e38294a62d7f37c0661273a9a26fda16d557423f.zip
First pass at the mutable API. Quite a bit more to do - in particular, it's pretty slow right now.
Diffstat (limited to 'src/google/protobuf/compiler/csharp/csharp_repeated_enum_field.cc')
-rw-r--r--src/google/protobuf/compiler/csharp/csharp_repeated_enum_field.cc25
1 files changed, 9 insertions, 16 deletions
diff --git a/src/google/protobuf/compiler/csharp/csharp_repeated_enum_field.cc b/src/google/protobuf/compiler/csharp/csharp_repeated_enum_field.cc
index f5d5a126..ebbbf3be 100644
--- a/src/google/protobuf/compiler/csharp/csharp_repeated_enum_field.cc
+++ b/src/google/protobuf/compiler/csharp/csharp_repeated_enum_field.cc
@@ -49,6 +49,7 @@ namespace csharp {
RepeatedEnumFieldGenerator::RepeatedEnumFieldGenerator(
const FieldDescriptor* descriptor, int fieldOrdinal)
: FieldGeneratorBase(descriptor, fieldOrdinal) {
+ variables_["packed"] = descriptor->is_packed() ? "Packed" : "";
}
RepeatedEnumFieldGenerator::~RepeatedEnumFieldGenerator() {
@@ -75,27 +76,21 @@ void RepeatedEnumFieldGenerator::GenerateMergingCode(io::Printer* printer) {
void RepeatedEnumFieldGenerator::GenerateParsingCode(io::Printer* printer) {
printer->Print(
variables_,
- "input.ReadEnumArray<$type_name$>(tag, fieldName, result.$name$_);\n");
+ "input.ReadEnumArray<$type_name$>(tag, fieldName, $name$_);\n");
}
void RepeatedEnumFieldGenerator::GenerateSerializationCode(io::Printer* printer) {
// TODO(jonskeet): Originally, this checked for Count > 0 first.
// The Write* call should make that cheap though - no need to generate it every time.
- if (descriptor_->is_packed()) {
- printer->Print(
- variables_,
- "output.WritePackedEnumArray($number$, fieldNames[$field_ordinal$], $name$_);\n");
- } else {
- printer->Print(variables_,
- "output.WriteEnumArray($number$, fieldNames[$field_ordinal$], $name$_);\n");
- }
- printer->Print("}\n");
+ printer->Print(
+ variables_,
+ "output.Write$packed$EnumArray($number$, fieldNames[$field_ordinal$], $name$_);\n");
}
void RepeatedEnumFieldGenerator::GenerateSerializedSizeCode(io::Printer* printer) {
+ // TODO(jonskeet): Move all this code into CodedOutputStream? It's a lot to repeat everywhere...
printer->Print("{\n");
printer->Indent();
- // TODO(jonskeet): Move all this code into CodedOutputStream? It's a lot to repeat everywhere...
printer->Print(
variables_,
"int dataSize = 0;\n"
@@ -104,7 +99,7 @@ void RepeatedEnumFieldGenerator::GenerateSerializedSizeCode(io::Printer* printer
printer->Print(
variables_,
"foreach ($type_name$ element in $name$_) {\n"
- " dataSize += pb::CodedOutputStream.ComputeEnumSizeNoTag((long) element);\n"
+ " dataSize += pb::CodedOutputStream.ComputeEnumSizeNoTag(element);\n"
"}\n"
"size += dataSize;\n");
int tagSize = internal::WireFormat::TagSize(descriptor_->number(), descriptor_->type());
@@ -127,15 +122,13 @@ void RepeatedEnumFieldGenerator::GenerateSerializedSizeCode(io::Printer* printer
void RepeatedEnumFieldGenerator::WriteHash(io::Printer* printer) {
printer->Print(
variables_,
- "foreach($type_name$ i in $name$_) {\n"
- " hash ^= i.GetHashCode();\n"
- "}\n");
+ "hash ^= $name$_.GetHashCode();\n");
}
void RepeatedEnumFieldGenerator::WriteEquals(io::Printer* printer) {
printer->Print(
variables_,
- "if(!$name$_.Equals(other.$name$)) return false;\n");
+ "if(!$name$_.Equals(other.$name$_)) return false;\n");
}
void RepeatedEnumFieldGenerator::WriteToString(io::Printer* printer) {