0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

個人メモ:Protocol Buffers2_作成例

Last updated at Posted at 2019-10-05

protobuf作成例

1 Student用のprotobuf作成

syntax = "proto3";

// 学生情報レクエスト
message StudentRequest {
    string name = 1;
    int32 age = 2;
}

// 学生情報レスポンス
message StudentResponse{
    int32 error = 1; // エラーcode
    string errmessage = 2; // エラーメッセージ
}

2 別のメッセージ参照

message StudentInfo {
    // Studentメッセージを参照し、配列表記する
    repeated Student info = 1;
}
message Student {
    string name = 1;
    int32 age = 2;
}

3 メッセージの中での参照

syntax = "proto3";
message StudentInfo {
    // メッセージの中のStudentを参照
    repeated Student info = 1;

    message Student {
        string name = 1;
        int32 age = 2;
    }
}

4 別のメッセージの定義参照

syntax = "proto3";
message StudentInfo {
    repeated Student info = 1;

    message Student {
        string name = 1;
        int32 age = 2;
    }
}

// StudentInfoメッセージにネストされた定義参照
message StudentMessage {
    StudentInfo.Student info = 1;
}

5 メッセージは任意の数のネスト可能

syntax="proto3";
message Manager {              // level 0
    message Leader {           // level 1
        message Menber {       // level 2
            string name = 1;
            int32 age = 2;
        }
    }
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?