Git Product home page Git Product logo

oatpp-protobuf's Introduction

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++:

Usage

Let's say we have a .proto file:

syntax = "proto3";

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

In Endpoint

ENDPOINT("POST", "createUser", createUser, 
         BODY_DTO(oatpp::protobuf::Object<User>, user)) 
{
  auto name = user->name();
  auto role = user->role();
  ...
  return createResponse(Status::CODE_200, "OK");
}
ENDPOINT("GET", "getUser", getUser) 
{
  oatpp::protobuf::Object<User> user = std::make_shared<User>();
  user->set_name("Ivan");
  user->set_role(User_Role_GUEST);
  return createDtoResponse(Status::CODE_200, user);
}

Output:

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

oatpp-protobuf's People

Contributors

lganzzzo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

oatpp-protobuf's Issues

I must be missing something ...

My interpretation using this was that I only needed to use the oatpp::protobuf::Object instead of the oatpp::Object template as in

ENDPOINT_INFO(hasPointToPointLOS) {
info->summary = "Given two instances of a location and height on a map determine if the two points have a LOS vector between them withing the fidelity of the number_of_steps to examine the LOS vector.";

info->addConsumes<oatpp::protobuf::Object<HasLineOfSightRequest>>("application/json");

info->addResponse<oatpp::protobuf::Object<HasLineOfSightResponse>>(Status::CODE_200, "application/json");

}
ENDPOINT("POST", "hasPointToPointLOS", hasPointToPointLOS,
BODY_DTO(oatpp::protobuf::Object, requestDto))
{
return createDtoResponse(Status::CODE_200, m_terrainService.hasPointToPointLineOfSight(requestDto));
}

however the swagger shows

"Unknown Type: oatpp::protobuf::AbstractObject"

as my payload json, and if push through and type in a valid json object for my request object, say such as

{
"locationFrom": {
"latitude": 0.0,
"longitude": 0.0
},
"locationTo": {
"latitude": 0.0,
"longitude": 0.0
},
"numberOfSteps": 10
}

That leads to deserialization error

{
"status": "ERROR",
"code": 500,
"message": "[oatpp::parser::json::mapping::Deserializer::deserialize()]: Error. No deserialize method for type 'oatpp::protobuf::AbstractObject'"
}

So, I must be missing something, and am ready to move onto a different C++ Rest framework.

There is some plumbing concerning getting the oatpp::protobuf::Object to get all that toInterpretation fromInterpretation working, but I don't see it yet.

FYI, I have this built against 1.2.5 oatpp on Windows 10 using VS 2017 Pro.

Build with test failed

Build with test failed
but with cmake -DOATPP_BUILD_TESTS=FALSE build complete

Console output

-- Configuring done
CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
PROTOLIB_LIBRARY
    linked by target "module-tests" in directory /tmp/oatpp-protobuf/test

-- Generating done
CMake Generate step failed.  Build files cannot be regenerated correctly

Build script

#!/bin/sh
# install components from repo
apk add git cmake wget unixodbc unixodbc-dev g++ make postgresql-dev protobuf protobuf-dev

# build and install oatpp
cd /tmp

set -- "oatpp" \
    "oatpp-websocket" \
    "oatpp-postgresql" \
    "oatpp-protobuf"
    
for i in "$@"; do
    echo "$i"
    git clone --depth=1 https://github.com/oatpp/$i
    mkdir -p $i/build
    cd $i/build
    cmake .. && make -j $(grep -c '^processor' /proc/cpuinfo) install
    cd ../../
done

cd /
rm -rf /tmp

Dockerfile

FROM alpine:latest AS builder
ADD ./build.sh /tmp
WORKDIR /tmp
RUN /tmp/build.sh
WORKDIR /

Oat++ 1.3 compatibility

I tried using this with Oat++ 1.3 and I get the following error:

CMake Error at CMakeLists.txt:41 (find_package):
  Could not find a configuration file for package "oatpp" that is compatible
  with requested version "1.2.5".

Is this module no longer supported?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.