aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/google/protobuf/compiler/ruby
diff options
context:
space:
mode:
authorGravatar Josh Haberman <jhaberman@gmail.com>2015-07-15 11:05:10 -0700
committerGravatar Josh Haberman <jhaberman@gmail.com>2015-07-16 12:25:55 -0700
commit181c7f26360429b236ab833c746d10d97811931f (patch)
tree3abdbaf4abb0115c17892bcf2a1629c9475f147c /src/google/protobuf/compiler/ruby
parentfde6e89f99eda04a4f1b8677bcea07e6c2040405 (diff)
Added Ruby to conformance tests.
This involved fixing a few important bugs in the Ruby implementation -- mostly cases of mixing upb field types and descriptor types (upb field types do not distinguish between int/sint/fixed/sfixed like descriptor types do). Also added protobuf-specific exceptions so parse errors can be caught specifically. Change-Id: Ib49d3db976900b2c6f3455c8b88af52cfb86e036
Diffstat (limited to 'src/google/protobuf/compiler/ruby')
-rw-r--r--src/google/protobuf/compiler/ruby/ruby_generated_code.rb6
-rw-r--r--src/google/protobuf/compiler/ruby/ruby_generator.cc34
2 files changed, 24 insertions, 16 deletions
diff --git a/src/google/protobuf/compiler/ruby/ruby_generated_code.rb b/src/google/protobuf/compiler/ruby/ruby_generated_code.rb
index 100d6fa7..49b23fbe 100644
--- a/src/google/protobuf/compiler/ruby/ruby_generated_code.rb
+++ b/src/google/protobuf/compiler/ruby/ruby_generated_code.rb
@@ -13,7 +13,7 @@ Google::Protobuf::DescriptorPool.generated_pool.build do
optional :optional_double, :double, 6
optional :optional_float, :float, 7
optional :optional_string, :string, 8
- optional :optional_bytes, :string, 9
+ optional :optional_bytes, :bytes, 9
optional :optional_enum, :enum, 10, "A.B.C.TestEnum"
optional :optional_msg, :message, 11, "A.B.C.TestMessage"
repeated :repeated_int32, :int32, 21
@@ -24,7 +24,7 @@ Google::Protobuf::DescriptorPool.generated_pool.build do
repeated :repeated_double, :double, 26
repeated :repeated_float, :float, 27
repeated :repeated_string, :string, 28
- repeated :repeated_bytes, :string, 29
+ repeated :repeated_bytes, :bytes, 29
repeated :repeated_enum, :enum, 30, "A.B.C.TestEnum"
repeated :repeated_msg, :message, 31, "A.B.C.TestMessage"
map :map_int32_string, :int32, :string, 61
@@ -47,7 +47,7 @@ Google::Protobuf::DescriptorPool.generated_pool.build do
optional :oneof_double, :double, 46
optional :oneof_float, :float, 47
optional :oneof_string, :string, 48
- optional :oneof_bytes, :string, 49
+ optional :oneof_bytes, :bytes, 49
optional :oneof_enum, :enum, 50, "A.B.C.TestEnum"
optional :oneof_msg, :message, 51, "A.B.C.TestMessage"
end
diff --git a/src/google/protobuf/compiler/ruby/ruby_generator.cc b/src/google/protobuf/compiler/ruby/ruby_generator.cc
index a9b6837e..9692f1bf 100644
--- a/src/google/protobuf/compiler/ruby/ruby_generator.cc
+++ b/src/google/protobuf/compiler/ruby/ruby_generator.cc
@@ -47,7 +47,7 @@ namespace compiler {
namespace ruby {
// Forward decls.
-std::string IntToString(uint32 value);
+std::string IntToString(int32 value);
std::string StripDotProto(const std::string& proto_file);
std::string LabelForField(google::protobuf::FieldDescriptor* field);
std::string TypeName(google::protobuf::FieldDescriptor* field);
@@ -64,7 +64,7 @@ void GenerateEnumAssignment(
const google::protobuf::EnumDescriptor* en,
google::protobuf::io::Printer* printer);
-std::string IntToString(uint32 value) {
+std::string IntToString(int32 value) {
std::ostringstream os;
os << value;
return os.str();
@@ -85,17 +85,25 @@ std::string LabelForField(const google::protobuf::FieldDescriptor* field) {
}
std::string TypeName(const google::protobuf::FieldDescriptor* field) {
- switch (field->cpp_type()) {
- case FieldDescriptor::CPPTYPE_INT32: return "int32";
- case FieldDescriptor::CPPTYPE_INT64: return "int64";
- case FieldDescriptor::CPPTYPE_UINT32: return "uint32";
- case FieldDescriptor::CPPTYPE_UINT64: return "uint64";
- case FieldDescriptor::CPPTYPE_DOUBLE: return "double";
- case FieldDescriptor::CPPTYPE_FLOAT: return "float";
- case FieldDescriptor::CPPTYPE_BOOL: return "bool";
- case FieldDescriptor::CPPTYPE_ENUM: return "enum";
- case FieldDescriptor::CPPTYPE_STRING: return "string";
- case FieldDescriptor::CPPTYPE_MESSAGE: return "message";
+ switch (field->type()) {
+ case FieldDescriptor::TYPE_INT32: return "int32";
+ case FieldDescriptor::TYPE_INT64: return "int64";
+ case FieldDescriptor::TYPE_UINT32: return "uint32";
+ case FieldDescriptor::TYPE_UINT64: return "uint64";
+ case FieldDescriptor::TYPE_SINT32: return "sint32";
+ case FieldDescriptor::TYPE_SINT64: return "sint64";
+ case FieldDescriptor::TYPE_FIXED32: return "fixed32";
+ case FieldDescriptor::TYPE_FIXED64: return "fixed64";
+ case FieldDescriptor::TYPE_SFIXED32: return "sfixed32";
+ case FieldDescriptor::TYPE_SFIXED64: return "sfixed64";
+ case FieldDescriptor::TYPE_DOUBLE: return "double";
+ case FieldDescriptor::TYPE_FLOAT: return "float";
+ case FieldDescriptor::TYPE_BOOL: return "bool";
+ case FieldDescriptor::TYPE_ENUM: return "enum";
+ case FieldDescriptor::TYPE_STRING: return "string";
+ case FieldDescriptor::TYPE_BYTES: return "bytes";
+ case FieldDescriptor::TYPE_MESSAGE: return "message";
+ case FieldDescriptor::TYPE_GROUP: return "group";
default: assert(false); return "";
}
}