by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    oat++
    @oatpp_io_twitter
    please see the full working example:
    
    #include "oatpp/parser/json/mapping/ObjectMapper.hpp"
    #include "oatpp/core/macro/codegen.hpp"
    #include <iostream>
    
    #include OATPP_CODEGEN_BEGIN(DTO)
    
    class MyBaseDto : public oatpp::data::mapping::type::Object {
    
      DTO_INIT(MyBaseDto, Object)
    
      DTO_FIELD(String, myBaseDtoField);
    
    };
    
    class HeaderDto : public MyBaseDto /* Should also extend a class here */ {
    
      DTO_INIT(HeaderDto, MyBaseDto)
    
      DTO_FIELD(Int64, time);
    
    };
    
    class ResponseDto : public oatpp::data::mapping::type::Object {
    
      DTO_INIT(ResponseDto, Object)
    
      DTO_FIELD(HeaderDto::ObjectWrapper, header) = HeaderDto::createShared(); // Don't forger to initialize object
    
    };
    
    #include OATPP_CODEGEN_END(DTO)
    
    void run() {
    
      auto dto = ResponseDto::createShared();
      dto->header->time = 0;
      dto->header->myBaseDtoField = "Hello base class";
    
      auto objectMapper = oatpp::parser::json::mapping::ObjectMapper::createShared();
    
      auto json = objectMapper->writeToString(dto);
    
      std::cout << json->c_str() << std::endl;
    
    }
    
    int main() {
    
      oatpp::base::Environment::init();
      run();
      oatpp::base::Environment::destroy();
    
      return 0;
    }
    MJLHThomassen-Sorama
    @MJLHThomassen-Sorama
    @oatpp_io_twitter ill try that, probably the initilizing the object went wrong, ill let you know if this works!
    oat++
    @oatpp_io_twitter
    Please also note that you have to extend object as a regular c++ object too:
    class HeaderDto : public MyBaseDto /* Should also extend a class here */ {
    
      DTO_INIT(HeaderDto, MyBaseDto /* mention your base class here */)
    
      DTO_FIELD(Int64, time);
    
    };
    MJLHThomassen-Sorama
    @MJLHThomassen-Sorama
    Yeah i already had that
    oat++
    @oatpp_io_twitter
    Ok then! Please let me know how it goes.
    MJLHThomassen-Sorama
    @MJLHThomassen-Sorama
    yes this seems to work
    thanks alot
    oat++
    @oatpp_io_twitter
    You are welcome, please ping me in case you have more questions
    MJLHThomassen-Sorama
    @MJLHThomassen-Sorama
    I was missing information on this in the documentation, and also examples / test / other code from modules (like the swagger module) does not utilize this in this way. Perhaps this can be added to the docs?
    oat++
    @oatpp_io_twitter
    Sure, good point!
    MJLHThomassen-Sorama
    @MJLHThomassen-Sorama
    just for your info, currently evaluating Oat++ as possible replacement for CPP REST SDK for cross platform (Windows, NVidia Jetson and Xilinx Zync FPGA/ARM core) application
    so the help is very much apreciated!
    oat++
    @oatpp_io_twitter
    Cool! Are you planning to use Oat++ simple API or Async?
    MJLHThomassen-Sorama
    @MJLHThomassen-Sorama
    not sure yet, im leaning towards simple api since we are mainly targetting embedded systems where there will be not many concurrent api connections
    oat++
    @oatpp_io_twitter
    That's a good decision - Simple API is more developed and better tested
    Benedikt-Alexander Mokroß
    @bamkrs
    @MJLHThomassen-Sorama I already run oatpp successfully on a simple armv7 Code with 64mb RAM and even an stupid MIPS cpu with 600mhz and 128mb RAM. Both work fine with OpenWRT as OS.
    *armv7 core
    MJLHThomassen-Sorama
    @MJLHThomassen-Sorama
    I'm now experimenting with adding headers to my response, is there a better way to do this:
    response->putHeader("Custom-Timestamp", oatpp::String(std::to_string(152554).c_str()));
    (so not having to create oatpp::String from sting.c_str()
    oat++
    @oatpp_io_twitter
    Hello @MJLHThomassen-Sorama ,
    response->putHeader("Custom-Timestamp", "1234");
    response->putHeader("Custom-Timestamp", oatpp::utils::conversion::int64ToStr(1234)); // #include "oatpp/core/utils/ConversionUtils.hpp"
    MJLHThomassen-Sorama
    @MJLHThomassen-Sorama
    thanks!
    kapilpipaliya
    @kapilpipaliya
    error: non-constant condition for static assertion when i use arangodb::velocypack::Slice. i think its not copyable.
    oat++
    @oatpp_io_twitter

    Hello @kapilpipaliya ,

    Not sure I understand the question, and how it relates to oatpp.
    Please specify.

    Thanks

    DF-Dave
    @DF-Dave

    Hello, i have a problem/question with your DTO component of oat++. I try to generate an packet with different types of objects but I can't assign inherited classes. I show you my problem with a little example

    ...

    class Param : public oatpp::data::mapping::type::Object
    {
    DTO_INIT(Param , Object)
    };

    class RealParam : public Param
    {
    DTO_INIT(RealParam, Param)

    DTO_FIELD(Int32, magic);

    };

    class Packet : public oatpp::data::mapping::type::Object
    {
    DTO_INIT(Packet, Object)

    DTO_FIELD(List<Param::ObjectWrapper>::ObjectWrapper, params) 
        = List<Param::ObjectWrapper>::createShared();

    };

    ...

    When I try to add an instance (ObjectWrapper) of type RealParam to the list of Packet, I only get an error message from the compiler that there is no known conversion from RealParam::ObjectWrapper to Param::ObjectWrapper. Is there a way to explicitly cast the object or am I still making a mistake somewhere?

    oat++
    @oatpp_io_twitter

    Hello @DF-Dave ,

    It is possible to cast ObjectWrapper using oatpp::data::mapping::type::static_wrapper_cast, and it will compile:

    class Param : public oatpp::data::mapping::type::Object {
    
      DTO_INIT(Param , Object);
    
    };
    
    class RealParam : public Param {
    
      DTO_INIT(RealParam, Param)
    
      DTO_FIELD(Int32, magic);
    
    };
    
    class Packet : public oatpp::data::mapping::type::Object {
    
      DTO_INIT(Packet, Object)
    
      DTO_FIELD(List<Param::ObjectWrapper>::ObjectWrapper, params) = List<Param::ObjectWrapper>::createShared();
    
    };
    
    ...
    
    auto packet = Packet::createShared();
    auto realParam = RealParam::createShared();
    realParam->magic = 10;
    
    Param::ObjectWrapper param = oatpp::data::mapping::type::static_wrapper_cast<Param>(realParam);
    
    packet->params->pushBack(param);

    But the output will miss the magic int32 number:

    {
      "params": [
        {}
      ]
    }
    The point here is that you can't serialize things that you won't be able to deserialize
    Because if you serialize a child class as a parent, you won't have any info during the deserialization about what child class it was originally
    So it is a restriction. And it is an expected behavior here.
    So here DTO_FIELD(List<Param::ObjectWrapper>::ObjectWrapper, params) in the Param inside <> brackets is the actual model of the object that should be serialized. Serializer won't know about other fields present in the child.
    oat++
    @oatpp_io_twitter

    Hope I answered your question.
    Please let me know if you have more questions.

    Regards,
    Leonid

    DF-Dave
    @DF-Dave
    Thank you for your answer but I see the problem. But then I have another question can I use templates within the CODEGEN_MACROS so I can put a template at the packet and specify it's list type variable?
    oat++
    @oatpp_io_twitter

    Not sure if I understand correctly...

    The point is that the template parameter in the list should define the exact type of the object that you want to serialize.

    You can just do like this:

    class Param : public oatpp::data::mapping::type::Object {
    
      DTO_INIT(Param , Object);
    
    };
    
    class RealParam : public Param {
    
      DTO_INIT(RealParam, Param)
    
      DTO_FIELD(Int32, magic);
    
    };
    
    class Packet : public oatpp::data::mapping::type::Object {
    
      DTO_INIT(Packet, Object)
    
      DTO_FIELD(List<RealParam::ObjectWrapper>::ObjectWrapper, params) = List<RealParam::ObjectWrapper>::createShared();
    
    };

    Then, your serializer will serialize all the fields taking into account the base class inheritance.

    Or you mean if it's possible to templatize the DTO object?
    DF-Dave
    @DF-Dave
    yeah I mean to templatize the DTO object
    oat++
    @oatpp_io_twitter
    Let me try...
    oat++
    @oatpp_io_twitter
    Ok, I did it, but it looks pretty ugly. I had to introduce a bunch of typedefs:
    template<class T>
    class Param : public oatpp::data::mapping::type::Object {
    
      DTO_INIT(Param , Object);
    
      DTO_FIELD(T, templateParam);
    
    };
    
    template<class T>
    class Packet : public oatpp::data::mapping::type::Object {
    
      DTO_INIT(Packet, Object)
    
      typedef List<typename Param<T>::ObjectWrapper> ListOfParams;
      typedef typename ListOfParams::ObjectWrapper ListOfParams_ObjectWrapper;
    
      DTO_FIELD(ListOfParams_ObjectWrapper, params) = ListOfParams::createShared();
    
    };
    
    ...
    
      auto packet = Packet<oatpp::String>::createShared();
    
      auto param = Param<oatpp::String>::createShared();
      param->templateParam = "Hello";
    
      packet->params->pushBack(param);
    The output:
    {
      "params": [
        {
          "templateParam": "Hello"
        }
      ]
    }
    at least it's possible:)
    DF-Dave
    @DF-Dave
    ok thank you that helped me a lot :)
    oat++
    @oatpp_io_twitter
    You are welcome! Just ping me,- I'll be happy to help
    oat++
    @oatpp_io_twitter

    @/all ,
    Update :bell:

    The new release with all the November changes is finally shipped 0.19.11.

    Changelog

    oatpp

    • ApiClient. Introduce retries and RetryPolicy.
    • oatpp::network::virtual_::Interface. Introduce ListenerLock to acquire an interface for listening (analog to bind on a port).
    • oatpp::parser::json::mapping::Serializer. Remove extra space char.
    • oatpp::parser::json::mapping::Serializer. Introduce Beautifier and Beautifier config.
    • Introduce v_buff_size for buffer sizes, as an integer capable of storing a pointer.
    • Introduce oatpp::data::stream::Context to store aditional data about the stream.
    • oatpp::network::server::SimpleTCPConnectionProvider. Add feature to obtain peer IP and port available through the connection stream context.

    oatpp-libressl

    • Better portability.
    • Windows compatibility.
    • Support TLS over custom transport.
    • Require LibreSSL minimum version 3.0.0.

    oatpp-mbedtls

    • Fix acceptor-thread blocking by handshake. TLS Handshake is moved to the stream context initialization.

    Relevant documentation:


    Cheers :tada:
    Leonid

    BossZou
    @BossZou
    How I use NON-BLOCKING I/O in my server? I found examples of async used SimpleTCPConnectionProvider and it seems to be BLOCKING I/O. How I make server NON-BLOCKING?
    oat++
    @oatpp_io_twitter

    Hello @BossZou ,

    example-async-api - is exactly what you need.
    No matter what ConnectionProvider is used - when you use AsyncHttpConnectionHandler, it will put accepted connection in the NON-BLOCKING mode and then pass it to the processing coroutine.

    Also, you should be careful not to put any blocking code inside the processing coroutine.

    Regards,
    Leonid

    Amit Kumar
    @theamitk_twitter
    Hello
    oat++
    @oatpp_io_twitter
    Hello @theamitk_twitter , welcome to Oat++ dev community!
    oat++
    @oatpp_io_twitter

    Hey @/all ,
    Update :bell:

    The new BIG stabilization release is now available 0.19.12

    Features and Bug-Fixes

    • Introduce oatpp::data::buffer::Processor and oatpp::data::buffer::ProcessingPipeline for stream chunk-by-chunk processing.
    • Fix server stop() when using oatpp::network::server:: SimpleTCPConnectionProvider. Now server can be properly stopped without additional workarounds.
    • Fix tests inconsistency.
    • Fix a bunch of IO bugs (mostly for Windows).

    Architecture Changes

    • Move IODefinitions.hpp to the root. Move v_io_size, v_io_handle and IOError to the oatpp namespace.
    • Upgrade streams interfaces (to provide nesting and pipelining of any complexity):
      • InputStream now extends ReadCallback
      • OutputStream now extends WriteCallback
      • read/write methods now extended with additional parameter async::Action&.
      • suggestInputStreamAsyncAction / suggestOutputStreamAsyncAction removed.

    Changes Exposed to End-User

    • Rename oatpp::data::v_io_size to oatpp::v_io_size.
    • Rename oatpp::data::v_io_handle to oatpp::v_io_handle.
    • Rename oatpp::data::IOError to oatpp::IOError.
    • Use writeSimple instead of write for ConsistentOutputStreams - ChunkedBuffer and BufferOutputStream.
    • Server stop(). Now additional call to client::ConnectionProvider::getConnection() method is not needed in order to unblock accept and stop the server.

    You are highly recommended to update your applications to the new Oat++ version.


    Note: this is the last "pre" release - next is going to be version 1.0.0. As it took longer than expected to deliver 0.19.12, the 1.0.0 is shifted to the end of Jan - mid-Feb.

    Cheers :tada:
    Leonid

    rrajpaul
    @rrajpaul
    Is possible to do an example for mongodb?