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
- Host: GitHub
- URL: https://github.com/oatpp/oatpp-protobuf
- Owner: oatpp
- License: apache-2.0
- Created: 2020-09-16T22:16:24.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2022-09-28T22:37:02.000Z (over 3 years ago)
- Last Synced: 2025-06-04T11:10:37.972Z (7 months ago)
- Topics: cpp, dto, oatpp, protobuf
- Language: C++
- Homepage: https://oatpp.io/
- Size: 45.9 KB
- Stars: 6
- Watchers: 2
- Forks: 4
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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"
}
```