반응형
컴파일러 및 Exam 다운로드
(현, v3.11.4)
컴파일러
- https://github.com/protocolbuffers/protobuf/releases 에서 protoc-3.11.4-[OS타입].zip 다운로드
Exam
- https://github.com/protocolbuffers/protobuf/releases 에서 protoc-java-3.11.4.zip 다운로드
- examples/addressbook.proto를 사용하기 위해서...
.proto 준비
(Exam에서 ~\protobuf-3.11.4\examples\addressbook.proto)
// See README.txt for information and build instructions.
//
// Note: START and END tags are used in comments to define sections used in
// tutorials. They are not part of the syntax for Protocol Buffers.
//
// To get an in-depth walkthrough of this file and the related examples, see:
// https://developers.google.com/protocol-buffers/docs/tutorials
// [START declaration]
syntax = "proto3";
package tutorial;
import "google/protobuf/timestamp.proto";
// [END declaration]
// [START java_declaration]
option java_package = "com.example.tutorial";
option java_outer_classname = "AddressBookProtos";
// [END java_declaration]
// [START csharp_declaration]
option csharp_namespace = "Google.Protobuf.Examples.AddressBook";
// [END csharp_declaration]
// [START messages]
message Person {
string name = 1;
int32 id = 2; // Unique ID number for this person.
string email = 3;
enum PhoneType {
MOBILE = 0;
HOME = 1;
WORK = 2;
}
message PhoneNumber {
string number = 1;
PhoneType type = 2;
}
repeated PhoneNumber phones = 4;
google.protobuf.Timestamp last_updated = 5;
}
// Our address book file is just one of these.
message AddressBook {
repeated Person people = 1;
}
// [END messages]
`message` 는 직렬화해서 전달될 대상이다.
Person은 5개의 field가 정의 되어 있다. name, id, email, phones, last_updated
AddressBook은 1개의 field가 정의 되어 있다. people
(message명은 CamelCase, field명은 underscore_separated_names 형태로 사용한다.)
선언식에서 숫자값은 전달시 사이즈를 작게 해주기 위한 맵핑 값이므로 변경되서는 안되고 일정하여야 한다.
protoc.exe 실행
원하는 위치에서 실행
Java 파일 생성됨
반응형
'자율주행소식' 카테고리의 다른 글
자율 주행을 위한 클라이언트 시스템 (0) | 2020.10.13 |
---|---|
Sensoris schema 서버에 적용하기 #1 (0) | 2020.02.25 |
자율 주행 자동화 단계 (SAE) (0) | 2020.02.20 |
현대자동차, 앱티브(APTIV)와 조인트벤처 (0) | 2020.02.20 |
Sensoris (0) | 2020.02.19 |
댓글