상위 질문
타임라인
채팅
관점

프로토콜 버퍼

위키백과, 무료 백과사전

Remove ads

프로토콜 버퍼(Protocol Buffers, Protobuf)는 구조화된 데이터를 직렬화하는 방식이다. 유선이나 데이터 저장을 목적으로 서로 통신할 프로그램을 개발할 때 유용하다.

간략 정보 개발자, 발표일 ...

//polyline.proto
syntax = "proto2";

message Point {
  required int32 x = 1;
  required int32 y = 2;
  optional string label = 3;
}

message Line {
  required Point start = 1;
  required Point end = 2;
  optional string label = 3;
}

message Polyline {
  repeated Point point = 1;
  optional string label = 2;
}

위에서 C++ 버전의 프로토콜 버퍼 스키마를 만든 다음 C++ 소스 코드 파일 polyline.cpp은 아래와 같은 메시지 오브젝트를 사용할 수 있다:

// polyline.cpp
#include "polyline.pb.h"  // generated by calling "protoc polyline.proto"

Line* createNewLine(const std::string& name) {
  // create a line from (10, 20) to (30, 40)
  Line* line = new Line;
  line->mutable_start()->set_x(10);
  line->mutable_start()->set_y(20);
  line->mutable_end()->set_x(30);
  line->mutable_end()->set_y(40);
  line->set_label(name);
  return line;
}

Polyline* createNewPolyline() {
  // create a polyline with points at (10,10) and (20,20)
  Polyline* polyline = new Polyline;
  Point* point1 = polyline->add_point();
  point1->set_x(10);
  point1->set_y(10);
  Point* point2 = polyline->add_point();
  point2->set_x(20);
  point2->set_y(20);
  return polyline;
}
Remove ads

언어 지원

proto2C++, 자바, 파이썬을 위한 코드 생성기를 제공한다.[3]

타사 구현체는 자바스크립트를 지원한다.[4]

proto3C++, 자바(자바나노 포함), 파이썬, Go, 루비, 오브젝티브-C, C#를 위한 코드 생성기를 제공한다[5]. 3.0.0 베타 2부터 자바스크립트를 지원한다.[6]

타사 구현체는 , PHP, 스칼라, 줄리아를 지원한다.[7]

같이 보기

각주

외부 링크

Loading related searches...

Wikiwand - on

Seamless Wikipedia browsing. On steroids.

Remove ads