google/protocol-buffers

Protocol Buffers : Language Guide (proto3) - Packages

C/H 2018. 9. 5. 08:30

Index

Packages 패키지

You can add an optional package specifier to a .proto file to prevent name clashes between protocol message types.
옵션 패키지 지정자를 .proto 파일에 추가하여 프로토콜 메시지 유형 간의 이름 충돌을 방지할 수 있다.

package foo.bar;
message Open { ... }

You can then use the package specifier when defining fields of your message type:
그런 다음 메시지 유형의 필드를 정의할 때 패키지 지정자를 사용할 수 있다.

message Foo {
    ...
    foo.bar.Open open = 1;
    ...
}

The way a package specifier affects the generated code depends on your chosen language:
패키지 지정자가 생성된 코드에 영향을 미치는 방법은 선택한 언어에 따라 다르다.

  • In C++ the generated classes are wrapped inside a C++ namespace. For example, Open would be in the namespace foo::bar.
    C++에서 생성된 클래스는 C++ 네임스페이스 안에 포함된다. 예를 들어, Open은 네임스페이스 foo::bar에 있다.
  • In Java, the package is used as the Java package, unless you explicitly provide an option java_package in your .proto file.
    Java에서 패키지는 .proto 파일에 java_package 옵션을 명시적으로 제공하지 않는 한 Java 패키지로 사용된다.
  • In Python, the package directive is ignored, since Python modules are organized according to their location in the file system.
    Python 모듈은 파일 시스템의 위치에 따라 구성되므로 Python에서는 패키지 명령이 무시된다.
  • In Go, the package is used as the Go package name, unless you explicitly provide an option go_package in your .proto file.
    Go에서 패키지는 .proto 파일에 go_package 옵션을 명시적으로 제공하지 않는 한 Go 패키지 이름으로 사용된다.
  • In Ruby, the generated classes are wrapped inside nested Ruby namespaces, converted to the required Ruby capitalization style (first letter capitalized; if the first character is not a letter, PB_ is prepended). For example, Open would be in the namespace Foo::Bar.
    Ruby에서 생성된 클래스는 중첩된 Ruby 네임스페이스로 포장되어 필요한 Ruby 대문자로 변환된다(첫 번째 문자가 대문자로 변환됨; 첫 번째 문자가 문자가 아닌 경우 PB_가 미리 지정됨). 예를 들어, Open은 네임스페이스 foo::bar에 있다.
  • In C# the package is used as the namespace after converting to PascalCase, unless you explicitly provide an option csharp_namespace in your .proto file. For example, Open would be in the namespace Foo.Bar.
    C#에서 패키지는 .proto 파일에 csharp_namespace 옵션을 명시적으로 제공하지 않는 한 PascalCase로 변환한 후 네임스페이스로 사용된다. 예를 들어 Open은 네임스페이스 Foo.Bar에 있다.

Packages and Name Resolution 패키지 및 이름 결정

Type name resolution in the protocol buffer language works like C++: first the innermost scope is searched, then the next-innermost, and so on, with each package considered to be "inner" to its parent package. A leading '.' (for example, .foo.bar.Baz) means to start from the outermost scope instead.
프로토콜 버퍼 언어의 이름 확인은 C++와 같이 작동한다. 먼저 가장 안쪽 범위를 검색한 후 다음 가장 안쪽 패키지를 검색한 후 각 패키지를 상위 패키지에 "inner"로 간주한다. 선행 '.'(예: .foo.bar.Baz) 대신 가장 바깥쪽 범위에서 시작하는 것을 의미한다.

The protocol buffer compiler resolves all type names by parsing the imported .proto files. The code generator for each language knows how to refer to each type in that language, even if it has different scoping rules.
프로토콜 버퍼 컴파일러는 가져온 .proto 파일을 구문 분석하여 모든 유형 이름을 해결한다. 각 언어의 코드 생성기는 범위 지정 규칙이 다르더라도 해당 언어의 각 유형을 참조하는 방법을 알고 있다.

반응형