qykings / protobuf-actionscript3

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

Proto message with "length" attribute is never set #21

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

1. Create a proto message with "length" attribute 
message Toto {
    required uint32 length = 1;
}

2. Generate Actionscript 3 class for this message
3. Try to decode a binary proto message with protobuf-actionscript3

* What is the expected output?

The "length" property should be set

* What do you see instead?

The "length" property is never set (stays at default 0)

What version of the product are you using? On what operating system?
protobuf-actionscript3 2.3 / Windows

Please provide any additional information below.
I saw this in the source code of com.google.protobuf.Message (line 38) :

protected var fieldDescriptors:Array;

Nevertheless the fieldDesciptors is used as an associative array (line 251) :

protected function registerField(field:String, messageClass:String,
type:int, label:int, fieldNumber:int):void {

    //register descriptors only once        
      if (fieldDescriptors[field] == null)
          fieldDescriptors[field] = new Descriptor(field, messageClass, type,
label, fieldNumber);
}

In this function, the "length" field can never be added to fieldDescriptors
because fieldDescriptors already has a "length" attribute, inherited from
Array.

Besides, as mentioned in Adobe's documentation (
http://livedocs.adobe.com/flex/3/langref/Array.html) :
The Array class should never be used as an associative array, prefer Object
class.

Original issue reported on code.google.com by jerome.a...@gmail.com on 16 Feb 2010 at 9:55