2021-08-04 06:23:29 +08:00
|
|
|
# Oat++ 1.3.0
|
|
|
|
|
|
|
|
Previous release - [1.2.5](1.2.5.md)
|
|
|
|
|
|
|
|
Feel free to ask questions - [Chat on Gitter!](https://gitter.im/oatpp-framework/Lobby)
|
|
|
|
|
|
|
|
Contents:
|
|
|
|
|
|
|
|
- [The New oatpp::String](#the-new-oatppstring)
|
|
|
|
- [ConnectionPool::get() Timeout](#connectionpoolget-timeout)
|
|
|
|
- [JSON Serializer Escape Flags](#json-serializer-escape-flags)
|
|
|
|
|
|
|
|
|
|
|
|
## The New oatpp::String
|
|
|
|
|
|
|
|
Now it's much easier to use `oatpp::String` since `oatpp::String` is now wrapper over `std::string`
|
|
|
|
|
|
|
|
```cpp
|
|
|
|
{
|
|
|
|
std::string s1 = Hello;
|
|
|
|
oatpp::String s2 = s1;
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
oatpp::String s1 = "Hello";
|
|
|
|
std::string s2 = *s1;
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
oatpp::String s1 = "Hello";
|
|
|
|
bool b = s1 == "Hello"; // compare s1 with const char*
|
|
|
|
assert(b);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
oatpp::String s1 = "Hello";
|
|
|
|
std::stringg s2 = "Hello";
|
|
|
|
bool b = s1 == s2; // compare s1 with std::string
|
|
|
|
assert(b);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
oatpp::String s1 = "Hello";
|
|
|
|
std::string s2 = "World";
|
|
|
|
|
|
|
|
oatpp::String s3 = s1 + " " + s2; // concat oatpp::String with const char* and std::string directly
|
|
|
|
|
|
|
|
OATPP_LOGD("TEST", "str='%s'", s3->c_str()); // prints 'Hello World'
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
## ConnectionPool::get() Timeout
|
|
|
|
|
|
|
|
[#408](https://github.com/oatpp/oatpp/issues/408)
|
|
|
|
|
|
|
|
```cpp
|
2021-08-04 06:38:44 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
auto connectionProvider = oatpp::network::tcp::client::ConnectionProvider::createShared({"httpbin.org", 80});
|
|
|
|
|
|
|
|
auto pool = oatpp::network::ClientConnectionPool::createShared(connectionProvider,
|
|
|
|
1,
|
|
|
|
std::chrono::seconds(10),
|
|
|
|
std::chrono::seconds(5));
|
|
|
|
|
|
|
|
OATPP_LOGD("TEST", "start")
|
|
|
|
|
|
|
|
auto c1 = pool->get(); //<--- this one will succeed
|
|
|
|
OATPP_LOGD("TEST", "c1=%llu", c1.get())
|
|
|
|
|
|
|
|
auto c2 = pool->get(); //<--- this one will fail in 5 sec. Since Max-Resources is 1, Pool timeout is 5 sec. And c1 is not freed.
|
|
|
|
OATPP_LOGD("TEST", "c2=%llu", c2.get())
|
|
|
|
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
Output:
|
|
|
|
|
|
|
|
```
|
|
|
|
D |2021-08-04 01:32:56 1628029976986744| TEST:start
|
|
|
|
D |2021-08-04 01:32:57 1628029977126940| TEST:c1=140716915331208
|
|
|
|
D |2021-08-04 01:33:02 1628029982128324| TEST:c2=0
|
2021-08-04 06:23:29 +08:00
|
|
|
```
|
|
|
|
|
|
|
|
## JSON Serializer Escape Flags
|
|
|
|
|
|
|
|
[#381](https://github.com/oatpp/oatpp/issues/381)
|
|
|
|
|
|
|
|
Now you can control if solidus is escaped or not.
|
|
|
|
|
|
|
|
### Default Behavior
|
|
|
|
|
|
|
|
```cpp
|
|
|
|
oatpp::parser::json::mapping::ObjectMapper mapper;
|
|
|
|
// mapper.getSerializer()->getConfig()->escapeFlags = 0; // by default FLAG_ESCAPE_SOLIDUS is ON
|
|
|
|
auto res = mapper.writeToString(oatpp::String("https://oatpp.io/"));
|
|
|
|
OATPP_LOGD("TEST", "res='%s'", res->c_str());
|
|
|
|
```
|
|
|
|
|
|
|
|
Output:
|
|
|
|
|
|
|
|
```
|
|
|
|
res='"https:\/\/oatpp.io\/"' # by default, solidus is escaped
|
|
|
|
```
|
|
|
|
|
|
|
|
### Clear Escape Flags
|
|
|
|
|
|
|
|
```cpp
|
|
|
|
oatpp::parser::json::mapping::ObjectMapper mapper;
|
|
|
|
mapper.getSerializer()->getConfig()->escapeFlags = 0;
|
|
|
|
auto res = mapper.writeToString(oatpp::String("https://oatpp.io/"));
|
|
|
|
OATPP_LOGD("TEST", "res='%s'", res->c_str());
|
|
|
|
```
|
|
|
|
|
|
|
|
Output:
|
|
|
|
|
|
|
|
```
|
|
|
|
res='"https://oatpp.io/"' # solidus isn't escaped
|
|
|
|
```
|
|
|
|
|