[
https://issues.apache.org/jira/browse/PROTON-1216?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Alan Conway resolved PROTON-1216.
---------------------------------
Resolution: Fixed
> c++: proton::coerce<std::string>() should allow conversion from binary.
> -----------------------------------------------------------------------
>
> Key: PROTON-1216
> URL: https://issues.apache.org/jira/browse/PROTON-1216
> Project: Qpid Proton
> Issue Type: Bug
> Components: cpp-binding
> Affects Versions: 0.12.2
> Reporter: Alan Conway
> Assignee: Alan Conway
> Fix For: 0.13.0
>
>
> proton::coerce<std::string> should convert a binary value to a std::string.
> The documentation also needs clarification: coerce should allow exactly those
> conversions that are allowed as implicit C++ conversions.
> Issue raised in excellent bug report on the user list
> http://qpid.2158936.n2.nabble.com/Proton-C-0-13-x-decode-binary-type-tp7644510p7644747.html
> text follows:
> proton::coerce (both forms) currently throws the same
> exception as proton::get, as does value.as_string(), although that doesn't
> appear to be in the public API. Not sure what 'd' was in the d>>b example,
> but got a version working using value.get<std::binary>() and an implicit
> cast to std::string.
> To reproduce...
> #include <proton/value.hpp>
> #include <proton/binary.hpp>
> #include <proton/error.hpp>
> #include <iostream>
> template<typename Lambda>
> void expect_exception ( Lambda f )
> {
> try
> {
> f();
> std::cout << "*** FAIL (expected conversion error) ***" << std::endl;
> }
> catch ( const proton::conversion_error& e )
> {
> std::cout << "PASS" << std::endl;
> }
> }
> template<typename Lambda>
> void expect_value ( const std::string& expected, Lambda f )
> {
> try
> {
> std::cout << (f() == expected ? "PASS" : "*** FAIL (wrong value) ***")
> << std::endl;
> }
> catch ( const proton::conversion_error& e )
> {
> std::cout << "*** FAIL (conversion error) ***" << std::endl;
> }
> }
> int main()
> {
> std::string expected = "Hello World!";
> proton::value value = proton::binary(expected);
> expect_exception( [=] { return value.get<std::string>();
>
> });
> expect_exception( [=] { return proton::get<std::string>(value);
>
> });
> expect_exception( [=] { std::string result;
> proton::get<std::string>(value); return result; });
> expect_value(expected, [=] () -> std::string { return
> value.get<proton::binary>(); } );
> // The following currently fail under 0.13.x
> expect_value(expected, [=] { return value.as_string();
>
> });
> expect_value(expected, [=] { return proton::coerce<std::string>(value);
>
> });
> expect_value(expected, [=] { std::string result;
> proton::coerce<std::string>(value, result); return result; });
>
> }
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]