[protobuff] How to set a field of "Message" type? (C++)

704 views
Skip to first unread message

Maxim Leonovich

unread,
Jul 6, 2010, 6:01:29 PM7/6/10
to Protocol Buffers
I have a protocol like that:

message MSG {
enum MessageType {
//One enum value is needed for each message type
AUTHORIZATION_REQUEST = 1;
AUTHORIZATION_RESPONCE = 2;
}
required MessageType type = 1;
required int32 proto_version = 2 [default = 1];

//One value for each message
optional AuthorizationRequest auth_req_msg = 3;
optional AuthorizationResponce auth_resp_msg = 4;
}

message AuthorizationRequest {
required string login = 1;
required string password = 2;
}

message AuthorizationResponce {
enum Result {
ACCEPTED = 1;
INVALID_LOGIN_PASS = 2;
ACCOUNT_SUSPENDED = 3;
REJECTED = 4;
}
required Result result = 1;
optional string message = 2;
}


But in generated C++ class I have setters only for "type" and
"proto_version". For auth_msg_req and auth_msg_resp I have only

// optional .proto.AuthorizationResponce auth_resp_msg = 4;
inline bool has_auth_resp_msg() const;
inline void clear_auth_resp_msg();
static const int kAuthRespMsgFieldNumber = 4;
inline const ::proto::AuthorizationResponce& auth_resp_msg() const;
inline ::proto::AuthorizationResponce* mutable_auth_resp_msg();

But there is no setter here.
OK. How can I set a value for auth_resp and auth_req?
P.S. I have this problem only in C++. In Java all setters exists.

Daniel Wright

unread,
Jul 7, 2010, 12:19:06 PM7/7/10
to Maxim Leonovich, Protocol Buffers
In C++ you use the mutable_ accessor to set the value.  So for example, you could do:
  my_message.mutable_auth_resp_msg()->set_foo(1);


--
You received this message because you are subscribed to the Google Groups "Protocol Buffers" group.
To post to this group, send email to prot...@googlegroups.com.
To unsubscribe from this group, send email to protobuf+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/protobuf?hl=en.


Reply all
Reply to author
Forward
0 new messages