Jay Zhao
Jay Zhao

Reputation: 956

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:PBGeneratedMessage 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!

Upvotes: 1

Views: 805

Answers (1)

ovidiu
ovidiu

Reputation: 1129

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];

Upvotes: 2

Related Questions