From e5f27778179696429e4212611c6e5454e2a63e99 Mon Sep 17 00:00:00 2001 From: Kenneth Anthony Giusti Date: Thu, 28 Oct 2010 21:33:52 +0000 Subject: QPID-2916: throw an exception when a data value cannot be encoded correctly as its type. git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@1028501 13f79535-47bb-0310-9956-ffa450edef68 --- cpp/src/qpid/amqp_0_10/Codecs.cpp | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'cpp/src/qpid/amqp_0_10/Codecs.cpp') diff --git a/cpp/src/qpid/amqp_0_10/Codecs.cpp b/cpp/src/qpid/amqp_0_10/Codecs.cpp index abe6b2c7da..0fbe2a60b9 100644 --- a/cpp/src/qpid/amqp_0_10/Codecs.cpp +++ b/cpp/src/qpid/amqp_0_10/Codecs.cpp @@ -198,15 +198,21 @@ boost::shared_ptr convertString(const std::string& value, const std: } else { return boost::shared_ptr(new Var16Value(value, 0x90)); } - } else if (encoding == utf8 && !large) { + } else if (encoding == utf8) { + if (!large) return boost::shared_ptr(new Str16Value(value)); - } else if (encoding == utf16 && !large) { - return boost::shared_ptr(new Var16Value(value, 0x96)); - } else if (encoding == iso885915 && !large) { - return boost::shared_ptr(new Var16Value(value, 0x94)); + throw Exception(QPID_MSG("Could not encode utf8 character string - too long (" << value.size() << " bytes)")); + } else if (encoding == utf16) { + if (!large) + return boost::shared_ptr(new Var16Value(value, 0x96)); + throw Exception(QPID_MSG("Could not encode utf16 character string - too long (" << value.size() << " bytes)")); + } else if (encoding == iso885915) { + if (!large) + return boost::shared_ptr(new Var16Value(value, 0x94)); + throw Exception(QPID_MSG("Could not encode iso-8859-15 character string - too long (" << value.size() << " bytes)")); } else { - //either the string is too large for the encoding in amqp 0-10, or the encoding was not recognised - QPID_LOG(warning, "Could not encode " << value.size() << " byte value as " << encoding << ", encoding as vbin32."); + // the encoding was not recognised + QPID_LOG(warning, "Unknown byte encoding: [" << encoding << "], encoding as vbin32."); return boost::shared_ptr(new Var32Value(value, 0xa0)); } } -- cgit v1.2.1