protoc-3.10.1-osx-x86_64.zip
를 설치한다. ~/Downloads/protoc-3.10.1-osx-x86_64$ ll
total 8
drwxr-x---@ 3 dobby staff 96B 10 29 11:10 bin
drwxr-x---@ 4 dobby staff 128B 11 11 15:14 include
-rw-r-----@ 1 dobby staff 724B 10 29 11:10 readme.txt
이건 아직 안해봤는데 해봐야지..
syntax = "proto3";
package tutorial;
option java_package = "com.example.tutorial";
option java_outer_classname = "AddressBookProtos";
message Person {
required string name = 1;
required int32 id = 2;
string email = 3; //optional in proto3
enum PhoneType {
MOBILE = 0;
HOME = 1;
WORK = 2;
}
message PhoneNumber {
required string number = 1;
PhoneType type = 2;
}
repeated PhoneNumber phones = 4;
}
message AddressBook {
repeated Person people = 1;
}
protoc -I=$SRC_DIR --java_out=$DST_DIR $SRC_DIR/addressbook.proto
../protoc -I=./ --java_out=./ ./person.proto
// required string name = 1;
public boolean hasName();
public String getName();
// required int32 id = 2;
public boolean hasId();
public int getId();
// optional string email = 3;
public boolean hasEmail();
public String getEmail();
// repeated .tutorial.Person.PhoneNumber phones = 4;
public List<PhoneNumber> getPhonesList();
public int getPhonesCount();
public PhoneNumber getPhones(int index);
// required string name = 1;
public boolean hasName();
public java.lang.String getName();
public Builder setName(String value);
public Builder clearName();
// required int32 id = 2;
public boolean hasId();
public int getId();
public Builder setId(int value);
public Builder clearId();
// optional string email = 3;
public boolean hasEmail();
public String getEmail();
public Builder setEmail(String value);
public Builder clearEmail();
// repeated .tutorial.Person.PhoneNumber phones = 4;
public List<PhoneNumber> getPhonesList();
public int getPhonesCount();
public PhoneNumber getPhones(int index);
public Builder setPhones(int index, PhoneNumber value);
public Builder addPhones(PhoneNumber value);
public Builder addAllPhones(Iterable<PhoneNumber> value);
public Builder clearPhones();
java파일이 생성되면 다음과 같이 사용가능함
Person dobby =
Person.newBuilder()
.setId(1234)
.setName("dobby")
.setEmail("admin@dobby.work")
.addPhones(
Person.PhoneNumber.newBuilder()
.setNumber("123-4567")
.setType(Person.PhoneType.HOME))
.build();