google/protocol-buffers

Protocol Buffers : Tutorials Common Comment, 프로토콜 버퍼 공통 설명

C/H 2018. 8. 22. 20:30

Protocol Buffer Basics

This tutorial provides a basic Python programmer's introduction to working with protocol buffers. By walking through creating a simple example application, it shows you how to
튜토리얼에서는 프로토콜 버퍼를 사용하는 Language 프로그래머의 기본소개를 제공한다. 간단한 예제 응용프로그램을 만드는 과정을 통해, 그것은 어떻게 하는 지를 보여준다.

  • Define message formats in a .proto file.
    .proto 파일에 메시지 형식 정의.
  • Use the protocol buffer compiler.
    .proto 파일에 메시지 형식 정의
  • Use the Python protocol buffer API to write and read messages.
    Python 프로토콜 버퍼 API를 사용하여 메시지를 쓰고 읽습니다.

이것은 Language에서 프로토콜 버퍼를 사용하는것에 대한 포괄적인 가이드가 아니다. 자세한 참조정보는 프로토콜 버퍼 언어 안내서, Lanuage API, Language Generated Code Guide 및 Encoding Reference를 참조하세요.

Why Use Protocol Buffers? 프로토콜 버퍼를 사용하는 이유

The example we're going to use is a very simple "address book" application that can read and write people's contact details to and from a file. Each person in the address book has a name, an ID, an email address, and a contact phone number.
사용할 예는 매우 간단한 "주소록" 응용프로그램으로, 사람들의 연락처 세부 정보를 읽고 파일에서 쓸 수 있다. 주소록에 있는 각 사람은 이름, ID, 이메일 주소, 연락처 전화번호를 가지고 있다.

How do you serialize and retrieve structured data like this? There are a few ways to solve this problem.
구조화 된 데이터를 어떻게 직렬화하고 검색할까? 문제를 해결할 수있는 몇 가지 방법이 있다.

  • Use Python pickling. This is the default approach since it's built into the language, but it doesn't deal well with schema evolution, and also doesn't work very well if you need to share data with applications written in C++ or Java.
    파이썬 피클링을 사용하라. 이것은 언어에 내장된 기본 접근법이지만 스키마진화에 대해서는 잘 다루지 않으며 C++이나 Java로 작성된 응용프로그램과 데이터를 공유해야하는 경우에는 제대로 작동하지 않는다.
  • You can invent an ad-hoc way to encode the data items into a single string – such as encoding 4 ints as "12:3:-23:67". This is a simple and flexible approach, although it does require writing one-off encoding and parsing code, and the parsing imposes a small run-time cost. This works best for encoding very simple data.
    "12:3:-23:67"에서 4개의 정수로 인코딩하는 것과 같이 데이터항목을 단일 문자열로 인코딩하는 특별한 방법을 고안 할 수 있다. 일회용 인코딩 및 코드파싱이 필요하고, 구문 분석이 런타임 비용을 부과하더라도 간단하고 유연한 접근 방식이다. 이는 매우 간단한 데이터를 인코딩할 때 가장 잘 작동한다.
  • Serialize the data to XML. This approach can be very attractive since XML is (sort of) human readable and there are binding libraries for lots of languages. This can be a good choice if you want to share data with other applications/projects. However, XML is notoriously space intensive, and encoding/decoding it can impose a huge performance penalty on applications. Also, navigating an XML DOM tree is considerably more complicated than navigating simple fields in a class normally would be.
    데이터를 XML로 직렬화하라. 이 접근법은 XML이 사람이 읽을수있는 (일종의)사람이고, 많은 언어에 대한 바인딩 라이브러리가 있기 때문에 매우 매력적일수 있다. 다른 응용프로그램/프로젝트와 데이터를 공유하려면 이 옵션을 선택하는 것이 좋다. 그러나 XML은 공간이 많이 소요되는 것으로 알려져 있으며, 인코딩/디코딩은 응용프로그램에 큰 성능저하를 줄수 있다. 또한 XML DOM트리를 탐색하는 것은 일반적으로 클래스의 간단한 필드를 탐색하는 것보다 훨씬 복잡합니다.

Protocol buffers are the flexible, efficient, automated solution to solve exactly this problem. With protocol buffers, you write a .proto description of the data structure you wish to store. From that, the protocol buffer compiler creates a class that implements automatic encoding and parsing of the protocol buffer data with an efficient binary format. The generated class provides getters and setters for the fields that make up a protocol buffer and takes care of the details of reading and writing the protocol buffer as a unit. Importantly, the protocol buffer format supports the idea of extending the format over time in such a way that the code can still read data encoded with the old format.
프로토콜 버퍼는 이 문제를 정확하게 해결할수 있는 유연하고, 효율적인 자동솔루션이다. 프로토콜 버퍼를 사용하여 저장하려는 데이터 구조에 대한 .proto 설명을 작성한다. 프로토콜 버퍼 컴파일러는 효율적인 바이너리 형식으로 프로토콜 버퍼 데이터의 자동 인코딩 및 구문분석을 구현하는 클래스를 만든다. 생성된 클래스는 프로토콜 버퍼를 구성하는 필드에 대한 getter 및 setter를 제공하며 프로토콜 버퍼 읽기 및 쓰기 단위를 자세히 처리한다. 중요한 것은 프로토콜 버퍼 형식은 코드가 이전 형식으로 인코딩 된 데이터를 읽을 수있는 방식으로 시간이 지남에 따라 형식을 확장한다는 아이디어를 지원한다는 것이다.

Release Package

예제 코드 다운로드
  • 프로토콜 버퍼의 최신 릴리스는 릴리즈 페이지에서 찾을 수 있다.
  • 최신버전을 사용할것을 권장한다. 이전버전이 필요한 경우 이전 버전을 사용하라.
Protocol Buffers v3.6.1 Release List : 2018.08.20 현재
  • protobuf-all-3.6.1.tar.gz
  • protobuf-all-3.6.1.zip
  • protobuf-cpp-3.6.1.tar.gz
  • protobuf-cpp-3.6.1.zip
  • protobuf-csharp-3.6.1.tar.gz
  • protobuf-csharp-3.6.1.zip
  • protobuf-java-3.6.1.tar.gz
  • protobuf-java-3.6.1.zip
  • protobuf-js-3.6.1.tar.gz
  • protobuf-js-3.6.1.zip
  • protobuf-objectivec-3.6.1.tar.gz
  • protobuf-objectivec-3.6.1.zip
  • protobuf-php-3.6.1.tar.gz
  • protobuf-php-3.6.1.zip
  • protobuf-python-3.6.1.tar.gz
  • protobuf-python-3.6.1.zip
  • protobuf-ruby-3.6.1.tar.gz
  • protobuf-ruby-3.6.1.zip
  • protoc-3.6.1-linux-aarch_64.zip
  • protoc-3.6.1-linux-x86_32.zip
  • protoc-3.6.1-linux-x86_64.zip
  • protoc-3.6.1-osx-x86_32.zip
  • protoc-3.6.1-osx-x86_64.zip
  • protoc-3.6.1-win32.zip
  • Source code (zip)
  • Source code (tar.zip)

source Code


반응형