alibaba / hessian2-codec

hessian2-codec it is a complete C++ implementation of hessian2 spec
Apache License 2.0
26 stars 10 forks source link

extend OptRef to simplify the using of to<Type> methods #28

Closed wbpcode closed 1 year ago

wbpcode commented 1 year ago

In the previous implementation, absl::optional<std::reference_wrapper<T>> is used to store the ref of the hessian2 object. And if a method need to be called, the code would be like:

ObjectPtr object{};
auto opt_ref = object->toMutableUntypedMap();
if(opt_ref.has_value()) {
  opt_ref.value().get().emplace(....);
}

This simple patch will simplify this calling to following code. We needn't to repeat value().get().

ObjectPtr object{};
auto opt_ref = object->toMutableUntypedMap();
if(opt_ref.has_value()) {
  opt_ref->emplace(....);
}
codecov-commenter commented 1 year ago

Codecov Report

Patch and project coverage have no change.

Comparison is base (b6dedde) 87.03% compared to head (d2af096) 87.03%.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #28 +/- ## ======================================= Coverage 87.03% 87.03% ======================================= Files 25 25 Lines 2407 2407 ======================================= Hits 2095 2095 Misses 312 312 ``` | [Files Changed](https://app.codecov.io/gh/alibaba/hessian2-codec/pull/28?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=alibaba) | Coverage Δ | | |---|---|---| | [hessian2/object.hpp](https://app.codecov.io/gh/alibaba/hessian2-codec/pull/28?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=alibaba#diff-aGVzc2lhbjIvb2JqZWN0LmhwcA==) | `76.95% <ø> (ø)` | |

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

zyfjeff commented 1 year ago

LGTM