aboutsummaryrefslogtreecommitdiff
path: root/src/google
diff options
context:
space:
mode:
authorJon Skeet <jonskeet@google.com>2015-06-24 17:55:02 +0100
committerJon Skeet <jonskeet@google.com>2015-06-24 17:56:22 +0100
commit322ec531615b3f1aa7b25902ecb10e8673408cac (patch)
tree87ad38e9d5acd3f8f84ce558b2e92e62a65d805b /src/google
parentbfee2dfe137b07e64ebd46baf71d932d58d01b1f (diff)
downloadprotobuf-322ec531615b3f1aa7b25902ecb10e8673408cac.tar.gz
protobuf-322ec531615b3f1aa7b25902ecb10e8673408cac.tar.bz2
protobuf-322ec531615b3f1aa7b25902ecb10e8673408cac.zip
Revert the change to wire_format.h.
It seems too much code relies on the broken behaviour. See issue #493. Instead, we reimplement MakeTag just for C#, temporarily.
Diffstat (limited to 'src/google')
-rw-r--r--src/google/protobuf/compiler/csharp/csharp_field_base.cc2
-rw-r--r--src/google/protobuf/compiler/csharp/csharp_helpers.cc11
-rw-r--r--src/google/protobuf/compiler/csharp/csharp_helpers.h2
-rw-r--r--src/google/protobuf/compiler/csharp/csharp_message.cc3
-rw-r--r--src/google/protobuf/wire_format.h2
5 files changed, 16 insertions, 4 deletions
diff --git a/src/google/protobuf/compiler/csharp/csharp_field_base.cc b/src/google/protobuf/compiler/csharp/csharp_field_base.cc
index 0bfbc70e..c716e1bf 100644
--- a/src/google/protobuf/compiler/csharp/csharp_field_base.cc
+++ b/src/google/protobuf/compiler/csharp/csharp_field_base.cc
@@ -57,7 +57,7 @@ void FieldGeneratorBase::SetCommonFieldVariables(
// repeated fields varies by wire format. The wire format is encoded in the bottom 3 bits, which
// never effects the tag size.
int tag_size = internal::WireFormat::TagSize(descriptor_->number(), descriptor_->type());
- uint tag = internal::WireFormat::MakeTag(descriptor_);
+ uint tag = FixedMakeTag(descriptor_);
uint8 tag_array[5];
io::CodedOutputStream::WriteTagToArray(tag, tag_array);
string tag_bytes = SimpleItoa(tag_array[0]);
diff --git a/src/google/protobuf/compiler/csharp/csharp_helpers.cc b/src/google/protobuf/compiler/csharp/csharp_helpers.cc
index 76e2c850..39a53268 100644
--- a/src/google/protobuf/compiler/csharp/csharp_helpers.cc
+++ b/src/google/protobuf/compiler/csharp/csharp_helpers.cc
@@ -338,6 +338,17 @@ std::string FileDescriptorToBase64(const FileDescriptor* descriptor) {
return StringToBase64(fdp_bytes);
}
+// TODO(jonskeet): Remove this when internal::WireFormat::MakeTag works
+// properly...
+// Workaround for issue #493
+uint FixedMakeTag(const FieldDescriptor* field) {
+ internal::WireFormatLite::WireType field_type = field->is_packed()
+ ? internal::WireFormatLite::WIRETYPE_LENGTH_DELIMITED
+ : internal::WireFormat::WireTypeForFieldType(field->type());
+
+ return internal::WireFormatLite::MakeTag(field->number(), field_type);
+}
+
FieldGeneratorBase* CreateFieldGenerator(const FieldDescriptor* descriptor,
int fieldOrdinal) {
switch (descriptor->type()) {
diff --git a/src/google/protobuf/compiler/csharp/csharp_helpers.h b/src/google/protobuf/compiler/csharp/csharp_helpers.h
index bc77f43a..d2ee8fbe 100644
--- a/src/google/protobuf/compiler/csharp/csharp_helpers.h
+++ b/src/google/protobuf/compiler/csharp/csharp_helpers.h
@@ -97,6 +97,8 @@ std::string StringToBase64(const std::string& input);
std::string FileDescriptorToBase64(const FileDescriptor* descriptor);
+uint FixedMakeTag(const FieldDescriptor* descriptor);
+
FieldGeneratorBase* CreateFieldGenerator(const FieldDescriptor* descriptor, int fieldOrdinal);
bool HasRequiredFields(const Descriptor* descriptor);
diff --git a/src/google/protobuf/compiler/csharp/csharp_message.cc b/src/google/protobuf/compiler/csharp/csharp_message.cc
index 9580c167..a6c8e32b 100644
--- a/src/google/protobuf/compiler/csharp/csharp_message.cc
+++ b/src/google/protobuf/compiler/csharp/csharp_message.cc
@@ -194,8 +194,7 @@ void MessageGenerator::Generate(io::Printer* printer) {
"slash", field_names().size() > 0 ? "\"" : "");
std::vector<std::string> tags;
for (int i = 0; i < field_names().size(); i++) {
- uint32 tag = internal::WireFormat::MakeTag(
- descriptor_->FindFieldByName(field_names()[i]));
+ uint32 tag = FixedMakeTag(descriptor_->FindFieldByName(field_names()[i]));
tags.push_back(SimpleItoa(tag));
}
printer->Print(
diff --git a/src/google/protobuf/wire_format.h b/src/google/protobuf/wire_format.h
index 84270fee..8de491a6 100644
--- a/src/google/protobuf/wire_format.h
+++ b/src/google/protobuf/wire_format.h
@@ -290,7 +290,7 @@ class LIBPROTOBUF_EXPORT UnknownFieldSetFieldSkipper : public FieldSkipper {
inline WireFormatLite::WireType WireFormat::WireTypeForField(
const FieldDescriptor* field) {
- if (field->is_packed()) {
+ if (field->options().packed()) {
return WireFormatLite::WIRETYPE_LENGTH_DELIMITED;
} else {
return WireTypeForFieldType(field->type());