Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Feb 23 08:53
    bamkrs synchronize #393
  • Feb 23 08:45
    bamkrs synchronize #393
  • Feb 23 08:37
    lgtm-com[bot] commented #393
  • Feb 23 08:20
    bamkrs synchronize #393
  • Feb 22 17:39
    bamkrs opened #393
  • Feb 22 17:39
    bamkrs review_requested #393
  • Feb 22 17:39
    bamkrs labeled #393
  • Feb 21 14:05
    fanties closed #392
  • Feb 21 13:08
    lganzzzo commented #392
  • Feb 21 12:48
    fanties commented #392
  • Feb 21 12:48
    fanties commented #392
  • Feb 21 12:03
    lganzzzo labeled #392
  • Feb 21 12:03
    lganzzzo commented #392
  • Feb 21 08:43
    fanties edited #392
  • Feb 21 08:43
    fanties opened #392
  • Feb 21 00:58
    lganzzzo edited #304
  • Feb 20 15:33

    lganzzzo on v1.3.0

    (compare)

  • Feb 20 15:30
    lganzzzo synchronize #304
  • Feb 20 15:30

    lganzzzo on endpoint_400

    web::server::HttpRouter. Introd… Merge pull request #344 from oa… Create 1.2.5 changelog and 52 more (compare)

  • Feb 19 14:37
    bamkrs commented #280
oat++
@oatpp_io_twitter

@ke9 ,

I think that you are right. It is better to have allowUnknownFields == true for better compatibility with Consul API.

RES
@madkote
hello here, is there a recommendation which async redis client can be used (or better fits into) in aot++ framework?
and a usage example would be also very helpful... Thanks in advance!
oat++
@oatpp_io_twitter

Hello @madkote ,

I don't have any direct recommendations, but there are some points to consider:

  • If you are using oatpp Simple API - then it should be very easy to use any Redis client, and the process of integration should be straight forward.
  • If you are using oatpp Async API - then things become more complicated because, in oatpp-coroutines, you have to user oatpp-coroutines based API. It also depends on what kind of Redis API you are planning to use...
    • Redis Key-Value - you'll need to do additional synchronization code. All Redis read/write should be done in the separate thread, and coroutine should wait asynchronously for the result from that thread.
    • Pub/Sub - should be comparably easy to implement. You publish from a separate thread. If there is a message for subscriber, you spawn new oatpp-coroutine to handle that message.

Something like that...
Please let me know if you have more questions.

RES
@madkote
@oatpp_io_twitter thx for reply.
Simple API is clear. regarding async - I would like to avoid running redis commands in threads, therfore my question if there is any recommendation for native async redis lib.
I will look around.. thx
MJLHThomassen-Sorama
@MJLHThomassen-Sorama
Hello, i have a question regarding DTO's and inheritance.
I have 2 DTO's, one "Base" and one that inherits from this. As i udnerstand it, i need to pass the class name that gets inherited from to DTO_EXTENDS like this
DTO_INIT(ChildDto, BaseDto)
instead of
DTO_INIT(ChildDto, Object)
when i do this, i get runtime errors trying to access a property of the BaseDto on an instance of ChildDto
Also, maybe this has to do with the fact that the property i try to access in the BaseDto definition is itself a Dto
class HeaderDto : public oatpp::data::mapping::type::Object
{
DTO_INIT(HeaderDto, Object)
        DTO_FIELD(Int64, time);

    };

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

        DTO_FIELD(HeaderDto::ObjectWrapper, header);
    };
i try to access field "time" on ResponseDto object via field "header"
so
auto dto = ResponseDto::createShared();
dto->header->time = 0;
oat++
@oatpp_io_twitter
Hello @MJLHThomassen-Sorama , and welcome.
Let me double-check this. Will get back to you shortly.
MJLHThomassen-Sorama
@MJLHThomassen-Sorama
Hey @oatpp_io_twitter , thanks!
oat++
@oatpp_io_twitter
Hey @MJLHThomassen-Sorama
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