开发者

Protocol Buffer for Objective-C

I'm using this library:

PB for ObjC http://code.google.com/p/metasyntactic/wiki/ProtocolBuffers.

The problem is I can't find an API to modify a PB object like setting a field of an object.

It seems that to modify an object like PBData:PBGenerat开发者_如何学GoedMessage I have to call one of three API:

- (PBData_Builder*) builder;
+ (PBData_Builder*) builder;
+ (PBData_Builder*) builderWithPrototype:(PBData*) prototype;

Any one of them just create a new one not modifying the existing one. Is there any API like PB for C++:

PBData* mutable_data(); 

So I can just modify an existing one.

Any ideas? Thanks!


The PBData class is read-only. To create your PBData with the values you want, just use the builder variant. Say you have this definition:

message Point {
  required float latitude = 1;
  required float longitude = 2;
  required float altitude = 3;
}

Then in your code you'd do something like this:

Point_Builder* pointBuilder = [Point builder];
pointBuilder.latitude = ...;
pointBuilder.longitude = ...;
pointBuilder.altitude = ...;
ProtoPoint* point = [pointBuilder build];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜