// in proto file package tutorial message Person { .... // declare field:`field_type field_name` // eg. id, email, phone, name ......
message PhoneNumber }
message AddressBook{ Person ..name_of_variable }
// in proto.h file namespace tutorial{ // declare some methods and variables, and class
class AddressBook class Person class Person_PhoneNumber
// definition: class Person{ public: .... // implements message --------
/** standard message methods: * check or manipulate the entire msg **/ boolIsInitialized()const; // checks if all required field is set
stringDebugString()const; // return useful msg for debug
voidCopyFrom(const Person& from); // overwrites the message with the given message's values.
voidClear();: clears all the elements back to the empty state. // nested types ---------- typedef ...
// accesssors ----- methods for each field of msg Person declared in .proto file
// required int32 id = 2 # id inlineboolhas_id()const; inlinevoidclear_id(); staticconstint kIdFieldNumber = 2; // id inline int32_t id()const; inlinevoidset_id(int32_t value); // type int only have the most basic method:`has_`, `clear_`, `set_`
intmain(){ // initial tutrorial::AddressBook address_book; // class AddressBook have field person, type: msg Person // therefore have method: `add_person` PromptForAddress(address_book.add_person())
// address_book.add_person() is a pointer to object of class Person }