lzw216 / protoc-gen-as3

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

Add ability to remove optional properties from a protobuf #14

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Lets say you have a protobuf:

message Person {
    optional string name = 1;
}

Inside the Person AS3 file you'll have:

private var name_:int;
private var hasName_:Boolean = false;
public function get hasName():Boolean {
    return hasName_;
}
public function set name(value:String):void {
    hasName_ = true;
    name_ = value;
}
public function get name():String {
    return name_;
}

My proposition is to add another method:

public function removeName():void {
    hasName_ = false;
    name_ = null;
}

Which would be handled like expected in writeToBuffer():

if (hasName) {
    WriteUtils.writeTag(output, WireType.LENGTH_DELIMITED, 1);
    WriteUtils.write_TYPE_STRING(output, name);
}

Doing 'person.name = null' simply sets name to null. It doesn't set hasName to 
false.

Original issue reported on code.google.com by william.bowers on 24 Sep 2010 at 2:16

GoogleCodeExporter commented 9 years ago
By the way, this is an enhancement request, not a defect. I just couldn't 
figure out how to set that.

Original comment by william.bowers on 24 Sep 2010 at 2:17

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
fixed in 0.8.9

Original comment by pop.atry@gmail.com on 25 Sep 2010 at 8:01

GoogleCodeExporter commented 9 years ago
Awesome :) Thanks!

Original comment by william.bowers on 25 Sep 2010 at 8:40