qykings / protobuf-actionscript3

Automatically exported from code.google.com/p/protobuf-actionscript3
0 stars 0 forks source link

default values for enums are ignored #20

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. create an enum 
2. create a message with a field using that enum
3. compile the protobuf

What is the expected output? What do you see instead?
the default value will be "-1";
it should be the first-declared value in the enum.

What version of the product are you using? On what operating system?

Please provide any additional information below.

the fix is relatively straight-forward.
in as3_enum_field.cc:
in SetEnumVariables(), change this line:
(*variables)["default"] = type + "." + default_value->name();
to this:
(*variables)["default"] = descriptor->enum_type()->name() + "." + 
default_value->name();

and in EnumFieldGenerator::GenerateMembers(), change this line:
"public var $name$:Number = -1; //No default value for now...\n")
to this:
"public var $name$:Number = $default$;\n");

.. i would also recommend changing enums from Number to int,
but that's an independent issue.

Original issue reported on code.google.com by DocOce...@gmail.com on 19 Jan 2010 at 9:02

GoogleCodeExporter commented 9 years ago
correction:
descriptor->enum_type()->name()
should be:
descriptor->enum_type()->full_name()

Original comment by DocOce...@gmail.com on 20 Jan 2010 at 1:32