mustang2247 / protoc-gen-as3

Automatically exported from code.google.com/p/protoc-gen-as3
BSD 2-Clause "Simplified" License
0 stars 0 forks source link

no dynamic class #23

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I would like to use no dynamic class.
And keep unknown field value.

Best regards

Original issue reported on code.google.com by mk.trans...@gmail.com on 7 Nov 2011 at 8:19

GoogleCodeExporter commented 9 years ago
Could you express your point clearly? I don't know what you are talking about.

Original comment by pop.atry@gmail.com on 8 Nov 2011 at 12:55

GoogleCodeExporter commented 9 years ago
Thank you for your reply. 

My writing was too brief. 

1. dynamic class

Generate from the following messages. 

//----- message

message KeyValue {
   optional string Key = 1;
   optional string Value = 2;
   extensions 1000 to max;
}

The following classes are generated. 

//----- generated class

public dynamic final class KeyValue extends Array implements 
flash.utils.IExternalizable, com.netease.protobuf.IMessage {
       ^^^^^^^ <- dynamic class

}

Since dynamic class is an obstacle of debugging, I do not want to use. 

2. unknown field

An addition is needed for a message. 

//----- message

message KeyValue {
   optional string Key = 1;
   optional string Value = 2;
   optional string Description = 3; // ADD
   extensions 1000 to max;
}

Description is the unknown field for the class generated before. 

Version 0.9.1, This field value lost by the writeExternal method. 
Version 1.0.0-rc6, When data with this field was received, the exception 
occurred by the readFromSlice method. 

Original comment by mk.trans...@gmail.com on 9 Nov 2011 at 1:30

GoogleCodeExporter commented 9 years ago
It had forgotten to write an important thing. 
I have deleted dynamic declaration. 

Original comment by mk.trans...@gmail.com on 9 Nov 2011 at 1:38

GoogleCodeExporter commented 9 years ago
1. v0.9.x will use dynamic class if the message has extensions. v1.0.x will 
always use dynamic class to hold unknown fields and extensions.
2. v1.0.x will store unknown fields. I tested your message and I didn't see 
exception occurred.

Original comment by pop.atry@gmail.com on 9 Nov 2011 at 6:41

GoogleCodeExporter commented 9 years ago
v1.0.0-rc6

If there is dynamic declaration, Don't see exception.
I have deleted dynamic declaration, I receive the following error.

ReferenceError: Error #1069: KeyValue にプロパティ 26 
が見つからず、デフォルト値もありません。
    at com.netease.protobuf::Message/readUnknown()[C:\cygwin\home\Atry\Desktop\protoc-gen-as3\as3\com\netease\protobuf\Message.as:156]
    at com.netease.protobuf::Message/readExtensionOrUnknown()[C:\cygwin\home\Atry\Desktop\protoc-gen-as3\as3\com\netease\protobuf\Message.as:174]
    at KeyValue/readFromSlice()[C:\FlashDevelop\ProtoBuf\KeyValue.as:97]
    at ProtoBuf()[C:\FlashDevelop\ProtoBuf\ProtoBuf.as:31]

//--- sample

package {

    import com.netease.protobuf.*;
    import flash.display.Sprite;
    import flash.utils.ByteArray;
    import flash.utils.IDataInput;
    import com.hurlant.util.Base64;

    public class ProtoBuf extends Sprite
    {
        public function ProtoBuf()
        {           
            /*
            var kv:KeyValue = new KeyValue();   // This is new "KeyValue", Include "Description".
            kv.key = "Key";
            kv.value = "Value";
            kv.description = "Description";

            var data:ByteArray = new ByteArray();

            kv.writeTo(data);

            trace(Base64.encodeByteArray(data)); // CgNLZXkSBVZhbHVlGgtEZXNjcmlwdGlvbg==

            */

            var dataString:String = "CgNLZXkSBVZhbHVlGgtEZXNjcmlwdGlvbg==";
            var data:ByteArray = Base64.decodeToByteArray(dataString);

            var kv:KeyValue = new KeyValue();   // This is old "KeyValue", Unknowing "Description" and remove dynamic. 
            kv.readFromSlice(data, 0);          // ReferenceError
        }
    }
}

It is not a defect that an error occurs.
I wish to support Unknown and Extension without making a dynamic declaration. 

Original comment by mk.trans...@gmail.com on 9 Nov 2011 at 10:55

GoogleCodeExporter commented 9 years ago
I would also like the dynamic word to be removed. I don't like it because it 
prevents getting compiler errors if you use wrong attributes. 

Original comment by TiRSO.00 on 9 Nov 2011 at 5:05

GoogleCodeExporter commented 9 years ago
This project is aim to implement protobuf in a NATIVE way with minimum API. 
`dynamic` is the native way for extensions and unknown fields. Other solutions, 
such as wrap extensions and unknown fields in another Array/Object will create 
more object, and these solutions all introduce more API other than 
ActionScript's native way.

Original comment by pop.atry@gmail.com on 10 Nov 2011 at 1:05

GoogleCodeExporter commented 9 years ago
During development, I delete dynamic declaration.
When deployment, I give it.

Thank you.

Original comment by mk.trans...@gmail.com on 10 Nov 2011 at 1:51

GoogleCodeExporter commented 9 years ago

Original comment by pop.atry@gmail.com on 10 Nov 2011 at 6:45

GoogleCodeExporter commented 9 years ago
Issue 43 has been merged into this issue.

Original comment by pop.atry@gmail.com on 11 May 2013 at 4:32