An open API service indexing awesome lists of open source software.

https://github.com/oatpp/oatpp-protobuf

Use protobuf messages as regular oatpp DTOs
https://github.com/oatpp/oatpp-protobuf

cpp dto oatpp protobuf

Last synced: 7 months ago
JSON representation

Use protobuf messages as regular oatpp DTOs

Awesome Lists containing this project

README

          

# oatpp-protobuf

**Alpha**
**Since oatpp 1.2.0**

Protobuf messages integration with oatpp object-mapping framework.

Now you can use protobuf messages as regular oatpp DTOs!

More about Oat++:

- [Oat++ Website](https://oatpp.io/)
- [Oat++ Github Repository](https://github.com/oatpp/oatpp)

## Usage

Let's say we have a .proto file:

```proto
syntax = "proto3";

message User {
enum Role {
ADMIN = 0;
GUEST = 1;
}
string name = 1;
Role role = 2;
}
```

### In Endpoint

```cpp
ENDPOINT("POST", "createUser", createUser,
BODY_DTO(oatpp::protobuf::Object, user))
{
auto name = user->name();
auto role = user->role();
...
return createResponse(Status::CODE_200, "OK");
}
```

```cpp
ENDPOINT("GET", "getUser", getUser)
{
oatpp::protobuf::Object user = std::make_shared();
user->set_name("Ivan");
user->set_role(User_Role_GUEST);
return createDtoResponse(Status::CODE_200, user);
}
```

Output:

```json
{
"name": "Ivan",
"role": "GUEST"
}
```