Skip to content

EN.03.10.01.Protocol Buffers

stormcat24 edited this page Oct 30, 2014 · 2 revisions

Protocol Buffers is serialization format developed by Google. In Protocol Buffers, defines data structure by proto file.

On Aeromock, you've only have to make data file related to proto file and it respond binary response of Protocol Buffers. However, protobuf mode cannot coexist template mode.

project.yaml

When configure protobuf and data section at project.yaml, be able to respond to binary data of Protocol Buffers.

protobuf.root

Root directory of proto file. Specify a relative path from project root path.

protobuf:
  root: ./protobuf

protobuf.api (optional)

In the case of sub directory under root directory is exist, no need request url with /api by defining apiPrefix.

protobuf:
  root: ./protobuf
  apiPrefix: /api

data.root

Root directory of proto data file. Specify a relative path from project root path.

protobuf:
  root: ./protobuf
  apiPrefix: /api

data:
  root: ./data

Relation of proto file to data file

Locate proto file and data file at same hierarchy.

Example

proto_root/path1/test.proto -> data_root/path1/test.yaml

proto data file

Specification of proto data file is the save as JSON API. In addition, there specialized specification on proto data file.

__type

On the specification of Protocol Buffers, can define multiple messages at a proto file. That is, you need to specify message type be used as response message type in proto data file, by defining __type in data file.

For example, there is a proto file such as the following.

package protobuf.api;

import "schema/user.proto";

message TestRequest {
    required int32 prop1 = 1;
    required string prop2 = 2;
}

message TestResponse {
    required int32 prop1 = 1;
    required string prop2 = 2;
    required int64 prop3 = 3;
    repeated string prop4 = 4;
    required schema.TestUser prop5 = 5;
    optional int64 prop6 = 6 [default = 1];
}

If you use TestResponse as response message type, describe data file as the following.

__type: TestResponse
prop1: 100
prop2: prop2value
prop3: 11111111111
prop4:
  - "1111"
  - "2222"
  - "3333"
prop5:
  id: 1000
  name: testuser
Clone this wiki locally