qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From astitc...@apache.org
Subject [1/5] qpid-proton git commit: PROTON-1707: [C++ binding] Simplify source directory structure - Remove pointless extra directories
Date Mon, 04 Dec 2017 19:00:21 GMT
Repository: qpid-proton
Updated Branches:
  refs/heads/master 25efd103a -> 25025e9b3


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/5199e8c2/proton-c/bindings/cpp/src/reconnect_options_impl.hpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/src/reconnect_options_impl.hpp b/proton-c/bindings/cpp/src/reconnect_options_impl.hpp
new file mode 100644
index 0000000..2aca82d
--- /dev/null
+++ b/proton-c/bindings/cpp/src/reconnect_options_impl.hpp
@@ -0,0 +1,45 @@
+#ifndef PROTON_CPP_RECONNECT_OPTIONSIMPL_H
+#define PROTON_CPP_RECONNECT_OPTIONSIMPL_H
+
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+#include "proton/duration.hpp"
+
+#include <string>
+#include <vector>
+
+namespace proton {
+
+class reconnect_options::impl {
+  public:
+    impl() : delay(10), delay_multiplier(2.0), max_delay(duration::FOREVER), max_attempts(0)
{}
+
+    duration delay;
+    float    delay_multiplier;
+    duration max_delay;
+    int      max_attempts;
+    std::vector<std::string> failover_urls;
+};
+
+}
+
+#endif  /*!PROTON_CPP_RECONNECT_OPTIONSIMPL_H*/

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/5199e8c2/proton-c/bindings/cpp/src/scalar_test.hpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/src/scalar_test.hpp b/proton-c/bindings/cpp/src/scalar_test.hpp
new file mode 100644
index 0000000..a54eabe
--- /dev/null
+++ b/proton-c/bindings/cpp/src/scalar_test.hpp
@@ -0,0 +1,209 @@
+#ifndef SCALAR_TEST_HPP
+#define SCALAR_TEST_HPP
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+// Template tests used by both scalar_test.cpp and value_test.hpp to test conversion
+// of scalar values via a proton::scalar or a proton::value.
+
+#include "test_bits.hpp"
+
+#include "proton/types.hpp"
+#include "proton/error.hpp"
+
+#include <sstream>
+
+
+namespace test {
+
+using namespace proton;
+
+// Inserting and extracting simple C++ values using same-type get<T> and coerce<T>
+template <class V, class T> void simple_type_test(T x, type_id tid, const std::string&
s, T y) {
+    V vx(x);                    // Construct from C++ value
+    ASSERT_EQUAL(tid, vx.type());
+    ASSERT(!vx.empty());
+    ASSERT_EQUAL(x, get<T>(vx));
+    ASSERT_EQUAL(x, coerce<T>(vx));
+
+    V vxa = x;                  // Assign from C++ value
+    ASSERT_EQUAL(tid, vxa.type());
+    ASSERT(!vx.empty());
+    ASSERT_EQUAL(vx, vxa);
+    ASSERT_EQUAL(x, get<T>(vxa));
+    ASSERT_EQUAL(x, coerce<T>(vxa));
+
+    V v2;                       // Default construct
+    ASSERT(v2.type() == NULL_TYPE);
+    ASSERT(v2.empty());
+    v2 = x;                     // Assign from C++ value
+    ASSERT_EQUAL(tid, v2.type());
+    ASSERT_EQUAL(vx, v2);
+    ASSERT_EQUAL(x, get<T>(v2));
+    ASSERT_EQUAL(x, coerce<T>(v2));
+
+    V v3(vx);                   // Copy construct
+    ASSERT_EQUAL(tid, v3.type());
+    ASSERT_EQUAL(vx, v3);
+    ASSERT_EQUAL(x, get<T>(v3));
+    ASSERT_EQUAL(x, coerce<T>(v3));
+
+    V v4 = vx;                  // Copy assign
+    ASSERT_EQUAL(tid, v4.type());
+    ASSERT_EQUAL(x, get<T>(v4));
+    ASSERT_EQUAL(x, coerce<T>(v4));
+
+    ASSERT_EQUAL(s, to_string(vx));   // Stringify
+    V vy(y);
+    ASSERT(vx != vy);           // Compare
+    ASSERT(vx < vy);
+    ASSERT(vy > vx);
+}
+
+// Test native C/C++ integer types via their mapped integer type ([u]int_x_t)
+template <class V, class T> void simple_integral_test() {
+    typedef typename internal::integer_type<sizeof(T), internal::is_signed<T>::value>::type
int_type;
+    simple_type_test<V>(T(3), internal::type_id_of<int_type>::value, "3", T(4));
+}
+
+// Test invalid gets, valid same-type get<T> is tested by simple_type_test
+// Templated to test both scalar and value.
+template<class V>  void bad_get_test() {
+    try { get<bool>(V(int8_t(1))); FAIL("byte as bool"); } catch (conversion_error)
{}
+    try { get<uint8_t>(V(true)); FAIL("bool as uint8_t"); } catch (conversion_error)
{}
+    try { get<uint8_t>(V(int8_t(1))); FAIL("int8 as uint8"); } catch (conversion_error)
{}
+    try { get<int16_t>(V(uint16_t(1))); FAIL("uint16 as int16"); } catch (conversion_error)
{}
+    try { get<int16_t>(V(int32_t(1))); FAIL("int32 as int16"); } catch (conversion_error)
{}
+    try { get<symbol>(V(std::string())); FAIL("string as symbol"); } catch (conversion_error)
{}
+    try { get<std::string>(V(binary())); FAIL("binary as string"); } catch (conversion_error)
{}
+    try { get<binary>(V(symbol())); FAIL("symbol as binary"); } catch (conversion_error)
{}
+    try { get<binary>(V(timestamp())); FAIL("timestamp as binary"); } catch (conversion_error)
{}
+    try { get<int>(V(timestamp())); FAIL("timestamp as int"); } catch (conversion_error)
{}
+    try { get<timestamp>(V(0)); FAIL("int as timestamp"); } catch (conversion_error)
{}
+    try { get<timestamp>(V(std::string())); FAIL("string as timestamp"); } catch (conversion_error)
{}
+}
+
+// Test some valid coercions and some bad ones with mixed types.
+// Templated to test both scalar and value.
+template<class V> void coerce_test() {
+    // Valid C++ conversions should work with coerce.
+    ASSERT_EQUAL(false, coerce<bool>(V(0)));
+    ASSERT_EQUAL(true, coerce<bool>(V(-1)));
+    ASSERT_EQUAL(true, coerce<bool>(V(int64_t(0xFFFF0000))));
+
+    ASSERT_EQUAL(1, coerce<uint8_t>(V(uint64_t(1)))); // In range.
+    ASSERT_EQUAL(1, coerce<uint8_t>(V(uint32_t(0xFF01)))); // int truncate.
+    ASSERT_EQUAL(0xFFFF, coerce<uint16_t>(V(int8_t(-1)))); // Sign extend.
+    ASSERT_EQUAL(-1, coerce<int32_t>(V(uint64_t(0xFFFFFFFFul)))); // 2s complement
+
+    ASSERT_EQUALISH(1.2f, coerce<float>(V(double(1.2))), 0.001f);
+    ASSERT_EQUALISH(3.4, coerce<double>(V(float(3.4))), 0.001);
+    ASSERT_EQUALISH(23.0, coerce<double>(V(uint64_t(23))), 0.001); // int to double.
+    ASSERT_EQUAL(-1945, coerce<int>(V(float(-1945.123))));    // round to int.
+
+    // String-like conversions.
+    ASSERT_EQUAL(std::string("foo"), coerce<std::string>(V(symbol("foo"))));
+    ASSERT_EQUAL(std::string("foo"), coerce<std::string>(V(binary("foo"))));
+
+    // Bad coercions, types are not `is_convertible`
+    V s("foo");
+    try { coerce<bool>(s); FAIL("string as bool"); } catch (conversion_error) {}
+    try { coerce<int>(s); FAIL("string as int"); } catch (conversion_error) {}
+    try { coerce<double>(s); FAIL("string as double"); } catch (conversion_error) {}
+
+    try { coerce<std::string>(V(0)); FAIL("int as string"); } catch (conversion_error)
{}
+    try { coerce<symbol>(V(true)); FAIL("bool as symbol"); } catch (conversion_error)
{}
+    try { coerce<binary>(V(0.0)); FAIL("double as binary"); } catch (conversion_error)
{}
+    try { coerce<symbol>(V(binary())); FAIL("binary as symbol"); } catch (conversion_error)
{}
+    try { coerce<binary>(V(symbol())); FAIL("symbol as binary"); } catch (conversion_error)
{}
+    try { coerce<binary>(s); } catch (conversion_error) {}
+    try { coerce<symbol>(s); } catch (conversion_error) {}
+}
+
+template <class V> void null_test() {
+    V v;
+    ASSERT(v.empty());
+    ASSERT_EQUAL(NULL_TYPE, v.type());
+    get<null>(v);
+    null n;
+    get(v, n);
+    V v2(n);
+    ASSERT(v.empty());
+    ASSERT_EQUAL(NULL_TYPE, v.type());
+    v = "foo";
+    ASSERT_EQUAL(STRING, v.type());
+    try { get<null>(v); FAIL("Expected conversion_error"); } catch (conversion_error)
{}
+    v = null();
+    get<null>(v);
+}
+
+// Nasty hack for uninterpreted decimal<> types.
+template <class T> T make(const char c) { T x; std::fill(x.begin(), x.end(), c); return
x; }
+
+template <class V> void scalar_test_group(int& failed) {
+    // Direct AMQP-mapped types.
+    RUN_TEST(failed, simple_type_test<V>(false, BOOLEAN, "false", true));
+    RUN_TEST(failed, simple_type_test<V>(uint8_t(42), UBYTE, "42", uint8_t(50)));
+    RUN_TEST(failed, simple_type_test<V>(int8_t(-42), BYTE, "-42", int8_t(-40)));
+    RUN_TEST(failed, simple_type_test<V>(uint16_t(4242), USHORT, "4242", uint16_t(5252)));
+    RUN_TEST(failed, simple_type_test<V>(int16_t(-4242), SHORT, "-4242", int16_t(3)));
+    RUN_TEST(failed, simple_type_test<V>(uint32_t(4242), UINT, "4242", uint32_t(5252)));
+    RUN_TEST(failed, simple_type_test<V>(int32_t(-4242), INT, "-4242", int32_t(3)));
+    RUN_TEST(failed, simple_type_test<V>(uint64_t(4242), ULONG, "4242", uint64_t(5252)));
+    RUN_TEST(failed, simple_type_test<V>(int64_t(-4242), LONG, "-4242", int64_t(3)));
+    RUN_TEST(failed, simple_type_test<V>(wchar_t('X'), CHAR, "88", wchar_t('Y')));
+    RUN_TEST(failed, simple_type_test<V>(float(1.234), FLOAT, "1.234", float(2.345)));
+    RUN_TEST(failed, simple_type_test<V>(double(11.2233), DOUBLE, "11.2233", double(12)));
+    RUN_TEST(failed, simple_type_test<V>(timestamp(1234), TIMESTAMP, "1234", timestamp(12345)));
+    RUN_TEST(failed, simple_type_test<V>(make<decimal32>(1), DECIMAL32, "decimal32(0x01010101)",
make<decimal32>(2)));
+    RUN_TEST(failed, simple_type_test<V>(make<decimal64>(3), DECIMAL64, "decimal64(0x0303030303030303)",
make<decimal64>(4)));
+    RUN_TEST(failed, simple_type_test<V>(make<decimal128>(5), DECIMAL128, "decimal128(0x05050505050505050505050505050505)",
make<decimal128>(6)));
+    RUN_TEST(failed, simple_type_test<V>(
+                 uuid::copy("\x00\x11\x22\x33\x44\x55\x66\x77\x88\x99\xaa\xbb\xcc\xdd\xee\xff"),
+                 UUID, "00112233-4455-6677-8899-aabbccddeeff",
+                 uuid::copy("\xff\x11\x22\x33\x44\x55\x66\x77\x88\x99\xaa\xbb\xcc\xdd\xee\xff")));
+    RUN_TEST(failed, simple_type_test<V>(std::string("xxx"), STRING, "xxx", std::string("yyy")));
+    RUN_TEST(failed, simple_type_test<V>(symbol("aaa"), SYMBOL, "aaa", symbol("aaaa")));
+    RUN_TEST(failed, simple_type_test<V>(binary("\010aaa"), BINARY, "b\"\\x08aaa\"",
binary("aaaa")));
+
+    // Test native C++ integral types.
+    RUN_TEST(failed, (simple_integral_test<V, char>()));
+    RUN_TEST(failed, (simple_integral_test<V, signed char>()));
+    RUN_TEST(failed, (simple_integral_test<V, unsigned char>()));
+    RUN_TEST(failed, (simple_integral_test<V, short>()));
+    RUN_TEST(failed, (simple_integral_test<V, int>()));
+    RUN_TEST(failed, (simple_integral_test<V, long>()));
+    RUN_TEST(failed, (simple_integral_test<V, unsigned short>()));
+    RUN_TEST(failed, (simple_integral_test<V, unsigned int>()));
+    RUN_TEST(failed, (simple_integral_test<V, unsigned long>()));
+#if PN_CPP_HAS_LONG_LONG_TYPE
+    RUN_TEST(failed, (simple_integral_test<V, long long>()));
+    RUN_TEST(failed, (simple_integral_test<V, unsigned long long>()));
+#endif
+
+
+    RUN_TEST(failed, (coerce_test<V>()));
+    RUN_TEST(failed, (null_test<V>()));
+    RUN_TEST(failed, (bad_get_test<V>()));
+}
+
+}
+
+#endif // SCALAR_TEST_HPP

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/5199e8c2/proton-c/bindings/cpp/src/test_bits.hpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/src/test_bits.hpp b/proton-c/bindings/cpp/src/test_bits.hpp
new file mode 100644
index 0000000..4e019f2
--- /dev/null
+++ b/proton-c/bindings/cpp/src/test_bits.hpp
@@ -0,0 +1,158 @@
+#ifndef TEST_BITS_HPP
+#define TEST_BITS_HPP
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include "msg.hpp"
+#include "proton/types.hpp"
+
+#include <stdexcept>
+#include <iostream>
+#include <iterator>
+#include <sstream>
+#include <cstring>
+#include <math.h>
+
+namespace test {
+
+struct fail : public std::logic_error {
+    explicit fail(const std::string& what) : logic_error(what) {}
+};
+
+struct error : public std::logic_error {
+    explicit error(const std::string& what) : logic_error(what) {}
+};
+
+template <class T, class U>
+void assert_equal(const T& want, const U& got, const std::string& what) {
+    if (!(want == got))
+        throw fail(MSG(what << " " << want << " != " << got));
+}
+
+template <class T>
+inline void assert_equalish(T want, T got, T delta, const std::string& what)
+{
+    if (!(fabs(want-got) <= delta))
+        throw fail(MSG(what << " " << want << " !=~ " << got));
+}
+
+#define FAIL_MSG(WHAT) (MSG(__FILE__ << ":" << __LINE__ << ": " <<
WHAT).str())
+#define FAIL(WHAT) throw test::fail(FAIL_MSG(WHAT))
+#define ASSERT(TEST) do { if (!(TEST)) FAIL("failed ASSERT(" #TEST ")"); } while(false)
+#define ASSERT_EQUAL(WANT, GOT) \
+    test::assert_equal((WANT), (GOT), FAIL_MSG("failed ASSERT_EQUAL(" #WANT ", " #GOT ")"))
+#define ASSERT_EQUALISH(WANT, GOT, DELTA) \
+    test::assert_equalish((WANT), (GOT), (DELTA), FAIL_MSG("failed ASSERT_EQUALISH(" #WANT
", " #GOT ")"))
+#define ASSERT_THROWS(WANT, EXPR) do { try { EXPR; FAIL("Expected " #WANT); } catch(const
WANT&) {} } while(0)
+
+#define RUN_TEST(BAD_COUNT, TEST)                                       \
+    do {                                                                \
+        try {                                                           \
+            std::cout << "TEST: " << #TEST << std::endl;              
 \
+            TEST;                                                       \
+            break;                                                      \
+        } catch(const test::fail& e) {                                        \
+            std::cout << "FAIL " << #TEST << std::endl << e.what()
<< std::endl; \
+        } catch(const std::exception& e) {                              \
+            std::cout << "ERROR " << #TEST << std::endl << __FILE__
<< ":" << __LINE__ << ": " << e.what() << std::endl; \
+        }                                                               \
+            ++BAD_COUNT;                                                \
+    } while(0)
+
+/* Like RUN_TEST but only if one of the argv strings is found in the test EXPR */
+#define RUN_ARGV_TEST(BAD_COUNT, EXPR) do {     \
+    if (argc == 1) {                            \
+      RUN_TEST(BAD_COUNT, EXPR);                \
+    } else {                                    \
+      for (int i = 1; i < argc; ++i) {          \
+        if (strstr(#EXPR, argv[i])) {           \
+            RUN_TEST(BAD_COUNT, EXPR);          \
+          break;                                \
+        }                                       \
+      }                                         \
+    }                                           \
+  } while(0)
+
+
+template<class T> std::string str(const T& x) {
+    std::ostringstream s; s << std::boolalpha << x; return s.str();
+}
+
+// A way to easily create literal collections that can be compared to std:: collections
+// and to print std collections
+// e.g.
+//     std::vector<string> v = ...;
+//     ASSERT_EQUAL(many<string>() + "a" + "b" + "c", v);
+template <class T> struct many : public std::vector<T> {
+    many() {}
+    template<class S> explicit many(const S& s) : std::vector<T>(s.begin(),
s.end()) {}
+    many& operator+=(const T& t) { this->push_back(t); return *this; }
+    many& operator<<(const T& t) { return *this += t; }
+    many operator+(const T& t) { many<T> l(*this); return l += t; }
+};
+
+template <class T, class S> bool operator==(const many<T>& m, const S&
s) {
+    return m.size() == s.size() && S(m.begin(), m.end()) == s;
+}
+
+template <class T, class S> bool operator==(const S& s, const many<T>&
m) {
+    return m.size() == s.size() && S(m.begin(), m.end()) == s;
+}
+
+template <class T> std::ostream& operator<<(std::ostream& o, const many<T>&
m) {
+    std::ostream_iterator<T> oi(o, " ");
+    std::copy(m.begin(), m.end(), oi);
+    return o;
+}
+
+}
+
+namespace std {
+template <class T> std::ostream& operator<<(std::ostream& o, const std::vector<T>&
s) {
+    return o << test::many<T>(s);
+}
+
+template <class T> std::ostream& operator<<(std::ostream& o, const std::deque<T>&
s) {
+    return o << test::many<T>(s);
+}
+
+template <class T> std::ostream& operator<<(std::ostream& o, const std::list<T>&
s) {
+    return o << test::many<T>(s);
+}
+
+template <class K, class T> std::ostream& operator<<(std::ostream& o,
const std::map<K, T>& x) {
+    return o << test::many<std::pair<K, T> >(x);
+}
+
+template <class U, class V> std::ostream& operator<<(std::ostream& o,
const std::pair<U, V>& p) {
+    return o << "( " << p.first << " , " << p.second << " )";
+}
+
+#if PN_CPP_HAS_CPP11
+template <class K, class T> std::ostream& operator<<(std::ostream& o,
const std::unordered_map<K, T>& x) {
+    return o << test::many<std::pair<const K, T> >(x);
+}
+
+template <class T> std::ostream& operator<<(std::ostream& o, const std::forward_list<T>&
s) {
+    return o << test::many<T>(s);
+}
+#endif
+}
+
+#endif // TEST_BITS_HPP

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/5199e8c2/proton-c/bindings/cpp/src/types_internal.hpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/src/types_internal.hpp b/proton-c/bindings/cpp/src/types_internal.hpp
new file mode 100644
index 0000000..bff93a0
--- /dev/null
+++ b/proton-c/bindings/cpp/src/types_internal.hpp
@@ -0,0 +1,74 @@
+#ifndef TYPES_INTERNAL_HPP
+#define TYPES_INTERNAL_HPP
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include "proton/internal/type_traits.hpp"
+#include "proton/error.hpp"
+#include "proton/binary.hpp"
+#include <sstream>
+
+///@file
+/// Inline helpers for encode/decode/type conversion/ostream operators.
+
+namespace proton {
+
+/// Byte copy between two objects, only enabled if their sizes are equal.
+template <class T, class U>
+typename internal::enable_if<sizeof(T) == sizeof(U)>::type byte_copy(T &to, const
U &from) {
+    const char *p = reinterpret_cast<const char*>(&from);
+    std::copy(p, p + sizeof(T), reinterpret_cast<char*>(&to));
+}
+
+inline conversion_error
+make_conversion_error(type_id want, type_id got, const std::string& msg=std::string())
{
+    std::ostringstream s;
+    s << "unexpected type, want: " << want << " got: " << got;
+    if (!msg.empty()) s << ": " << msg;
+    return conversion_error(s.str());
+}
+
+/// Convert std::string to pn_bytes_t
+inline pn_bytes_t pn_bytes(const std::string& s) {
+    pn_bytes_t b = { s.size(), s.empty() ? 0 : const_cast<char*>(&s[0]) };
+    return b;
+}
+
+inline pn_bytes_t pn_bytes(const binary& s) {
+    pn_bytes_t b = { s.size(), s.empty() ? 0 : reinterpret_cast<const char*>(&s[0])
};
+    return b;
+}
+
+inline std::string str(const pn_bytes_t& b) { return std::string(b.start, b.size); }
+inline binary bin(const pn_bytes_t& b) { return binary(b.start, b.start+b.size); }
+
+// Save all stream format state, restore in destructor.
+struct ios_guard {
+    std::ios &guarded;
+    std::ios old;
+    ios_guard(std::ios& x) : guarded(x), old(0) { old.copyfmt(guarded); }
+    ~ios_guard() { guarded.copyfmt(old); }
+};
+
+// Convert a char (signed or unsigned) into an unsigned 1 byte integer that will ostream
+// as a numeric byte value, not a character and will not get sign-extended.
+inline unsigned int printable_byte(uint8_t byte) { return byte; }
+
+}
+#endif // TYPES_INTERNAL_HPP


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


Mime
View raw message